Skip to content

Instantly share code, notes, and snippets.

View kkirsche's full-sized avatar

Kevin Kirsche kkirsche

View GitHub Profile
kkirsche /
Last active December 11, 2023 16:34
Versioning Troubleshooting
#!/usr/bin/env python
"""Versioned mixin class and other utilities."""
from __future__ import annotations
import datetime
from import Callable, Generator
from typing import TypeAlias, Any
kkirsche /
Last active September 14, 2022 19:28
TOML Path — A simple utility class to retrieve a specific key path in a TOML file
from os import PathLike
from functools import reduce
from operator import getitem
# Python 3.11+
from tomllib import load, loads
except ImportError:
from tomli import load, loads
from typing import Any, BinaryIO, Iterable, Mapping, TypeAlias, TypeGuard, Union
kkirsche / write-blob.go
Last active August 24, 2022 13:24
Writing Git Blob Objects
package main
import (
kkirsche /
Last active August 12, 2022 12:38
rsync algorithm in Python
#!/usr/bin/env python
# based on
from import Generator
from hashlib import md5
from io import BufferedReader, TextIOWrapper
from logging import DEBUG, INFO, basicConfig, getLogger
from os import PathLike
kkirsche / asdf-update-all
Last active July 11, 2023 15:01
ASDF Auto Updater
#!/usr/bin/env bash
set -euo pipefail
function version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; }
if ! command -v jq &> /dev/null
echo "jq could not be found"
kkirsche /
Created March 11, 2022 17:41
Locating Database Errors

If you ever run into:

(1005, 'Can't create table `database_name`.`table_name` (errno: 150 "Foreign key constraint is incorrectly formed")


kkirsche /
Created February 11, 2022 10:40
ASDF Version Checker / Updater
#!/usr/bin/env bash
set -eu -o pipefail;
function check {
PLUGINS=$(asdf plugin list)
echo "Plugin Current Latest"
for plugin in ${PLUGINS}; do
LATEST_VERSION=$(asdf latest ${plugin})
CURRENT_VERSION=$(asdf current ${plugin}| perl -lne 'print $& if /((\d+\.){2}\d+(-otp-\d+)?)/')
kkirsche /
Last active December 19, 2021 13:36
Useful functions to have in a shell
# Load via:
# if [ -f "${HOME}/" ]; then . "${HOME}/"; fi
# MIT License
if [ "${PLATFORM}" = "Linux" ]; then
alias pbcopy='xclip -selection clipboard'
alias pbpaste='xclip -selection clipboard -o'
function extract() {
kkirsche /
Last active October 19, 2021 14:26
Reserved Word Retriever for SQLAlchemy
#!/usr/bin/env python
"""Usage Example:
$ python --help
usage: [-h] [-y] [-a] [-w] [-d]
Retrieve the reserved keywords for MySQL and/or MariaDB
-h, --help show this help message and exit
kkirsche /
Last active July 30, 2021 17:44
SOUNDEX implementation
#!/usr/bin/env python
"""The following module is an implementation of American SOUNDEX.
SOUNDEX is a phonetic algorithm for indexing names by sound, as pronounced in English.
The goal is for homophones to be encoded to the same representation so that they can be
matched despite minor differences in spelling.
This implements the algorithm as defined on: