This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
HOST=example.com | |
FLAG=/tmp/host_is_up | |
SLEEP=60 | |
RETRIES=3 | |
RETRY_SLEEP=10 | |
MSG_PREFIX="example.com is" | |
TG_TOKEN= | |
TG_CHAT_ID= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""some decorators for methods of classes | |
>>> class A: | |
... "test class" | |
... @(cached & dynamic(int)) | |
... def square(self, x=1): | |
... "docstring" | |
... print('computed!') | |
... return x**2 | |
... @dynamic_array |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
[ -z "$TG_TOKEN" ] && { echo "TG_TOKEN not set"; exit 1; } | |
[ -z "$TG_CHAT_ID" ] && { echo "TG_CHAT_ID not set"; exit 1; } | |
while IFS= read -r stdin; do | |
# printf '%s\n' "$stdin" | |
curl -s -d chat_id="$TG_CHAT_ID" --data-urlencode text="$stdin" "https://api.telegram.org/bot$TG_TOKEN/sendMessage" | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# coding: utf8 | |
import time, glob, csv, os, logging, random, sys, requests, functools, io | |
from datetime import datetime, timedelta | |
from sqlitedict import SqliteDict | |
from bs4 import BeautifulSoup | |
prefix = 'https://www.rheinhessen-sparkasse.de' | |
target = '/en/home/onlinebanking/umsaetze/umsaetze.html' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import numpy as np | |
from scipy.sparse import diags, linalg | |
import sympy as sp | |
from scipy import integrate | |
import matplotlib.pyplot as plt | |
# nucleus charge: | |
Z = 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import numpy as np | |
from scipy.sparse import diags, linalg | |
import matplotlib.pyplot as plt | |
# solving for function values excluding boundaries: | |
x = np.linspace(-.5, .5, 42)[1:-1] | |
# imposing psi=0 boundary conditions, aka infinite walls: | |
laplace = diags([1, -2, 1], [-1, 0, 1], shape=[len(x)]*2) / (x[1] - x[0])**2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import numpy as np | |
from numpy import cos, sin, pi, exp | |
from functools import lru_cache | |
nt = 500 # number of timesteps of the animation per (default) period of the oscillation | |
nx = 200 # number of points to evaluate the function at for each frame | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
parallel execution function decorator (with quite large overhead) | |
>>> @parallel(reduction=sum) | |
... def f(array): | |
... return sum(array) | |
>>> f(range(1, 9)) | |
36 | |
>>> @parallel |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Dynamic values (hack) | |
Dynamic float value: | |
>>> f = ffloat(lambda x=1.0, y=2.0: x**y) | |
>>> f | |
1.0 | |
>>> f(x=2, y=3) | |
8.0 | |
>>> f | |
1.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
class ClassWraps(type): # metaclass | |
"""kinda like functools.wraps decorator, but a metaclass and specifically for descriptor-decorator classes, | |
just to retain the documentation of the decorated methods inside a class""" | |
def __new__(cls, clsname, parents, attrs): | |
def copy_attr(attr): # closure | |
return property(lambda self: getattr(self._method, attr)) | |
for attr in ['__name__', '__doc__', '__module__', '__annotations__']: # `__qualname__` won't work like this... | |
attrs[attr] = copy_attr(attr) |
NewerOlder