Skip to content

Instantly share code, notes, and snippets.

@tavin
tavin / quantreg-bs.py
Created May 17, 2018 17:13
b-spline quantile regression with statsmodels
#!/usr/bin/env python3
import matplotlib.pyplot as plt
import numpy as np
import statsmodels.formula.api as smf
x = np.linspace(0, 2, 100)
y = np.sqrt(x) * np.sin(2 * np.pi * x) + np.random.random_sample(100)
@tavin
tavin / consecutive.py
Created June 1, 2018 12:25
count the longest line of consecutive True along an axis
def consecutive(cond, axis):
cond = np.moveaxis(cond, axis, -1)
measure = np.zeros(cond.shape[:-1], dtype=np.uint32)
diff = np.diff(cond)
for index in np.ndindex(measure.shape):
boundary = np.flatnonzero(diff[index])
if not len(boundary):
continue
if cond[index][0]:
boundary = np.insert(boundary, 0, -1)
#!/bin/bash
fibs=(1 1)
while ((fibs[-1] < 200))
do
echo ${fibs[@]}
fibn=$((fibs[-1] + fibs[-2]))
fibs+=($fibn)
done
from base64 import b64encode
from subprocess import check_call
from subprocess import check_output
from tempfile import mkdtemp
def lambda_handler(_event, _context):
tmp = mkdtemp(dir='/tmp')
check_call(['pip', 'install', 'psycopg2', '--target', tmp])
tar = check_output(['tar', '-C', tmp, '-cz', '.'])
@tavin
tavin / chain.py
Created March 15, 2019 17:57
wrap a chain of callables
def chain(iterable):
i, f = 0, None
scope = {}
loc = []
for i, f in enumerate(iterable):
name = '_' + str(i)
scope[name] = f
loc.append(name + '(*a,**k)')
if i == 0:
return f
#!/bin/sh -ex
export WINEPREFIX=$PWD
export WINEARCH=win32
wineboot
winetricks -q dotnet35sp1
winetricks -q corefonts
winetricks -q windowscodecs || cabextract \
~/.cache/winetricks/windowscodecs/wic_x86_enu.exe -F 'windowscodecs*.dll' -d drive_c/windows/system32
wine ADE_2.0_Installer.exe
perl -pe '/time=\S+\.\.(\S+) rows=(\d+) loops=(\d+)/; print $3*$1, "\t";' explain.out
jupyter contrib nbextension install --user
jupyter nbextension enable equation-numbering/main
%%javascript
MathJax.Hub.Config({
TeX: {
equationNumbers: {
autoNumber: "AMS"
}
}
});
@tavin
tavin / pgbench.sh
Created February 24, 2021 14:27
pgbench.sh
#!/bin/bash
set -ex
scale=20 # table size factor; should not be less than $clients
clients=10 # number of concurrent sessions
jobs=$((`nproc`/2)) # threads i.e. how many cpus to use
duration=300 # length of test in seconds
progress=10 # progress reporting interval
filesystem=postgresql/pgbench