Skip to content

Instantly share code, notes, and snippets.

View bvisness's full-sized avatar

Ben Visness bvisness

View GitHub Profile
@bvisness
bvisness / stopwatch.js
Created January 14, 2026 17:32
A little JS timing utility
class Stopwatch {
constructor(name, silent = false) {
this.silent = silent;
this.samples = [];
this.reset(name);
}
reset(name) {
this.name = name;
this.last = performance.now();
@bvisness
bvisness / dom.ts
Created December 30, 2025 18:55
Simple utilities for creating DOM elements.
/**
* DOM utilities to ease the pain of document.createElement.
*/
type NonNull<T> = T extends null ? never : T;
type CopyNullable<Src, Dst> = Src extends null ? Dst | null : NonNull<Dst>;
type Falsy = null | undefined | false;
/**
* A slightly relaxed Node type for my DOM utilities.
@bvisness
bvisness / ntutil.py
Last active December 8, 2025 00:39
A helpful wrapper for the WPILib NetworkTables API.
from typing import Any, Dict, Generic, List, Type, TypeVar
import ntcore
import wpilib
import wpiutil.log
nt = ntcore.NetworkTableInstance.getDefault()
T = TypeVar("T")
@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>