Skip to content

Instantly share code, notes, and snippets.

View peterc's full-sized avatar
🏠
Working from home

Peter Cooper peterc

🏠
Working from home
View GitHub Profile
@peterc
peterc / fetch-mail.sh
Created May 10, 2026 19:01
Process inbound mail on exe.dev VMs into an SQLite database
#!/bin/bash
# Ingest new Maildir messages into ~/mail.db, then delete the files.
#
# schedule in cron with something like:
# * * * * * /home/exedev/bin/fetch-mail.sh >> /home/exedev/.fetch-mail.log 2>&1
set -euo pipefail
DB="$HOME/mail.db"
NEW="$HOME/Maildir/new"
LOCK="$HOME/.fetch-mail.lock"
@peterc
peterc / mpd218.py
Created May 10, 2026 14:19
Control the pad LEDs for the Akai MPD218 over USB MIDI
"""Reusable LED control for the Akai MPD218 over USB MIDI.
from mpd218 import pad_on, pad_off, all_on, all_off
pad_on(13) # light pad 13
pad_off(13)
all_on(); all_off()
Pad indices are 1..16 (bottom-left = 1, top-right = 16, matching the device's default
note mapping of pads 1..16 -> MIDI notes 36..51 on channel 10).
"""
@peterc
peterc / NES-ON-MACOS-DEV-PROMPT.md
Last active May 6, 2026 16:09
Set up basic NES dev environment for AI agent

Prompt: bootstrap an NES dev environment with an agent-controlled emulator

You are a coding agent on macOS. Your job is to set up an environment where you can build NES (Nintendo Entertainment System) ROMs in C, run them in an emulator, and drive that emulator from the command line so you can iterate without a human pressing buttons. Aim for the state described below; report back at each milestone with what you did and what is verified.

Target environment

By the end you should have:

  1. An emulator running. FCEUX 2.6+ installed and able to load .nes ROMs. It exposes a Lua scripting API; that API is how you will control it programmatically.
  2. A C toolchain for the 6502. cc65 (which provides cc65, ca65, ld65, cl65) and a copy of Shiru/clbr's NESLib, a small C-callable helper library that wraps the bits of the NES hardware most games need (palettes, sprites, controllers, PPU, frame waits, optional famitone2 audio).
@peterc
peterc / embedding.rb
Created April 18, 2026 12:52
Create an embedding from Ruby using a good small model, quickly on CPU only.
require "informers"
MODEL = "Snowflake/snowflake-arctic-embed-s"
embedder = Informers.pipeline(
"embedding",
MODEL,
dtype: "int8",
device: "cpu",
)
@peterc
peterc / a.mjs
Created April 9, 2026 12:01
Text-to-speech with tiny-tts (Node.js ESM example)
import TinyTTS from 'tiny-tts';
const tts = new TinyTTS();
await tts.speak('Hello, welcome to Node Weekly.', {
output: 'output.wav',
});
await tts.dispose();
@peterc
peterc / bookmarks.rb
Last active February 8, 2026 23:43
How to fetch a user's bookmarks with the X API as of February 2026
# Fetch X bookmarks and output them as CSV.
#
# On first run, opens a browser for OAuth 2.0 authorization and stores
# tokens in tokens-USERNAME.json. Subsequent runs reuse (and auto-refresh)
# those tokens, so no further login is needed. Multiple users are supported
# via separate token files.
#
# Usage:
# ruby bookmarks.rb [--username USER] [--limit N] [--per-call N]
#
@peterc
peterc / mp3-to-text
Created February 7, 2026 01:19
Transcribe MP3 files using Mistral's Voxtral API with speaker diarization
#!/usr/bin/env python3
import json
import os
import sys
from mistralai import Mistral
def format_time(seconds):
minutes = int(seconds) // 60
@peterc
peterc / transcribe
Created February 6, 2026 12:48
Transcribe audio files to plain text using OpenAI Whisper API. Compresses via ffmpeg (mono, 22kHz, 64kbps) and trims if over 25MB.
#!/usr/bin/env bash
set -euo pipefail
if [ -z "${OPENAI_API_KEY:-}" ]; then
echo "Error: OPENAI_API_KEY is not set" >&2
exit 1
fi
if [ $# -ne 1 ] || [ ! -f "$1" ]; then
echo "Usage: transcribe <audio-file>" >&2
@peterc
peterc / macos_app.rb
Created February 4, 2026 20:34
A native macOS app written in Ruby using FFI to call libobjc, etc.
#!/usr/bin/env ruby
# A macOS GUI app written in Ruby, calling libobjc directly via Fiddle.
# No gems. No Objective-C. Just Ruby and the runtime.
require "fiddle"
OBJC = Fiddle.dlopen("/usr/lib/libobjc.A.dylib")
APPKIT = Fiddle.dlopen("/System/Library/Frameworks/AppKit.framework/AppKit")
# Core runtime functions
@peterc
peterc / helloworld.c
Created February 4, 2026 20:26
A macOS app entirely in plain C
// A macOS GUI app written in pure C, using the Objective-C runtime directly.
// No Objective-C syntax anywhere. Just raw objc_msgSend and runtime calls.
// This is cursed. Enjoy.
// Compile with clang -Wall -Wextra -o hello_runtime hello_runtime.c \
// -framework Cocoa -lobjc
#include <objc/objc.h>
#include <objc/message.h>
#include <objc/runtime.h>