Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@skeeto
skeeto / meminfo.c
Created January 10, 2024 02:02
/proc/meminfo parser
// Parse /proc/meminfo into a hash map
// This is free and unencumbered software released into the public domain.
#include <fcntl.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@skeeto
skeeto / aoc2023d15.c
Last active January 4, 2024 17:31
Advent of Code 2023 Day 15
// Advent of Code 2023 Day 15
// https://adventofcode.com/2023/day/15
// https://nrk.neocities.org/articles/aoc23
// This is free and unencumbered software released into the public domain.
#include <stddef.h>
#include <string.h>
#define assert(c) while (!(c)) *(volatile int *)0 = 0
#define new(a, t, n) (t *)alloc(a, sizeof(t)*n)
// Gradual-commit arena demonstration
// This is free and unencumbered software released into the public domain.
#include <stddef.h>
#include <string.h>
static void *os_reserve(ptrdiff_t);
static _Bool os_commit(void *, ptrdiff_t);
#define ARENA_PAGESIZE ((ptrdiff_t)1<<26)
// $ cc -mwindows stretchdibits.c
#include <windows.h>
enum {
WIDTH = 1280,
HEIGHT = 720,
};
static unsigned char *pixels;
@skeeto
skeeto / moveset.c
Last active December 15, 2023 03:21
Moveset resolver
#include <stddef.h>
#include <stdint.h>
#define assert(c) while (!(c)) *(volatile int *)0 = 0
#define countof(a) (size)(sizeof(a) / sizeof(*(a)))
#define new(a, t, n) (t *)alloc(a, sizeof(t), _Alignof(t), n)
typedef int32_t b32;
typedef uint32_t u32;
typedef uint64_t u64;
@skeeto
skeeto / ascreenshot.png
Last active December 10, 2023 00:42
Example SDL2 "roguelike"
ascreenshot.png
#define _GNU_SOURCE
#include <assert.h>
#include <fcntl.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <unistd.h>
@skeeto
skeeto / jit.c
Last active November 15, 2023 13:20
Partial application JIT demo, with arena
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <windows.h>
#define new(a, t, n) (t *)alloc(a, sizeof(t)*n)
typedef struct {
char *beg, *end;
} arena;
@skeeto
skeeto / 2pow.c
Last active October 29, 2023 15:45
2^1000000
enum {
BASE = 1000000000, // nine decimals per limb
NUMCAP = 1<<16, // capacity just over a half million decimals
};
typedef struct {
int *digits;
int len;
} num;
@skeeto
skeeto / intset.c
Last active October 26, 2023 14:13
Hash trie iterator example (integer set)
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#define assert(c) while (!(c)) *(volatile int *)0 = 0
#define new(a, t) (t *)alloc(a, sizeof(t))
typedef struct {
char *beg, *end;