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 / rubyui_shim.rb
Created June 25, 2026 15:14
RubyUI shim for Sinatra
# Replicates what RubyUI's Rails install generator wires up, but for a plain
# Ruby process: make `RubyUI` a Phlex Kit, then load every component file.
require "date"
require "phlex"
require "tailwind_merge"
module RubyUI
extend Phlex::Kit
end
@peterc
peterc / pelican.MD
Created June 10, 2026 21:37
DiffusionGemma pelican on a bicycle

pelican

@peterc
peterc / CLI-GUIDELINES.md
Created June 6, 2026 16:03
A compact contract for CLIs for agents and development tools to use

CLI-GUIDELINES.md

A compact contract for CLIs that humans can use (good UX) and machines can trust (predictable behavior, stable output).

Use when designing, implementing, or reviewing command-line tools, especially CLIs that need reliable automation behavior, stable machine-readable output, safe mutation semantics, or good terminal UX.

How to Use This Document

When building or reviewing a CLI:

  1. First classify it by capability/risk dimensions:
@peterc
peterc / fakedis_server.cpp
Last active June 6, 2026 13:25
fakedis: A fake vibe-coded slopathon that passes the Redis 2.0 test suite
/*
* fakedis_server.cpp
*
* A vibe-coded (Codex) Redis server implementation in C++.
* Or: A TERRIBLE THING MADE JUST TO SEE HOW LONG IT WOULD TAKE AND HOW BAD
* IT WOULD BE.
*
* This is a vibe-coded C++ Redis lookalike built with one goal: pass
* the Redis 2.0 compatibility test suite. And it does. But it's not a
* Redis replacement (plus 2.0 is ancient anyway - it's up to like 8.2 now).
@peterc
peterc / drop.ts
Last active May 30, 2026 19:07
A temporary file dropping/sharing service
// drop
//
// A dependency-free Bun web app for short-lived file sharing. It serves a
// drag-and-drop page, accepts SVG, PNG, PDF, GIF, WEBP, and JPEG uploads after
// detecting the file type from contents, stores each upload in /tmp/images under
// a random UUID filename, and deletes stored files after 5 minutes. The storage
// directory is capped at 1 GB by deleting the oldest files first, and is kept at
// 0700 so only the app's Unix user can inspect stored files directly.
//
// Run:
@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();