Skip to content

Instantly share code, notes, and snippets.


Martin Becker mgbckr

View GitHub Profile
mgbckr /
Last active Feb 2, 2020
Matplotlib subplots legend bottom center; does not work in Jupyter but the output is fine
import matplotlib.pyplot as plt
import matplotlib.lines
# matplotlib.rcParams["legend.frameon"] = False # need to set this once to enable styling??? WTF???
titles = ["title 1", "title 2", "title 3", "title 4"]
colors = ['#ffd600', '#f44336', '#43a047', '#1e88e5', '#ab47bc', '#3f51b5', '#f57c00']
# init figure / plot
fig, axes = plt.subplots(1, len(titles), figsize=(5*len(titles) - 3, 5))
for i_t, ax in enumerate(axes):
mgbckr /
Last active Aug 15, 2019
Access path of file in module (even if in zip file) in Python
# Source:
# IMPORANT: There needs to be a `` in `your.lib.resources`
# otherwise `pkg_resources.path` throws a FileNotFoundError saying "<resource> resource not found in <package_name>".
import your.lib.resources
import importlib.resources as pkg_resources
except ImportError:
# Try backported to PY<37 `importlib_resources`.
import importlib_resources as pkg_resources
View mlflowuihelper.user.js
// ==UserScript==
// @name MLflow UI Helper
// @namespace
// @version 1.0.0
// @updateURL
// @downloadURL
// @description Enhances MLflow UI (see
// @author Martin Becker
// @match http://localhost:7777
// @match http://localhost:5000
mgbckr /
Last active Feb 9, 2019
A parallel and sparse approach to calculating correlations between columns of a Pandas DataFrame
def calculate_correlations(df, correlation_threshold=0.3, pvalue_threshold=0.05):
shape = (df.shape[1], df.shape[1])
correlation_matrix = sp.sparse.lil_matrix(shape)
pvalues = sp.sparse.lil_matrix(shape)
mask = sp.sparse.lil_matrix(shape)
overlap = sp.sparse.lil_matrix(shape)
def column_corr(col1_idx):
mgbckr /
Last active Jan 24, 2019
How to use TiddlyWiki behind an Apache Proxy in a Sub- (folder / path / URL)

This Gist is about how to setup TiddlyWiki behind an Apache proxy in a sub- (folder / path / URL).


When starting TiddlyWiki add a path-prefix:

tiddlywiki --listen "path-prefix=/my/path"

The alternative is using a specific tiddler, but that did not work for me for some reason.


mgbckr / tmux_cheatsheet.tmux
Last active Jan 23, 2019
My TMUX cheatsheet
View tmux_cheatsheet.tmux
# assume hitting STRG+B before each command
# windows
l switch to last window
, rename
:set-option -g allow-rename off disable auto-rename of windows
# panes
% split window
" split window
mgbckr /
Last active Aug 6, 2020
Compiling and installing Zsh without root privileges on Stanford's Sherlock ( for use in tmux
# # Install Zsh on Sherlock
# Installs Zsh with Oh-My-Zsh without root privileges
# on Stanford's Sherlock ( for use in tmux
# ## Instructions
# 1) bash
# 2) edit .zshrc (add the path to your Zsh binary to the PATH variable, etc.)
# 3) add `set-option -g default-shell <path to zsh>/bin/zsh` to `~/.tmux.conf`
# 4) also see comments for potential further notes
mgbckr /
Created Dec 17, 2018
Script to show CPU usage (percent) by user
# start with `watch -n 1 bash` for continuous monitoring
top -b -n 1 | awk '
NR <= 7 { print; next }
{ a[$2] += $9 }
for (i in a) {
printf "%-15s\t%s\n", i, a[i];
import numpy as np
from sklearn import svm
import sklearn as sk
def exp(majority_vote=False, n=1000):
# data
y = np.array([1,2] * 14)
x = np.random.rand(len(y), 100)
mgbckr /
Created May 2, 2018
A helper function to plot data with multiple axes using Python's matplotlib. Adjust to your needs. Obviously needs some clean up.
def plot_multiple_axes(data, columns, x= "timestamp", colors=["black", "r-", "g-", "c-", "m-", "y-"], window=60):
TODO: Needs some clean up
:type data: pandas.DataFrame
:type columns: list of str
fig, host = plt.subplots(figsize=(20, 4))
axes = [host] + [host.twinx() for c in range(1, len(columns))]
You can’t perform that action at this time.