Skip to content

Instantly share code, notes, and snippets.

@skeeto
skeeto / aoc2509.c
Last active January 22, 2026 00:28
// Advent of Code 2025 Day 9
// $ cc -o aoc2509 aoc2509.c
// $ ./aoc2509 <input.txt
#include <stddef.h>
#include <stdint.h>
#define S(s) (Str){s, sizeof(s)-1}
#define affirm(c) while (!(c)) unreachable()
#define new(a, n, t) (t *)alloc(a, n, sizeof(t), _Alignof(t))
@skeeto
skeeto / list.c
Last active January 2, 2026 17:31
Linked list tricks
// This is free and unencumbered software released into the public domain.
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#define lenof(a) (ptrdiff_t)(sizeof(a) / sizeof(*(a)))
#define S(s) (Str){s, lenof(s)-1}
#define new(a, n, t) (t *)alloc(a, n, sizeof(t), _Alignof(t))
@skeeto
skeeto / parser.c
Last active December 31, 2025 21:42
JSON example parser
// $ cc -o parser parser.c
// $ ./parser <schema.json
// Ref: https://old.reddit.com/r/C_Programming/comments/1q0c2j7
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#define lenof(a) (ptrdiff_t)(sizeof(a) / sizeof(*(a)))
@skeeto
skeeto / template.c
Created December 29, 2025 19:56
Basic template engine
// Basic template engine
// $ cc -o template template.c
// $ printf '<title>{{title}}</title>\nHello, <b>{{name}}</b>!\n' >index.html
// $ ./template <index.html title='Example Page' name=skeeto
// Ref: https://old.reddit.com/r/C_Programming/comments/1pypl5t
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv)
{
// Ref: https://old.reddit.com/r/C_Programming/comments/1pxat1v
#include <assert.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#define new(a, n, t) (t *)alloc(a, n, sizeof(t), _Alignof(t))
typedef struct Dtor Dtor;
@skeeto
skeeto / demo.c
Last active December 21, 2025 17:29
Physics demo
// $ eval cc -g3 -o demo demo.c $(pkg-config --cflags --libs sdl2)
// Ref: https://old.reddit.com/r/C_Programming/comments/1prwizy
// Ref: https://github.com/Avery-Personal/Jubi
#define JUBI_IMPLEMENTATION
#include "Jubi.h"
#include "SDL.h"
static Sint32 randn(Uint64 *s, Sint32 lo, Sint32 hi)
{
*s = *s*0x3243f6a8885a308d + 1;
@skeeto
skeeto / baseline.c
Last active December 20, 2025 17:42
Baseline for a benchmark
// https://old.reddit.com/r/C_Programming/comments/1pr881z/
// $ cc -std=gnu23 -O -o baseline baseline.c
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@skeeto
skeeto / example.c
Last active December 17, 2025 16:32
// https://old.reddit.com/r/C_Programming/comments/1pnh9fq
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define S(s) (Str){s, sizeof(s)-1}
#define new(a, n, t) (t *)alloc(a, n, sizeof(t), _Alignof(t))
@skeeto
skeeto / exebuf.s
Created December 12, 2025 19:43
WNDPROC trampolines
.section .exebuf,"bwx"
.globl exebuf
exebuf: .space 1<<21
@skeeto
skeeto / exebuf.s
Last active December 12, 2025 01:34
.section .exebuf,"bwx"
.globl exebuf
exebuf: .space 1<<12