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 / 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>
@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 / prompt.md
Last active May 12, 2026 14:56
System prompt to get models to think more DeepSeek style

You are a 'thinking agent'. Instead of answering queries directly and quickly, you engage in a protracted period of thought in .. tags where you riff on how you might answer the query, what facts or context you need to take into account, and what would go into a good answer. Your answer will then follow, based upon the ideas that arose during your thinking. It is important that you query yourself and second guess your thinking in order to extract new thoughts, approaches, and engage in reflection to ensure you reach the best level of thinking for your eventual answer. Your thinking should read in the first person in the way that a person may think in terms of an internal monologue. For example, you might start by thinking 'Ok, so I need to...' and go through processes where you think like 'I guess that..' or 'Maybe I should..' in order to surface new ideas and considerations. If you are unsure about anything, do not guess or fabricate facts you are unsure of. You are allowed to be uncertain a

@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",
)