Skip to content

Instantly share code, notes, and snippets.

View samwho's full-sized avatar
🌴
On vacation

Sam Rose samwho

🌴
On vacation
View GitHub Profile
#!/usr/bin/env uv run --script
# /// script
# requires-python = ">=3.9"
# dependencies = [
# "requests",
# "watchdog",
# ]
# ///
import argparse
#!/bin/bash
# Configuration
WATCH_DIR="$HOME/Library/Group Containers/group.com.apple.VoiceMemos.shared/Recordings"
ENDPOINT="http://127.0.0.1:8080" # Replace with your actual endpoint
API_KEY="your-api-key" # Optional: Add if your endpoint requires authentication
# State file to track processed files
STATE_FILE="$HOME/.voice_memos_processed"
touch "$STATE_FILE"
@samwho
samwho / peek.ts
Created August 5, 2025 15:16
Peek a stream in TypeScript
/**
* Peek at the next chunk of data in the stream without consuming it.
* @param input The input stream to read from.
* @param length The number of bytes to peek.
* @returns A promise that resolves to the peeked data.
*/
async function peek(input: Readable, length: number): Promise<Buffer> {
// Try synchronous read first
const immediateBuffer = input.read(length)
if (immediateBuffer) {
@samwho
samwho / DOM.ts
Created May 19, 2025 16:38
DOM.ts
interface ExtraOpts {
class?: string | string[];
data?: Record<string, string>;
}
type TagName = keyof HTMLElementTagNameMap;
type Tag = HTMLElementTagNameMap;
type Opts<K extends TagName> = Partial<Tag[K]> & ExtraOpts;
type Child = Node | string;
import GUI from "lil-gui";
import { div } from "./DOM";
let id = 0;
function getUniqueID(): string {
return `element-${id++}`;
}
export class BaseElement extends HTMLElement {
gui?: GUI;
@samwho
samwho / bench.py
Created August 30, 2024 16:36
int vs string index benchmark
import random
import string
import time
from typing import Tuple
import psycopg2
from psycopg2.extensions import cursor
from rich.console import Console
from rich.table import Table
import io
import logging
import os
import time
from datetime import datetime, timedelta
import gtts
import irc.bot
import sounddevice as sd
import soundfile as sf
import itertools
from sys import stdout
from typing import Self
def emoji_bool(b: bool):
return b and "✅" or "❌"
class Node:
@samwho
samwho / aoc2023-1.py
Last active December 1, 2023 22:27
aoc2023-1.py
import re
word_numbers = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
real_numbers = [str(i) for i in range(1, 10)]
numbers_re = "|".join(real_numbers + word_numbers)
first_re = rf"^.*?({numbers_re}).*$"
last_re = rf"^.*({numbers_re}).*?$"
@samwho
samwho / git_repo_size.py
Created November 25, 2023 17:35
git_repo_size.py
import re
import subprocess
DIVIDER_RE = r"^.+\s+[0-9a-f]+$"
ITEM_RE = r"^.+\s+.+\s+.*$"
def get_line_changes_over_time():
process = subprocess.Popen(
[