Skip to content

Instantly share code, notes, and snippets.


Andreas Stöckel astoeckel

View GitHub Profile
astoeckel /
Created Aug 11, 2021
Environment Guard
import os
class EnvGuard:
Class used to temporarily set some environment variables to a certain value.
In particular, this is used to set the variable OMP_NUM_THREADS to "1" for
each of the subprocesses using cvxopt.
def __init__(self, env={}):
self.env = env
astoeckel /
Created Jul 23, 2021
Compute neuron transfer function
def compute_transfer_function(us, xs, dt=dt, smoothing=100.0):
Us = np.fft.fftshift(np.fft.fft(us))
Xs = np.fft.fftshift(np.fft.fft(xs))
fs = np.fft.fftshift(np.fft.fftfreq(len(us), dt))
wnd = np.exp(-np.square(fs) / np.square(smoothing))
wnd /= np.sum(wnd) * dt
UXs = np.fft.fftshift(np.fft.fft(Us * np.conj(Xs)))
astoeckel /
Created Feb 27, 2021
Fuzzy Jaccard similarity based search
def fuzzy_find(term, lst, threshold=0.75, shingle_len=3):
# Create a set of n-grams of length shingle_len
def shingle(s):
shingles = []
for t in re.split(' ', s):
for i in range(max(1, len(t) - shingle_len)):
return set(shingles)
# Computes the Jaccard similarity between two sets
astoeckel /
Created Jan 29, 2021
Python 2D z-order curve
def zorder(N):
if N == 0:
return np.zeros((0, 0),
elif N == 1:
return np.zeros((1, 2),
pnts = zorder(N - 1)
l = pnts.shape[0]
offs = 2 ** (N - 2)
res = np.zeros((4 * l, 2),
astoeckel / nbdkit.service
Last active Nov 16, 2020
nbdkit systemd socket and service file
View nbdkit.service
# nbdkit.service
Description=nbdkit Service
astoeckel /
Created Nov 15, 2020
Compiling and installing nbdkit on CentOS 7
# Downloads NBDKit and builds a minimal version. This minimal version only
# installs basic plugins and filters, and the SSH plugin.
# For compilation to succeed, you'll need to install
# yum install gcc gcc-c++ libssh-devel openssl-devel autoconf automake libtool
# Also, best create a user nbdkit
# adduser --system --user-group --shell /sbin/nologin --home-dir /opt/nbdkit --create-home nbdkit
astoeckel / gist:fae7fd37a0f5c5f48bce03bee301fbcd
Created Apr 29, 2020
Libre Office Export All Sheets As CSV
View gist:fae7fd37a0f5c5f48bce03bee301fbcd
Sub ExportAllToCsv
document = ThisComponent
' Use the global string tools library to generate a base filename for each CSV
' based on the current prefixless filename
DocumentName = Left(document.Namespace, Len(document.Namespace) - 1)
BasePath = Tools.Strings.DirectoryNameoutofPath(DocumentName, "/")
BaseFilename = Tools.Strings.GetFileNameWithoutExtension(DocumentName, "/")
astoeckel / csc_matrix.cpp
Last active Jan 22, 2020
CSC Matrix Operations -- Code I wrote before I realised that Eigen can be made to directly interface with CSC matrices via SparseMatrix and makeCompressed()
View csc_matrix.cpp
* libbioneuronqp -- Library solving for synaptic weights
* Copyright (C) 2020 Andreas Stöckel
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
astoeckel / mount.qcow2
Last active Dec 25, 2019
Mounts a LUKS encrypted QCOW2 image
View mount.qcow2
if test -z "$QCOW2_ACTION" || test -z "$QCOW2_FILENAME" || test -z "$QCOW2_MOUNTPOINT"; then
echo "Usage: mount.qcow2 <mount|unmount> <FILENAME> <MOUNTPOINT>";
exit 1
astoeckel /
Created Aug 11, 2019
Python script that transfers the ratings from multiple Rhythmbox databases into a single Rhythmbox database. If the same song exists multiple times in the target database, only the one with the highest quality is assigned a rating.
#!/usr/bin/env python3
import os
import sys
import urllib.parse
import urllib.request
import lxml.etree as ET
import icu
import collections
import math