View secure-redirect.lua
require('weblit-app')
-- Listen on port 80 without encryption
.bind {host = "0.0.0.0", port = 80 }
-- Listen on port 443 with encryption
.bind {host = "0.0.0.0", port = 443, tls = {
cert = module:load("cert.pem"),
key = module:load("key.pem")
View imperial.lua
-- Use Euclids algorithm to find gcd
-- m and n need to be positive integers, m must be larger.
local function gcd(m, n)
while n > 0 do
m, n = n, m % n
end
return m
end
View hexycoop.scad
module timber(l=8*12) {
linear_extrude(l)
polygon([
[.5,0],[3,0],
[3.5,1.75],
[3,3.5],[.5,3.5],
[0,1.75]]);
}
module timberr(x,y,z,r,o) {
View hexycoop.scad
module timber(l=8*12) {
linear_extrude(l)
polygon([
[.5,0],[3,0],
[3.5,1.75],
[3,3.5],[.5,3.5],
[0,1.75]]);
}
module timberr(x,y,z,r,o) {
rotate([0,0,r-90])
View promise-run.js
function run(iterator) {
return new Promise((resolve, reject) => {
var error, value, done;
next();
function next() {
while (!done) {
View storage.md

Level DB Style

This is highly influenced by https://github.com/google/leveldb#features

  • Keys and values are arbitrary byte arrays.
  • Data is stored sorted by key.
  • Callers can provide a custom comparison function to override the sort order.
  • The basic operations are Put(key,value), Get(key), Delete(key).
  • Multiple changes can be made in one atomic batch.
  • Users can create a transient snapshot to get a consistent view of data.
View vm.rust
#[derive(Debug)]
enum Value {
Nil,
Integer(i64),
String(usize),
Pair(usize)
}
#[derive(Debug)]
struct State {
View merger.lua
local concat = table.concat
-- Merger allows for effecient merging of many chunks.
-- The scan function returns truthy when the chunk contains a useful delimeter
-- Or in other words, when there is enough data to flush to the decoder.
local function merger(read, scan)
local parts = {}
-- Return a new read function that combines chunks smartly
return function ()
View line-decode.lua
local find = string.find
local sub = string.sub
local function decode(chunk)
local i = find(chunk, "\n", 1, true)
if not i then return end
return sub(chunk, 1, i - 1), sub(chunk, i + 1)
end
local function encode(line)
View large-grid.js
var neopixelWrite = require('ESP8266').neopixelWrite;
var count = 256;
var pixels = new Uint8Array(count * 3);
function update() {
neopixelWrite(14, pixels);
}
function dampen(p) {
var i = (p % count) * 3;
pixels[i]>>>=1;
pixels[++i]>>>=1;