Skip to content

Instantly share code, notes, and snippets.

@rrampage
rrampage / sh.c
Last active June 14, 2025 13:32
Minimal Linux shell (C, Zig and ASM)
/*
Compile with one of the following:
zig cc -v -s -Os -target aarch64-linux-musl -nostdlib -flto -static shell.c -o csh
zig cc -v -s -Os -target aarch64-linux-gnu -nostdlib -flto -static shell.c -o csh
CLANG:
clang -v -s -Oz -ffreestanding -nostdlib -fno-stack-protector -Wl,--entry=_start -Wl,--gc-sections -Wl,-z,now -flto -static -o csh shell.c
musl-clang -v -s -Os -nostdlib -nostartfiles -fno-stack-protector -Wl,--entry=_start -Wl,--gc-sections -Wl,-z,now -flto -nostdinc -static -o csh shell.c
GCC (some things DO NOT WORK like `pwd`):
@hirrolot
hirrolot / CoC-60.ml
Created April 13, 2025 13:40
Calculus of Constructions in 60 lines of OCaml
let discard _a b = b
let rec pp lvl = function
| `Lam f -> "(λ" ^ pp (lvl + 1) (f (`Go lvl)) ^ ")"
| `Pi (a, f) -> "(Π" ^ pp lvl a ^ "." ^ pp (lvl + 1) (f (`Go lvl)) ^ ")"
| `Appl (m, n) -> "(" ^ pp lvl m ^ " " ^ pp lvl n ^ ")"
| `Ann (m, a) -> "(" ^ pp lvl m ^ " : " ^ pp lvl a ^ ")"
| `Go x -> string_of_int x
| `Star -> "*"
| `Box -> "☐"
@neel-krishnaswami
neel-krishnaswami / pcomb.ml
Last active September 6, 2023 13:43
A linear-time parser combinator library in Ocaml
module C : sig
type t
val empty : t
val one : char -> t
val union : t -> t -> t
val inter : t -> t -> t
val top : t
val mem : char -> t -> bool
val make : (char -> bool) -> t
val equal : t -> t -> bool
@hirrolot
hirrolot / CoC.ml
Last active June 18, 2025 23:16
How to implement dependent types in 80 lines of code
type term =
| Lam of (term -> term)
| Pi of term * (term -> term)
| Appl of term * term
| Ann of term * term
| FreeVar of int
| Star
| Box
let unfurl lvl f = f (FreeVar lvl)
@pdarragh
pdarragh / papers.md
Last active February 23, 2025 02:04
Approachable PL Papers for Undergrads

Approachable PL Papers for Undergrads

On September 28, 2021, I asked on Twitter:

PL Twitter:

you get to recommend one published PL paper for an undergrad to read with oversight by someone experienced. the paper should be interesting, approachable, and (mostly) self-contained.

what paper do you recommend?

@p4bl0-
p4bl0- / 00_readme.md
Last active January 2, 2025 09:03
A complete compiler for a simple language (in less than 150 LoC)

This project is a tiny compiler for a very simple language consisting of boolean expression.

The language has two constants: 1 for true and 0 for false, and 4 logic gates: ! (not), & (and), | (or), and ^ (xor).

It can also use parentheses to manage priorities.

Here is its grammar in BNF format:

expr ::= "0" | "1"

@snej
snej / tails.cc
Last active May 8, 2021 18:27
Tails! A tiny Forth core written as a hack for May Forth 2021, using some of Wasm3's secret optimization sauce.
// Tails has grown a bit and moved out into its own repository: https://github.com/snej/tails/
// Please visit it there!
//
// If you want to see the tiny original version from May Forth 2021, it's still here;
// click the "Revisions" button above, or go to:
// https://gist.github.com/snej/9ba59d90689843b22dc5be2730ef0d49/2d55f844b7622aa117b9275bbc9d189613f7ff7f
@MattPD
MattPD / analysis.draft.md
Last active June 21, 2025 13:34
Program Analysis Resources (WIP draft)

This document has moved!

It's now here, in The Programmer's Compendium. The content is the same as before, but being part of the compendium means that it's actively maintained.

@aprell
aprell / newproject.sh
Created October 12, 2012 09:57
Project templates
#!/bin/bash
usage="Usage: $(basename "$0") <name>"
if [ $# -ne 1 ]; then
echo $usage
exit 0
fi
proj=$1