Skip to content

Instantly share code, notes, and snippets.

View bvisness's full-sized avatar

Ben Visness bvisness

View GitHub Profile
@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 May 22, 2024 05:52
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,
@bvisness
bvisness / HandmadeMathInclude.cpp
Last active August 23, 2016 23:28
"Test" for Handmade Math
/*
* This file actually includes the implementations from HandmadeMath.h so the
* main test can link with them.
*/
#define HANDMADE_MATH_NO_INLINE
#define HANDMADE_MATH_IMPLEMENTATION
#define HANDMADE_MATH_CPP_MODE
#include "HandmadeMath.h"
@bvisness
bvisness / verbal-expression-arrays.js
Last active August 18, 2016 04:22
Verbal Expressions made better
//
// Chaining functions is kind of annoying, and seems unnecessary. Let's try
// building verbal expressions using arrays instead.
//
// (Plus let's throw some new features in, because regexes can do a lot!)
//
//
// Simple stuff can be done like this:
//