Skip to content

Instantly share code, notes, and snippets.

James Halliday substack

Block or report user

Report or block substack

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@substack
substack / kv.js
Created Oct 29, 2018
trie k/v but it's slow
View kv.js
var createHash = require('crypto').createHash
module.exports = KV
var KEY_SIZE = 16
var TRIE_SIZE = KEY_SIZE*4
function KV (storage, opts) {
if (!(this instanceof KV)) return new KV(storage, opts)
if (!opts) opts = {}
this.storage = storage
View after-batches.js
var randombytes = require('crypto').randomBytes
module.exports = function (n, opts) {
var batch = []
var refs = []
for (var i = 0; i < n; i++) {
if (i % 5 === 4) {
batch.push({
type: 'put',
id: randombytes(8).toString('hex'),
@substack
substack / light.sh
Created Sep 22, 2018
backlight script
View light.sh
#!/bin/bash
n=$1
if test -z "$n"; then
cat /sys/class/backlight/radeon_bl0/brightness
exit
elif echo "$n" | grep '%'; then
max=$(cat /sys/class/backlight/radeon_bl0/max_brightness)
nn=$(echo "$n" | sed 's/%$//')
b=$(cat /sys/class/backlight/radeon_bl0/brightness)
n=$((b+nn*max/100))
View axis.js
var mat4 = require('gl-mat4')
var quat = require('gl-quat')
module.exports = function (regl, d) {
var model = new Float32Array(16)
var positions = new Float32Array(3*6)
return regl({
frag: `
precision highp float;
uniform vec3 axis;
@substack
substack / waveform.js
Created Jul 31, 2018
render waveform data to a framebuffer in webgl
View waveform.js
module.exports = function (regl) {
var fb = regl.framebuffer()
var draw = regl({
frag: `
precision highp float;
uniform sampler2D left, right;
varying vec2 uv;
void main () {
vec4 c = texture2D(left, vec2(uv.x,0.5));
float amp = pow(clamp(0.0,1.0,c.x),0.25)-abs(uv.y*2.0-1.0);
View player.js
module.exports = function (state, emitter) {
state.pxPerSecond = 10
state.position = 0
state.sources = {}
state.play = { playing: false, start: 0 }
state.playQueue = []
state.played = []
emitter.on('play', function () {
state.play.playing = true
View generate.js
var Simplex = require('simplex-noise')
module.exports = function (state, emitter) {
state.tiles = {
size: [0,0],
data: []
}
emitter.on('generate', function (seed) {
var simplex = new Simplex(seed)
var v = simplex.noise2D(500,500)*0.5+0.5
@substack
substack / build-kdb.js
Created Apr 24, 2018
top-down kdb construction
View build-kdb.js
module.exports = function build (rows, opts) {
var B = opts.branchFactor
var write = opts.write
var fB = Math.floor(B/2)
var cB = Math.ceil(B/2)
;(function walk (rows, depth, index) {
if (rows.length === 1) {
write(index, rows[0])
}
if (rows.length <= 1) return
@substack
substack / format.md
Created Apr 17, 2018
spatial tree format
View format.md
[header] (size: 20 bytes)
  uint32_t N
  uint32_t staging_len
  uint8_t[24] bitfields

[staging] (size: N*1 bytes)
[tree0] (size: N*1 bytes)
[tree1] (size: N*2 bytes)
...
View gist:4469cf83e0c085869122502fb1e61c9a
function swarm (key, branches, opts) {
var swarmDefaults = require('datland-swarm-defaults')
var disc = require('discovery-swarm')
var EventEmitter = require('events').EventEmitter
if (!opts) opts = {}
var sync = new EventEmitter
var sw = disc(swarmDefaults(Object.assign({
port: 3282,
id: branches[0].key,
hash: false,
You can’t perform that action at this time.