Skip to content

Instantly share code, notes, and snippets.

@eikevons
eikevons / traverse_nested_dict.py
Last active March 19, 2024 06:46
Iterate/traverse over a nested Python dict
def traverse_nested_dict(
d: dict, min_depth: int = 0, max_depth: int | None = None, yield_objects=True
):
"""Traverse over a nested dict.
Creates a generator yielding key-value pairs. Keys will be tuples containing the path to the value, e.g.::
(top_key, level_1_key), value
Parameters
@eikevons
eikevons / pre-commit.max-file-size
Last active June 26, 2023 13:20
git pre-commit hook to prevent checking in large files
#!/bin/sh
# Maximum file size limit in MiB
limitMiB=${GIT_MAX_MIB:-5} # Default 5MiB
if [ $limitMiB -le 0 ]; then
exit 0
fi
# Go to repo root folder
cd "$(git rev-parse --show-toplevel)"
@eikevons
eikevons / nmvpn-fzf.sh
Created June 7, 2022 14:43
Manage network manager VPNs via fzf menu
#!/bin/bash
# Restart in terminal if called without one
if [ ! -t 1 ]; then
urxvt -name "dwm-floating" -title vpn -geometry 120x20 -e "$0"
fi
all_off="all off"
list_vpns () {
@eikevons
eikevons / aws.docker.sh
Last active December 23, 2021 14:44
Wrap around dockerized AWS CLI
#!/bin/sh
# Simple wrapper around AWS CLI docker image to share the users config but
# keeping the file permissions consistent on Linux.
# Make this executable and put this as aws in your $PATH
set -e
CONFDIR="$HOME/.aws"
@eikevons
eikevons / memoizing_dag.py
Created August 19, 2020 15:27
Simple memoizing DAG in Python using decorators
from functools import wraps
from inspect import getmembers, ismethod
class MemoizingDAG:
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# memory of target results
self._built_targets = {}
@eikevons
eikevons / get-ipytion-notebook-name.js
Last active March 12, 2019 10:47
Get notebook name in IPython
%%javascript
var kernel = IPython.notebook.kernel;
var thename = window.document.getElementById("notebook_name").innerHTML;
var command = "notebook_name = " + "'" + thename + "'";
kernel.execute(command);
@eikevons
eikevons / Makefile
Last active February 12, 2023 11:04
Makefile template to build dependent docker images and auto-create dependencies on all git-tracked files.
# Copyright (c) Jupyter Development Team
# Jan Eike von Seggern <eikevons@yahoo.de>
# Distributed under the terms of the Modified BSD License.
## Template to build a hierarchy of dependent docker images.
## Based on https://github.com/jupyter/docker-stacks/blob/master/Makefile
## Builds are tracked via build-stamps in $BUILD_DIR.
## Dependencies for each image are created automatically for all files tracked by git.
##
## Usage (see examples below):
@eikevons
eikevons / numpy_group_indices.py
Created February 3, 2016 10:59
Get groups of windowed indices of numpy array
import numpy as np
def group_indices(sarr, window_size=None, start=None):
"""Get list with indices of entries of sorted `sarr` grouped in windows.
Parameters
----------
sarr : ndarray
Sorted array.
window_size : float, optional
@eikevons
eikevons / combine-quantiles.ipynb
Last active August 29, 2015 14:22
Combine Quantiles
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@eikevons
eikevons / cwd.diff
Created October 25, 2012 18:24
cwd patch for dwm
diff -r 8f9965d9727f Makefile
--- a/Makefile Wed Oct 03 15:54:17 2012 +0200
+++ b/Makefile Thu Oct 25 20:10:54 2012 +0200
@@ -24,7 +24,7 @@
@echo creating $@ from config.def.h
@cp config.def.h $@
-dwm: ${OBJ}
+dwm: ${OBJ} cwd.c
@echo CC -o $@