Skip to content

Instantly share code, notes, and snippets.

@gordonbrander
gordonbrander / SKILL.md
Created February 9, 2026 09:02
sr-eng-review skill
name description context agent
sr-eng-review
Review git branch using diff against main. Always use this skill after you complete a unit of work, or complete a major step in a plan.
fork
general-purpose

Sr Eng Review

You are a Senior Software Engineer with 15+ years of experience conducting thorough code reviews. You have deep expertise in TypeScript, functional programming paradigms, and modern web development practices. Your reviews are known for being comprehensive yet constructive, catching subtle bugs while also mentoring developers toward better practices.

@gordonbrander
gordonbrander / sqlite-event-queue.ts
Created February 6, 2026 05:51
SQLite event queue
/**
* SQLite-backed event queue for inter-worker communication.
*
* Provides a simple pub/sub mechanism where workers can push events and poll
* for new events using cursor-based pagination. Each worker maintains its own
* cursor position, enabling reliable at-least-once delivery.
*
* @module event-queue
*/
@gordonbrander
gordonbrander / urlpattern-router.ts
Created September 22, 2025 07:24
URLPattern Router
export type RouteHandler = (context: URLPatternResult) => void;
export type Cancel = () => void;
type Matcher = (route: string) => URLPatternResult | undefined;
const matcher = (pathname: string, baseUrl?: string): Matcher => {
const pattern = new URLPattern({ pathname, baseURL: baseUrl });
return (route: string) => pattern.exec(route) ?? undefined;
};
@gordonbrander
gordonbrander / actor.ts
Last active February 25, 2025 13:48
Simple actors with async and TransformStream
import { type Receive, type Send, useMailbox } from "./mailbox.ts";
export type Context<Msg> = {
self: string;
send: (id: string, msg: Msg) => Promise<void>;
receive: Receive<Msg>;
spawn: (id: string, actor: Actor<Msg>) => string;
};
export type Actor<Msg> = (context: Context<Msg>) => Promise<void>;
@gordonbrander
gordonbrander / pipe.rs
Created November 24, 2024 15:42
pipe.rs - rust pipeline macro
#[macro_export]
macro_rules! pipe {
// Base case - single function
($value:expr, $func:expr) => {
$func($value)
};
// Recursive case - multiple functions
($value:expr, $func:expr, $($rest:expr),+) => {
pipe!($func($value), $($rest),+)
@gordonbrander
gordonbrander / middleware.test.ts
Last active November 6, 2024 02:14
middleware.ts - functional-style middleware
import { strict as assert } from "assert";
import { createMiddleware, Msg } from "./middleware.js";
describe("createMiddleware", () => {
it("should create middleware with empty initial state", () => {
const middleware = createMiddleware();
assert.deepEqual(middleware("test"), "test");
});
it("should execute single middleware", () => {
@gordonbrander
gordonbrander / transition.ts
Last active October 2, 2024 14:23
transition.ts - micro JS CSS transitions helper
let slowAnimations = false;
/** Set slow animations for debugging */
export const setSlowAnimations = (isSlow: boolean) => {
slowAnimations = isSlow;
};
/** @returns 10s if slow animations is turned on, otherwise returns `ms` */
export const slowable = (ms: number) => (slowAnimations ? 10000 : ms);
@gordonbrander
gordonbrander / multidispatch.ts
Created August 3, 2024 19:38
multidispatch.ts
export const multidispatch = <T>() => {
const routes = new Map<
(...args: unknown[]) => boolean,
(...args: unknown[]) => T
>();
const call = (...args: unknown[]) => {
for (const [isMatch, handler] of routes.entries()) {
if (isMatch(...args)) {
return handler(...args);
@gordonbrander
gordonbrander / h.js
Last active October 5, 2023 23:04
h.js - hyperscript micro implementation
// Set key on object, but only if value has changed.
// This is useful when setting keys on DOM elements, where setting the same
// value may trigger a style recalc.
//
// Note that the typical layout-triggering DOM properties are read-only,
// so this is safe to use to write to DOM element properties.
// See https://gist.github.com/paulirish/5d52fb081b3570c81e3a.
export const prop = (object, key, value) => {
if (object[key] !== value) {
object[key] = value
@gordonbrander
gordonbrander / prop.js
Created September 28, 2023 02:15
prop.js - make DOM fast with a write-through cache
// Set property of element.
// Uses a write-through cache to only set
// when value actually changes.
export const prop = (el, key, value) => {
let cacheKey = Symbol.from(`prop.${key}`)
if (el[cacheKey] != value) {
el[cacheKey] = value
el[key] = value
}
}