Skip to content

Instantly share code, notes, and snippets.

@saolsen
saolsen / bucket_array.c
Last active March 9, 2025 20:37
bucket array
// See bucket_array.h
// Define the same variables, include the .h file and then include this file in one .c file.
#ifndef BA_PREFIX
#error "BA_PREFIX must be defined"
#endif
#ifndef BA_TYPEDEF_NAME
#error "BA_TYPEDEF_NAME must be defined"
#endif
@saolsen
saolsen / dandd.c
Last active January 23, 2025 20:58
dungeons and diagrams
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#define u8 uint8_t
#define i32 int32_t
#define u64 uint64_t
// Solutions are 8x8 matrices in row-major order. If the value is 1, there's a wall, if it's 0
@saolsen
saolsen / steve.h
Last active January 14, 2025 23:27
Single header c library
// Single header file library for C.
// * Provides an arena allocator and some data structures that use it.
//
// * Maintains a (thread local) pool of arenas so they are cheap to acquire and release for temporary allocations.
// Since all allocations are backed by arenas you don't have to free anything individually, just
// use an arena that matches the lifetime of the data.
// * Includes data structures like a dynamic array that work well with the arena.
// * Allows for some optimizations like extending instead of reallocing if the array is on the end of an arena.
// * All lengths are signed.
// * Makes for less casting when comparing lengths and pointers.
@saolsen
saolsen / pgboss_postgres.ts
Last active September 11, 2024 20:53
pgboss with postgres.js
// wow, this is awesome
// you really don't need drizzle, this is much better
// I really kinda hate that copilot isn't working though...
import postgres from "npm:postgres";
import PgBoss from "npm:pg-boss";
interface World {
world: string;
@saolsen
saolsen / Dockerfile
Created April 16, 2024 14:03
Deno On Fly
ARG DENO_VERSION=1.42.2
ARG BIN_IMAGE=denoland/deno:bin-${DENO_VERSION}
FROM ${BIN_IMAGE} AS bin
FROM frolvlad/alpine-glibc:alpine-3.13
RUN apk --no-cache add ca-certificates
RUN addgroup --gid 1000 deno \
&& adduser --uid 1000 --disabled-password deno --ingroup deno \
@saolsen
saolsen / .Rust_Vals.md
Last active December 26, 2023 00:29
Rust Val

Make a Val with rust.

Build a https://www.val.town/ val with rust. This is an example of how to compile a rust file to wasm and use it as a val.

Requires rust, wasm-pack and deno.

Usage

  • Put your code in val.rs.
  • Build it.
@saolsen
saolsen / day13_part1.py
Last active October 25, 2023 17:35
aoc 2022 day13
from itertools import batched
def ordered(a, b) -> bool | None:
match a, b:
case int(i), int(j):
if i == j:
return None
return i < j
case list(i), list(j):
@saolsen
saolsen / copy_tmux_output.md
Created July 13, 2023 18:23
Copy tmux output
@saolsen
saolsen / .gitignore
Last active July 13, 2023 18:00
rust flat directory, whole rust project in a gist
target