Skip to content

Instantly share code, notes, and snippets.

Avatar

Martin Becker mgbckr

View GitHub Profile
@mgbckr
mgbckr / matplotlib_subplots_legend_bottom_center.py
Last active Feb 2, 2020
Matplotlib subplots legend bottom center; does not work in Jupyter but the output is fine
View matplotlib_subplots_legend_bottom_center.py
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
mgbckr / load_file_from_module.py
Last active Aug 15, 2019
Access path of file in module (even if in zip file) in Python
View load_file_from_module.py
# Source: https://stackoverflow.com/a/20885799/991496
# IMPORANT: There needs to be a `__init__.py` in `your.lib.resources`
# otherwise `pkg_resources.path` throws a FileNotFoundError saying "<resource> resource not found in <package_name>".
import your.lib.resources
try:
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 https://gist.github.com/mgbckr/6079e9ac26b33d9ae393791ce4fd7214
// @version 1.0.0
// @updateURL https://gist.github.com/mgbckr/6079e9ac26b33d9ae393791ce4fd7214/raw/mlflowuihelper.user.js
// @downloadURL https://gist.github.com/mgbckr/6079e9ac26b33d9ae393791ce4fd7214/raw/mlflowuihelper.user.js
// @description Enhances MLflow UI (see https://mlflow.org)
// @author Martin Becker
// @match http://localhost:7777
// @match http://localhost:5000
@mgbckr
mgbckr / calculate_correlations_parallel.py
Last active Feb 9, 2019
A parallel and sparse approach to calculating correlations between columns of a Pandas DataFrame
View calculate_correlations_parallel.py
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
mgbckr / tiddlywiki_apache_proxy_subdir.md
Last active Jan 24, 2019
How to use TiddlyWiki behind an Apache Proxy in a Sub- (folder / path / URL)
View tiddlywiki_apache_proxy_subdir.md

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

TiddlyWiki

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.

Apache

@mgbckr
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
mgbckr / install_zsh_on_sherlock.sh
Last active Aug 6, 2020
Compiling and installing Zsh without root privileges on Stanford's Sherlock (https://sherlock.stanford.edu) for use in tmux
View install_zsh_on_sherlock.sh
# # Install Zsh on Sherlock
# Installs Zsh with Oh-My-Zsh without root privileges
# on Stanford's Sherlock (https://sherlock.stanford.edu) for use in tmux
#
# ## Instructions
# 1) bash install_zsh.sh
# 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
mgbckr / utop.sh
Created Dec 17, 2018
Script to show CPU usage (percent) by user
View utop.sh
#!/bin/bash
# start with `watch -n 1 bash utop.sh` for continuous monitoring
top -b -n 1 | awk '
NR <= 7 { print; next }
{ a[$2] += $9 }
END {
for (i in a) {
printf "%-15s\t%s\n", i, a[i];
}
}
View exp.py
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
mgbckr / plot_multiple_axes.py
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.
View plot_multiple_axes.py
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.