Skip to content

Instantly share code, notes, and snippets.

View lifthrasiir's full-sized avatar

Kang Seonghoon lifthrasiir

View GitHub Profile
/* The world's smallest Brainfuck interpreter in C, by Kang Seonghoon
* http://j.mearie.org/post/1181041789/brainfuck-interpreter-in-2-lines-of-c */
s[99],*r=s,*d,c;main(a,b){char*v=1[d=b];for(;c=*v++%93;)for(b=c&2,b=c%7?a&&(c&17
?c&1?(*r+=b-1):(r+=b-1):syscall(4-!b,b,r,1),0):v;b&&c|a**r;v=d)main(!c,&a);d=v;}
@lifthrasiir
lifthrasiir / .gitignore
Last active September 26, 2025 06:42
WebAssembly interpreter in a Header (WAH) -- See https://github.com/lifthrasiir/wah/ for the recent version.
*.exe
wah_test_basic
wah_test_control_flow
wah_test_determinism
wah_test_export
wah_test_functions
wah_test_globals
wah_test_memory
wah_test_ops
wah_test_overflow
@lifthrasiir
lifthrasiir / disfilter.rs
Last active September 16, 2025 11:42
Disfilter: Fabian Giesen's x86-32 transformer, reworked for x86-64 in Rust (WIP)
#![cfg_attr(
not(all(feature = "encode", feature = "decode")),
allow(dead_code, unused_imports)
)]
// TODO:
// - Better error checking
// - Better code structure
// - Detect function boundary (skip CC or multi-byte nops)
@lifthrasiir
lifthrasiir / main.go
Created July 8, 2025 12:10
Linewise MCP (vibe-coded with Gemini)
package main
import (
"bufio"
"bytes"
"context"
"fmt"
"io/ioutil"
"log"
"os"
@lifthrasiir
lifthrasiir / brotli-bootstrap.mjs
Last active June 23, 2025 10:22
Brotli bootstrapping based on WOFF2 font
// Brotli bootstrapping based on WOFF2 font
// Kang Seonghoon, 2024-03-01, public domain
// Based on my earlier work for JS1024: https://js1024.fun/demos/2022/18
// Only vaguely tested, YMMV
import { argv, stderr } from 'node:process';
import fs from 'node:fs';
import zlib from 'node:zlib';
const generateBrotliParams = function* () {
@lifthrasiir
lifthrasiir / formats.md
Last active April 4, 2025 23:53
Comparison of schemaless byte-oriented binary serialization format

What the heck?

  • Schemaless: The format does not have a knowledge about the underlying data at all.
  • Byte-oriented: The format is built upon a byte stream, probably for the ease of implementation and performance.
  • Binary: The format is not targeted for human consumption and specified in terms of "bytes" (which is 8 bits long for our purpose).
  • Serialization: The format is primarily to be used for storage and transmission, not for the in-memory representation.

Contenders

  • S-Expressions (1997), a "canonical" encoding (which is also used for transport)
@lifthrasiir
lifthrasiir / hid-commands.txt
Created March 17, 2025 06:50
Archon M1 PRO MAX WebHID command listing (preliminary)
?? = not yet known, set to zero?; nnnn = u16be; nnnn^ = u16le; ...
XXXX (uppercased) = output locations, otherwise input locations or literal bytes
cmd# buffer configuration function signature
0x01 ?? VVVV getProtocolVersion() -> v
0x02 tt aa... VV... getKeyboardValue(t, a, n) -> v...
0x03 tt aa... setKeyboardValue(t, a...)
0x04 tt aa nn KKKK getKey(t, a, n) -> k
0x05 tt aa nn ssss/KKKK setKey(t, a, n, s) -> k
@lifthrasiir
lifthrasiir / numeric-tzid.md
Last active February 3, 2025 01:32
Proposal for stable short identifier (or two) of time zones

This proposal was originally written in 2018 as a concrete proposal for numeric time zone identifiers. I'm still not sure if this has a merit or not, but for the historical perspective, I reproduce the (incomplete) proposal in verbatim here. --Kang Seonghoon


[...]

The needs for the short and stable identifier are most importantly observed by the case of the Unicode CLDR project. CLDR required a stable identifier for the locales, which requires a stable identifier for the time zones. [...]

Short Identifiers

@lifthrasiir
lifthrasiir / nothing.html
Created September 16, 2024 07:30
Use nothing but a vanilla HTML/CSS/JS to rewrite https://usenothing.com/ in a single file (including the webfont)
<base target=_blank><style>*{box-sizing:border-box;padding:0;margin:0}:root{color:#a1a1aa;background:#09090b;font:1.2rem Crimson Text,serif}::selection{color:#fafafa;background:#3f3f46}strong,output{font-weight:normal;color:#fafafa}output{font-family:Courier New,monospace}body{width:90%;max-width:550px;margin:120px auto}p,svg{margin-bottom:12px}p:has(~hr){font-size:1.2rem}hr{width:50px;height:1px;background:#27272a;border:0;margin:50px 0}hr~*{line-height:1.7}hr~p{text-indent:24px;margin-bottom:24px}a{color:#fafafa;text-decoration:underline dotted #71717a}aside{position:fixed;bottom:20px;left:0;width:100%;pointer-events:none}#A{width:-moz-max-content;width:max-content;max-width:90%;padding:12px 16px;margin:0 auto;font:0.74rem Inter,Arial,sans-serif;line-height:1.6;color:#a1a1aa;background-color:#18181b;border:1px solid #27272a;opacity:var(--o,0);transform:translateY(calc(20px*(1 - var(--o))))}/* fonttools subset CrimsonText-Regular.ttf --unicodes="U+0020,U+0027,U+002C-002E,U+0030-0039,U+0041-005A,U+0061-007A,U
@lifthrasiir
lifthrasiir / alphabet.md
Last active February 16, 2024 19:03
The "Options" Alphabet