Skip to content

Instantly share code, notes, and snippets.

View hexpunk's full-sized avatar

Jay Sherby hexpunk

  • 18:37 (UTC -05:00)
View GitHub Profile
/**
* This is the type of function you'd pass to [`Array.prototype.sort()`](
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
* )
*/
type CompareFn<T> = (a: T, b: T) => SortResult;
const enum SortResult {
A_AFTER_B = 1,
A_BEFORE_B = -1,
function debug<V, M>(value: V, message?: M): V {
if (message === undefined) {
console.debug(value);
} else {
console.debug(message, value);
}
return value;
}
@hexpunk
hexpunk / msort.py
Last active March 5, 2022 05:17
Sorts a list of strings using a series of interactive prompts
#!/usr/bin/env python3
import argparse
import random
import sys
def eprint(*args, **kwargs):
"""Like print but for stderr"""
print(*args, file=sys.stderr, **kwargs)
@hexpunk
hexpunk / tourney.py
Last active March 5, 2022 05:16
Determines the top string in a list using an interactive single-elimination tournament
#!/usr/bin/env python3
import argparse
import random
import sys
def eprint(*args, **kwargs):
"""Like print but for stderr"""
print(*args, file=sys.stderr, **kwargs)
@hexpunk
hexpunk / check_github_login.py
Last active March 4, 2022 23:51
Checks availability of FILE(s) as login names for GitHub
#!/usr/bin/env python3
import argparse
import http.client
import itertools
import json
import os
import sys
import textwrap
from datetime import datetime
@hexpunk
hexpunk / permute.py
Last active March 4, 2022 23:50
Print the cartesian product of the lines in FILE(s) multiplied with itself REPEAT times to standard output
#!/usr/bin/env python3
import argparse
import itertools
import os
import sys
def positive_int(string):
"""Return a positive int from the argument string or raise an ArgumentTypeError"""
@hexpunk
hexpunk / consonant_vowel_pattern.awk
Created March 1, 2022 03:54
Awk script to assist in consonant-vowel frequency analysis
#!/bin/awk -f
# Converts words into consonant-vowel patterns
# Combine output with `sort | uniq -c | sort -rg` to list most to least common
{
split(tolower($1), chars, "")
for (i in chars) {
char = chars[i]
@hexpunk
hexpunk / find_github_logins.py
Last active March 1, 2022 03:52
Exhaustively check GitHub username/organization availability by length
#!/usr/bin/env python3
import argparse
import http.client
import json
import os
import string
import sys
from datetime import datetime
from itertools import islice, product
@hexpunk
hexpunk / remove_metadata.sh
Last active December 10, 2021 05:03
Remove metadata from videos using ffmpeg
#!/bin/sh
set -eu
for target in "$@"; do
original=$target.original
if mv "$target" "$original"; then
if ! ffmpeg -hide_banner \
-i "$original" \
-map_metadata -1 \
/usr/bin/time -l sh -c "find -type f -not -path '\./\.git/*' -not -path '\./node_modules/*' -exec sh -c \"git --no-pager blame --line-porcelain '{}' | sed -n 's/^author //p'\" 2>/dev/null \; | sort | uniq -c | sort -rn"