Skip to content

Instantly share code, notes, and snippets.

View kkirsche's full-sized avatar

Kevin Kirsche kkirsche

View GitHub Profile
@kkirsche
kkirsche / rsync.py
Last active August 12, 2022 12:38
rsync algorithm in Python
#!/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
@kkirsche
kkirsche / mount-shared-folders
Last active May 17, 2022 14:09
Mount or restart open VM toolchain
#!/bin/sh
# to install:
# git clone https://gist.github.com/381e17fab1457ccf3b8b750edbc40b79.git msd
# mv ./msd/mount-shared-folders /usr/local/bin
# rm -rf ./msd
# chmod +x /usr/local/bin/mount-shared-folders
# Source: https://gitlab.com/kalilinux/packages/kali-tweaks/-/blob/kali/master/data/mount-shared-folders
@kkirsche
kkirsche / foreign-keys.md
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")

Run:

mariadb -e "SHOW ENGINE INNODB STATUS"
@kkirsche
kkirsche / asdf-updater.sh
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
kkirsche / functions.sh
Last active December 19, 2021 13:36
Useful functions to have in a shell
# 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 / add_auth_key.sh
Last active November 12, 2021 21:07
Add Local SSH Keys to Remote Machine
cat ~/.ssh/id_rsa.pub | ssh <username>@<ip_address> "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys"
@kkirsche
kkirsche / reserved_words_retriever.py
Last active October 19, 2021 14:26
Reserved Word Retriever for SQLAlchemy
#!/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 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:
https://en.wikipedia.org/wiki/Soundex#American%20Soundex
#!/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]
import re
# https://github.com/sqlalchemy/alembic/blob/c97d5b3dd6fde31acb8e9e0c67d0ebc54fa0d809/alembic/script/base.py#L682
_slug_re = re.compile(r"\w+")
truncate_slug_length = 40
def generate_slug(message: str) -> str:
slug = "_".join(_slug_re.findall(message or "")).lower()
if len(slug) > truncate_slug_length:
slug = slug[: truncate_slug_length].rsplit("_", 1)[0] + "_"