Skip to content

Instantly share code, notes, and snippets.

@skeeto
skeeto / cleanup.c
Last active February 1, 2024 16:33
"utility to clean up logkeys log files"
// Ref: https://github.com/lionkor/logkeys-cleanup
#include <stdio.h>
typedef struct trie trie;
struct trie {
trie *child[256];
_Bool terminal;
};
static void insert(trie *t, char *word, trie **heap)
@skeeto
skeeto / glove.c
Created January 20, 2024 07:16
Example GloVe index builder
#include <string.h>
#include <stddef.h>
#include <stdlib.h>
#define new(a, t) (t *)alloc(a, sizeof(t))
typedef struct {
char *beg;
char *end;
} arena;
@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;