Skip to content

Instantly share code, notes, and snippets.

View mgbckr's full-sized avatar

Martin Becker mgbckr

View GitHub Profile
@mgbckr
mgbckr / tiddlywiki_apache_proxy_subdir.md
Last active March 15, 2021 17:42
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).

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 / matplotlib_subplots_legend_bottom_center.py
Last active February 2, 2020 06:30
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
mgbckr / load_file_from_module.py
Last active August 15, 2019 19:04
Access path of file in module (even if in zip file) in Python
# 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
// ==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 February 9, 2019 07:28
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
mgbckr / tmux_cheatsheet.tmux
Last active January 23, 2019 00:37
My TMUX cheatsheet
# 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 / utop.sh
Created December 17, 2018 17:15
Script to show CPU usage (percent) by user
#!/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];
}
}
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 / AccessFileOnClasspath
Last active July 14, 2018 12:55
Resource access in Maven projects.
/**
* <p>Shows how files in the class path can be accessed when using the standard
* Maven directory layout.</p>
*
* <p>The test file is "src/test/resources/accessFileOnClasspath/test.txt".
* It is accessed using either {@link ClassLoader#getResource(String)} or
* {@link ClassLoader#getResourceAsStream(String)}. Note that the file's
* path is always relative to the class path's root. Thus the test file is
* accessed using "accessFileOnClasspath/test.txt".</p>
*
@mgbckr
mgbckr / plot_multiple_axes.py
Created May 2, 2018 09:21
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))]