Skip to content

Instantly share code, notes, and snippets.

View bvisness's full-sized avatar

Ben Visness bvisness

View GitHub Profile
@bvisness
bvisness / esbuild-wasi.mjs
Created September 11, 2025 16:16
An esbuild plugin to get WASI 0.1 modules running in the browser.
import { createWriteStream } from "node:fs";
import { access, readFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { isAbsolute, join, relative } from "node:path";
import { pipeline } from "node:stream/promises";
import * as esbuild from "esbuild";
import { componentNew, transpile } from "@bytecodealliance/jco";
const WASI_ADAPTER_URL = "https://github.com/bytecodealliance/wasmtime/releases/download/v36.0.2/wasi_snapshot_preview1.command.wasm";
@bvisness
bvisness / fuss.ts
Created August 29, 2025 22:05
A simple black-box fuzzer.
import { assert } from "./utils.js";
type Awaitable = unknown;
export class Fusser {
buffer: Uint32Array;
init: () => Awaitable;
action: (v: number) => Awaitable;
private canceled: boolean;
@bvisness
bvisness / deltaforever
Last active May 29, 2025 14:58
A script to repeatedly run the `delta` test case reducer since it gets stuck.
#!/usr/bin/env python3
import argparse
import re
import subprocess
import sys
import time
from pathlib import Path
TEMPLATE_CONTENT = """#!/bin/bash
@bvisness
bvisness / convert.js
Created September 13, 2024 20:33
React "detranspiler"
#!/usr/bin/env node
// This script takes a script called `s01.js` and tries to de-transpile it somewhat,
// converting calls to `jsx` and `jsxs` into JSX syntax.
const acorn = require("acorn");
const walk = require("acorn-walk");
const { readFileSync, writeFileSync } = require("fs");
const prettier = require("prettier");
@bvisness
bvisness / growtable-nogc.js
Last active June 28, 2024 21:59
DefaultValue(externref) absurdity
function test(msg, f) {
try {
f();
console.log(`${msg}: ok`);
} catch (e) {
console.log(`${msg}: fail (${e})`);
}
}
function printTable(t) {
@bvisness
bvisness / wasm_in_ci.md
Last active December 21, 2024 19:33
A quick guide to running wasm files outside the browser

General info

The following code should work to test WebAssembly in various JS runtimes with minor modifications:

const bytes = /* read a .wasm file somehow */;
const mod = new WebAssembly.Module(bytes);
const instance = new WebAssembly.Instance(mod, { /* imports */ });

const { foo, bar } = instance.exports;
@bvisness
bvisness / pageroni_linux.c
Last active August 4, 2023 02:08
memory.discard test programs
// Run like so:
// gcc -opageroni pageroni_linux.c && pageroni
#include <stddef.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/types.h>
@bvisness
bvisness / ship.c
Created June 15, 2019 04:11
Quick matrix transformation demo
Mat4 RotationMatrix(float radians)
{
Mat4 result;
// assuming column-major order (first index is column, second is row)
result[0][0] = Math.Cos(radians);
result[0][1] = -Math.Sin(radians);
result[1][0] = Math.Sin(radians);
result[1][1] = Math.Cos(radians);
@bvisness
bvisness / PathBot.java
Last active October 27, 2018 16:51
Example implementation of pure-pursuit path following for NXT robots
import lejos.nxt.Button;
import lejos.nxt.addon.GyroSensor;
import lejos.nxt.SensorPort;
import lejos.nxt.NXTMotor;
import lejos.nxt.MotorPort;
import javax.microedition.lcdui.Graphics;
/**
* This program makes an NXT robot drive a predetermined path. It uses the wheel tachometers (encoders) and
* a gyro sensor to keep track of the robot's position and heading, then uses a basic "pure pursuit" algorithm
@bvisness
bvisness / frequency.py
Created April 7, 2017 03:04
Music note to its frequency
import re
def frequency(note):
aFreqs = {
-1: 13.75,
0: 27.5,
1: 55.0,
2: 110.0,
3: 220.0,
4: 440.0,