Skip to content

Instantly share code, notes, and snippets.

@rrampage
rrampage / sh.c
Last active July 3, 2025 15:17
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 14, 2025 09:26
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 August 30, 2025 01:15
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)
@swatson555
swatson555 / heap-lisp.c
Created February 17, 2023 12:42
Heap based scheme machine.
/* Heap based virtual machine described in section 3.4 of Three Implementation Models for Scheme, Dybvig
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <assert.h>
char token[128][32];
@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
@mcarilli
mcarilli / nsight.sh
Last active October 1, 2025 14:07
Favorite nsight systems profiling commands for Pytorch scripts
# This isn't supposed to run as a bash script, i named it with ".sh" for syntax highlighting.
# https://developer.nvidia.com/nsight-systems
# https://docs.nvidia.com/nsight-systems/profiling/index.html
# My preferred nsys (command line executable used to create profiles) commands
#
# In your script, write
# torch.cuda.nvtx.range_push("region name")
# ...
@MattPD
MattPD / analysis.draft.md
Last active October 7, 2025 17:07
Program Analysis Resources (WIP draft)