Skip to content

Instantly share code, notes, and snippets.

View creationix's full-sized avatar
💚
<3

Tim Caswell creationix

💚
<3
View GitHub Profile
// ESC := "^"
ESC := "\x1b"
WIDTH := 33
HEIGHT := 32
FPS := 120
SIZE := WIDTH * HEIGHT
pixels := ByteArray(SIZE)
dirty_x1 := 0
dirty_y1 := 0
var Neopixel = require('neopixel');
var data = new Uint8Array(4*12);
function hue(p, h, l) {
h = h % 0x600;
var r, g, b;
if (h < 0x100) { r = 0xff; g = h; b = 0; }
else if (h < 0x200) { r = 0x1ff - h; g = 0xff; b = 0; }
/* types
Button - represents a GPIO pin hooked to a button
Neopixel - represents a GPIO pin hooked to neopixels
Strip - represents a memory buffer for 1d array of colors
Grid - represents a memory buffer for a 2d array of colors
Position1d - represents a bounded 2D coordinate
Position2d - represents a bounded 2D coordinate
Interval - represents a clock 33345rtfv ith a given frequency
Schedule - represents a schedule to alarm at given times
Color - represents a 24 bit RGB color
var WIDTH = 10
var HEIGHT = 10
// 0 is null, pointers start at 1
const SIZE = WIDTH * HEIGHT
var set = new Uint16Array(SIZE)
// return end of chain
function walk(a) {
while (set[a - 1]) {
a = set[a - 1]
const std = @import("std");
fn AutoMap(comptime BLOCK_POWER: comptime_int) type {
return struct {
const BLOCK_SIZE = 2 << (BLOCK_POWER - 1);
const HASH_SIZE = 2 << (HASH_POWER - 1);
const BRANCH_POWER = std.math.log2(@sizeOf(Leaf) / @sizeOf(*Node));
const BRANCH_FACTOR = 2 << (BRANCH_POWER - 1);
const Hash = u256;
const Block = [BLOCK_SIZE]u8;
extern fn slowAddJS(a: u32, b: u32, frame: *@Frame(slowAdd)) void;
var addResult: u32 = 0;
export fn onSlowAdd(frame: *@Frame(slowAdd), result: u32) void {
addResult = result;
resume frame;
}
#include <stdint.h>
#include <unistd.h>
typedef struct {
uint8_t* ptr;
size_t len;
} slice_t;
typedef struct {
slice_t* ptr;
extern fn wsSendText(client: *Client, message: CSlice(u8)) void;
extern fn wsSendBInary(client: *Client, message: CSlice(u8)) void;
extern fn wsClose(client: *Client) void;
fn CSlice(comptime T: type) type {
return extern struct {
ptr: [*]const T,
len: usize,
pub fn fromSlice(slice: []const T) CSlice(T) {
// 84 x 44
// 26.5 - 31 height
// https://www.ana-white.com/woodworking-projects/modern-farm-table
// 2x6 legs
// 2x2 supports
// 2x4 side aprons
color("#aaaaaa") {
// Fridge
translate([0,-1.5,0]) cube([32,36,70]);
// Dishwasher
translate([0,36,0]) cube([24,24,34.5]);
// Sink
translate([27+1.5,36+21+25.9,36.05-10]) cube([33,16,10]);
// Stove
translate([24+3+36+24,36+21+24+3-1,0]) union() {
cube([30,25,36]);