Skip to content

Instantly share code, notes, and snippets.

Avatar

Kevin Kirsche kkirsche

View GitHub Profile
@kkirsche
kkirsche / tomlpath.py
Last active Sep 14, 2022
TOML Path — A simple utility class to retrieve a specific key path in a TOML file
View tomlpath.py
from os import PathLike
from functools import reduce
from operator import getitem
try:
# 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
kkirsche / write-blob.go
Last active Aug 24, 2022
Writing Git Blob Objects
View write-blob.go
package main
import (
"bytes"
"compress/zlib"
"crypto/sha1"
"encoding/hex"
"fmt"
"io"
"os"
@kkirsche
kkirsche / rsync.py
Last active Aug 12, 2022
rsync algorithm in Python
View rsync.py
#!/usr/bin/env python
# based on
# https://tylercipriani.com/blog/2017/07/09/the-rsync-algorithm-in-python/
from collections.abc import Generator
from hashlib import md5
from io import BufferedReader, TextIOWrapper
from logging import DEBUG, INFO, basicConfig, getLogger
from os import PathLike
View asdf-update-all
#!/usr/bin/env python
from shlex import split
from subprocess import CompletedProcess, run
from typing import cast
from packaging.version import parse
from requests import get
@kkirsche
kkirsche / foreign-keys.md
Created Mar 11, 2022
Locating Database Errors
View foreign-keys.md

If you ever run into:

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

Run:

mariadb -e "SHOW ENGINE INNODB STATUS"
@kkirsche
kkirsche / asdf-updater.sh
Created Feb 11, 2022
ASDF Version Checker / Updater
View asdf-updater.sh
#!/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
kkirsche / functions.sh
Last active Dec 19, 2021
Useful functions to have in a shell
View functions.sh
# Load via:
# if [ -f "${HOME}/.functions.sh" ]; then . "${HOME}/.functions.sh"; fi
# MIT License
if [ "${PLATFORM}" = "Linux" ]; then
alias pbcopy='xclip -selection clipboard'
alias pbpaste='xclip -selection clipboard -o'
fi
function extract() {
@kkirsche
kkirsche / reserved_words_retriever.py
Last active Oct 19, 2021
Reserved Word Retriever for SQLAlchemy
View reserved_words_retriever.py
#!/usr/bin/env python
"""Usage Example:
$ python reserved_words_retriever.py --help
usage: reserved_words_retriever.py [-h] [-y] [-a] [-w] [-d]
Retrieve the reserved keywords for MySQL and/or MariaDB
options:
-h, --help show this help message and exit
@kkirsche
kkirsche / soundex.py
Last active Jul 30, 2021
SOUNDEX implementation
View soundex.py
#!/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:
https://en.wikipedia.org/wiki/Soundex#American%20Soundex
View tree_node_sum.py
#!/usr/bin/env python
from __future__ import annotations
from uuid import uuid4, UUID
from typing import Sequence
class Node:
node_id: UUID
time_to_complete: int
children: Sequence[Node]