Skip to content

Instantly share code, notes, and snippets.

View miraculixx's full-sized avatar
💭
working on https://github.com/omegaml

miraculixx

💭
working on https://github.com/omegaml
  • Switzerland
View GitHub Profile
@miraculixx
miraculixx / rules.py
Last active July 25, 2021 07:18
a simple python based rule engine
"""
(c) 2014 miraculixx at gmx.ch
"""
from shrutil.dictobj import DictObject
class RuleContext(DictObject):
"""
rule context to store values and attributes (or any object)
"""
def __init__(self):
@miraculixx
miraculixx / tasks.py
Last active July 1, 2021 15:43
helm update-values helper
# Details on usage see docstring
#
# Installation:
#
# $ pip install invoke
# $ (copy/paste this file to your local tasks.py)
#
# Usage:
#
# 1. amend your values.yaml with a #==tags.myfeature (at line end of line to update)
@miraculixx
miraculixx / README.md
Last active June 19, 2021 14:57
Algorithmic trading references
@miraculixx
miraculixx / README.txt
Last active April 2, 2021 18:37
coin toss sequence, probability experiment in response to @nntaleb https://twitter.com/nntaleb/status/1377576808590282761
Question by @nntaleb
Throw a coin, H=head, T= Tail. Which sequence one is more likely?
A={H,T,H,T,H,T,H,T,H,T,T,H,T,H,H,T,T,T,H,H}
B={H,H,H,H,H,H,H,H,H,H,H,H,H,H,H,H,H,H,H,H}
C={H,H,H,H,H,H,H,H,H,H,T,T,T,T,T,T,T,T,T,T}
@miraculixx
miraculixx / example.py
Created December 10, 2020 11:48
omegaml async task chaining
# this will chain the fit and predict, i.e. fit will run only on predict success
with om.runtime.chain() as crt:
crt.model('regmodelx').fit('sample[y]', 'sample[x]')
crt.model('regmodelx').predict([5], rName='foox')
result = crt.run()
# sometime later
print(result.get())
@miraculixx
miraculixx / rancher-install-18.09.sh
Last active November 20, 2020 11:46
rancher-docker installer
#!/bin/sh
set -e
# https://unix.stackexchange.com/a/315517
sudo systemctl stop apt-daily.service apt-daily-timer apt-daily-upgrade.timer || true
sudo systemctl kill --kill-who=all apt-daily.service || true
# https://github.com/rancher/rancher/issues/27353#issuecomment-706103308
sudo killall dpkg || true
sudo rm -f /var/lib/dpkg/lock || true
@miraculixx
miraculixx / timeit.py
Created September 20, 2020 11:26
a straight forward statement timer for Python
@contextmanager
def timeit():
""" straight forward statement timer for Python
Usage:
with timeit() as timer:
...
print(timer.elpased()) # prints the timedelta, timer also has .start, .end
"""
@miraculixx
miraculixx / omx_launch.py
Last active August 14, 2020 01:03
simple gpu launcher
import subprocess
subprocess.run("getgist miraculixx progress.py".split(' '))
import omegaml as om_
from progress import progress
om = om_
def match_active_queues(queue=None, nodes=None):
queues = om.runtime.celeryapp.control.inspect().active_queues()
@miraculixx
miraculixx / progress.py
Last active August 14, 2020 01:02
a progress decorator for any python function
def progress(fn):
"""decorator to run fn until timeout in seconds, or wait forever if timeout < 0
Usage:
@progress
def fn(..):
return stop-flag, result
stopped, result = fn(.., timeout=SECONDS, stop_on_error=True|False, interval=SECONDS)
@miraculixx
miraculixx / Makefile
Last active August 12, 2020 17:57
create a locally hosted helm repository to use in dependencies, serve using python http.server
# put this in ./dependencies
# add external dependencies that cannot be added as a repository
# then add this directory as a file
# for every external chart, script the download as shown in localpath example, add to build target dependencies
# use $ make build to download all dependencies, build packages and local repo index
localpath:
mkdir -p staging
curl https://codeload.github.com/rancher/local-path-provisioner/tar.gz/v0.0.15 -o staging/localpath.tgz
cd staging && tar -xzf localpath.tgz