Skip to content

Instantly share code, notes, and snippets.

View TheLonelyGhost's full-sized avatar

David Alexander TheLonelyGhost

View GitHub Profile
@TheLonelyGhost
TheLonelyGhost / recruiter_seive.py
Created September 9, 2021 03:37
Compose valid Seive code (Fastmail filters) for recruiter spam
from typing import List
import json
def is_wildcard(email) -> bool:
return bool('*' in email)
def main():
@TheLonelyGhost
TheLonelyGhost / ansi-escape-string
Created September 9, 2021 07:40
Remove all ANSI escape sequences from a given string
#!/usr/bin/env python3
import fileinput
import re
# 7-bit C1 ANSI sequences
ansi_escape = re.compile(r'''
\x1B # ESC
(?: # 7-bit C1 Fe (except CSI)
[@-Z\\-_]
@TheLonelyGhost
TheLonelyGhost / list-paths
Created September 9, 2021 07:42
list all the places in one's PATH where a command might be. More reliable than `whence` in a cross-platform setting
#!/usr/bin/env bash
set -euo pipefail
if [ $# -lt 1 ]; then
printf 'USAGE: list-paths <command>\n' 1>&2
exit 1
fi
bin="$1"
found=0
@TheLonelyGhost
TheLonelyGhost / git-line-stat
Created September 9, 2021 07:44
determine how many lines added and removed from a given commit-ish (ref, brach, whatever)
#!/usr/bin/env bash
set -euo pipefail
git diff --numstat "$@" | awk '{ sum_plus+=$1; sum_minus+=$2 } END { print("+++++ ", sum_plus); print("----- ", sum_minus); }'