Skip to content

Instantly share code, notes, and snippets.

@ahue
ahue / license-plate-regex.md
Created April 22, 2022 12:02
License Plate Regex

Only guarantees structural compliance to definition

Germany

[A-ZÄÜÖ]{2,3}[ -][A-ZÄÜÖ]{1,2}[ -]\d{1,4}

Source

@ahue
ahue / obsidian.sh
Created April 10, 2022 12:49
Obsidian pull-push script for Android
#!/data/data/com.termux/files/usr/bin/bash
cd ~/storage/shared/documents/my-vault
git add --all
git commit -m "mobile update $(date)"
git pull --rebase
git push origin main
@ahue
ahue / fix-docker-machine-time-sync.ps1
Created March 29, 2022 20:18
fix-docker-machine-time-sync.ps1
$vm = Get-VM -Name DockerDesktopVM
$feature = "Zeitsynchronisierung"
Disable-VMIntegrationService -vm $vm -Name $feature
Enable-VMIntegrationService -vm $vm -Name $feature
cd ~/storage/shared/documents/my-vault
git pull --rebase
git add --all
git commit -m "mobile update $(date)"
git push origin main
@ahue
ahue / zh_sync.sh
Last active January 5, 2022 20:33
obsidian sync script
#!/data/data/com.termux/files/usr/bin/bash
# ^^^^^^^^^^^^^^^ This says find the first instance of a sh (shell)
# binary and use that shell to execute these commands.
# There is little to no complexity here and no bashisms so it
# should work just fine on most systems and instances of shells
# (bash, zsh, sh, etc.)
# original from: https://gist.githubusercontent.com/lucidhacker/0d6ea6308997921a5f810be10a48a498/raw/386fd5c640282daeaa3c9c5b7f4e875511c2946c/zk_sync.sh
# modified according to: https://lucidhacker.substack.com/p/setting-up-git-syncing-for-obsidian
@ahue
ahue / cluster_corr.py
Last active May 4, 2021 08:40
Rearranges the correlation matrix, corr_array, so that groups of highly correlated variables are next to eachother
import scipy
import scipy.cluster.hierarchy as sch
def cluster_corr(corr_array, inplace=False, impute_nan=False):
"""
Original author: @WYegelwel (https://wil.yegelwel.com/cluster-correlation-matrix/)
Rearranges the correlation matrix, corr_array, so that groups of highly
correlated variables are next to eachother
@ahue
ahue / cardinalities.py
Created May 3, 2021 11:52
Analyize cardinalities of a pandas Data.Frame
import pandas as pd
import seaborn as sns
def cardinalities(df: pd.DataFrame, plot: bool = False):
"""
Analyses cardinalities in a data frame
df DataFrame the data frame to be analyized
plot Plot whether to plot rather than return the result DataFrame
returns (DataFrame, Plot) of a matrix M(i,j) that reads row-wise,
@ahue
ahue / gist:98eb5a7744c24bb2b2b358985acefdc4
Created April 14, 2021 20:58
Filter a 3d array on one dimension using and 2d index to receive a 2d array
import numpy as np
def filter_tensor_by_mx(tensor, mx):
tshape = tensor.shape
row_ix = np.arange(mx.shape[0])
col_ix = np.arange(mx.shape[1])
ix = np.array(np.meshgrid(row_ix, col_ix)).T.reshape(-1,2).T
pane = rnd_ix_mx.ravel()
res = tensor[pane, ix[0], ix[1]].reshape(mx.shape)
return res
@ahue
ahue / motion.conf
Last active March 26, 2021 06:57
Configure raspberry pi zero for motion with gif creation and mqtt
# Rename this distribution example file to motion.conf
#
# This config file was generated by motion 4.1.1
# Documentation: /usr/share/doc/motion/motion_guide.html
############################################################
# Daemon
############################################################
# Start in daemon (background) mode and release terminal (default: off)
@ahue
ahue / cyclical_feature.py
Created February 15, 2021 21:09
Because I tend to forget... building cyclical features
import numpy as np
from typing import Union
def cyclical_feature(x: Union(float|np.array), max_x: float):
"""
Transforms a linear scale feature to a feature pair that represent a cyclical one.
Assumes that the feature is in interval [0, max_x]
See also https://towardsdatascience.com/cyclical-features-encoding-its-about-time-ce23581845ca