Skip to content

Instantly share code, notes, and snippets.

View mgbckr's full-sized avatar

Martin Becker mgbckr

View GitHub Profile
@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 / 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 / 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 / install_zsh_on_sherlock.sh
Last active April 8, 2024 05:49
Compiling and installing Zsh without root privileges on Stanford's Sherlock (https://sherlock.stanford.edu) for use in tmux
# Update 2023-07-20:
# I've recently switched to installing `zsh` via `conda` which is a lot less hassle.
# I added it to start automatically in `tmux` with
# `set-option -g default-shell "~/miniconda3/envs/default/bin/zsh"`
#
# # 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
@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 / 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))]
@mgbckr
mgbckr / pull_database_from_android.bash
Last active March 2, 2018 13:48
Small set of commands to download a database file (or any file) from an android device using `adb`
./adb shell
run-as the.package.of.the.application
cd /data/data/dthe.package.of.the.application/databases
chmod 777 TheDatabase.db
cp TheDatabase.db /mnt/sdcard/
./adb pull /mnt/sdcard/TheDatabase.db