Skip to content

Instantly share code, notes, and snippets.

View creationix's full-sized avatar
💚
<3

Tim Caswell creationix

💚
<3
View GitHub Profile
w = 3;
h = 4;
thick=19/32; // Thickness of plywood.
lift = 4+1/32;
//lift = height-(h+1)*thick-h*vspace;
width = 12*w; // outer width of shelves
hspace = (width-(thick*(w+1)))/w;
vspace = 12;
height = lift + thick*(h+1)+vspace*h; // outer height of shelves.
deep = 19.5; // depth of shelves
const locks = {};
async function protect(fn, name, ...args) {
while (locks[name]) await locks[name]
return (locks[name] = new Promise(async (resolve) => {
const ret = await fn(name, ...args);
delete locks[name];
resolve(ret);
}));
}
const locks = {};
/**
* @param {string} name the thing we want to have access to
*/
async function getLock(name) {
while (locks[name]) await locks[name]
let release;
locks[name] = new Promise(resolve => {
release = () => {
// For golden ratio rectangles
phi = (1 + sqrt(5)) / 2;
echo("phi",phi);
// dihedral angle of icosahedron
dih = acos(sqrt(5) / -3);
echo("dih",dih);
model="low_poly_person_by_Rochus.stl";
modelHeight=14.274;
import 'magic-script-polyfills';
import lumin from 'lumin';
import uv from 'uv';
import ssl from 'ssl';
import egl from 'egl';
import gl from 'gl';
import png from 'png';
import jpeg from 'jpeg';
a = cos(60);
b = sin(60);
z = 0.25; // inset to connections, larger is looser. 0.2
w = 7;
hex_tile = [
[(-1+z)*a,(2*w-1-z)*b],
[w+(-1-z)*a,(2*w-1-z)*b],
[w+(-2)*a,(2*w-2)*b],
[w-z-1+(-2)*a,(2*w-2)*b],
[w-1+(w-2-z)*a,(w-2-z)*b],
@creationix
creationix / block-profile.svg
Last active March 24, 2020 15:06
Block Raised Garden
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@creationix
creationix / gamepad.txt
Created January 24, 2020 15:32
Gamepad Areas
____________________________ __
/ [__ZL__] [__ZR__] \ |
/ [__ TL __] [__ TR __] \ | Front Triggers
__/________________________________\__ __|
/ _ \ |
/ /\ __ (N) \ |
/ || __ |MO| __ _ _ \ | Main Pad
| <===DP===> |SE| |ST| (W) -|- (E) | |
\ || ___ ___ _ / |
/\ \/ / \ / \ (S) /\ __|
@creationix
creationix / add.wat
Created January 15, 2020 05:54
Zig to wasm supports tiny modules.
(module
(type (;0;) (func (param i32 i32) (result i32)))
(func $add (type 0) (param i32 i32) (result i32)
local.get 1
local.get 0
i32.add)
(table (;0;) 1 1 funcref)
(memory (;0;) 2)
(global (;0;) (mut i32) (i32.const 66560))
(export "memory" (memory 0))
@creationix
creationix / asusevent.zig
Last active January 13, 2020 17:03
Reading Asus bluetooth gamepad events in zig.
const std = @import("std");
const File = std.fs.File;
const InputEvent = packed struct {
sec: u64,
usec: u64,
type: u16,
code: u16,
value: i32,
};