Skip to content

Instantly share code, notes, and snippets.

@quidmonkey
quidmonkey / whoiswinning.sh
Created July 14, 2026 15:10
Who is winning?
# display git authors, commits, added lines, deleted lines
function who_is_winning {
git log --format='author %aN' --numstat | awk '
/^author / { author = substr($0, 8); commits[author]++; next }
NF == 3 { add[author] += $1; del[author] += $2 }
END {
printf "%-30s %8s %10s %10s\n", "Author", "Commits", "Added", "Deleted"
for (n in commits) printf "%-30s %8d %10d %10d\n", n, commits[n], add[n], del[n] | "sort -rn -k1.31"
}'
}
@quidmonkey
quidmonkey / docker-compose.yml
Created June 26, 2026 11:09
DNS Hosting + JellyFin/*Arr Stack
services:
# ---------------------------------------------------------------------------
# Gluetun — VPN gateway (ProtonVPN via WireGuard). qBittorrent routes through
# this container's network. If Gluetun dies, qBittorrent loses all network =
# no IP leak.
# ---------------------------------------------------------------------------
gluetun:
image: qmcgaw/gluetun:latest
container_name: gluetun
cap_add:
@quidmonkey
quidmonkey / claudesearch
Created April 24, 2026 16:37
Search past Claude conversations for keywords e.g. claudesearch -h
claudesearch() {
if [[ "$1" == "-h" || "$1" == "--help" || $# -eq 0 ]]; then
echo "Usage: claudesearch <keyword> [keyword2 ...]"
echo " claudesearch -r <session-id>"
echo ""
echo "Options:"
echo " -h Show this help"
echo " -r <id> Resume a session by ID"
echo ""
echo "Examples:"
@quidmonkey
quidmonkey / main.js
Last active June 15, 2025 20:38
Nodejs Postgres Migrations with Multi-Schema Support in the vein of the postgres-migrations lib
const minimist = require('minimist);
Const { migrateAll } = require('./migrate');
const args = require('minimist')(process.argv.slice(2));
const dir = args.dir;
if (!dir) {
console.error('Usage: node migrate.js --dir <migrationsDir>');
process.exit(1);
}
@quidmonkey
quidmonkey / db.ts
Last active June 9, 2025 12:30
Nodejs SQL Querying (node-pg) with Schemas/Types (zod), Error Handling, Logging, String Interpolation, and No ORM
import { Pool } from 'pg';
import { ZodSchema } from 'zod';
// Initialize the database connection pool
const pool = new Pool({
user: 'your_db_user',
host: 'localhost',
database: 'your_db_name',
password: 'your_password',
port: 5432,
@quidmonkey
quidmonkey / numberMap.js
Created August 9, 2023 12:52
Map a Number from One Value System to Another
Number.prototype.map = (istart, istop, ostart, ostop) => {
return ostart + (ostop - ostart) * ((this - istart) / (istop - istart));
};
const map = (value, istart, istop, ostart, ostop) => {
return ostart + (ostop - ostart) * ((value - istart) / (istop - istart));
};
@quidmonkey
quidmonkey / async-loops.js
Created January 10, 2019 17:00
Async Loop Example
const sleep = async ms => new Promise(
resolve => setTimeout(() => {
console.log('~~~ Slept for', ms, 'ms')
resolve()
}, ms)
)
const of = async range => {
for (const ms of range) {
await sleep(ms)
@quidmonkey
quidmonkey / reduce.js
Last active March 16, 2018 00:43
Various JavaScript Implementations of Reduce
// utils
// unit test - assert 2 values are equal
const assert = (assertion, actual, expected) => {
console.log('~~~', assertion, ':', actual === expected);
};
// clone a value
// objects are only shallow cloned
const clone = (val) => {
@quidmonkey
quidmonkey / watch.sh
Created June 23, 2017 20:02
Sample NPM Run Script File for Watching
#!/bin/bash
function ctrl_c() {
for process in "${PROCESSES[@]}"; do
local pid=$(get_pid $process)
if [ ! -z $pid ]; then
kill $pid
fi
done
@quidmonkey
quidmonkey / fsm.js
Last active June 5, 2017 17:30
Simple FSM Based on Redux.js Style of State Management - Features Timewarping
import { merge, mergeWith } from 'lodash-es';
const history = []; // history of all states
let timePeriod = 0; // index for history, used to timewarp throughout the history
let state = Object.freeze({}); // current state
/**
* Recursively merges all objects, and overwrites
* all other values.
* @param {*} destObj Current state