Skip to content

Instantly share code, notes, and snippets.

@emilbayes
emilbayes / .block
Last active February 22, 2016 12:28 — forked from mbostock/.block
N-Body Problem
license: gpl-3.0
@import 'normalize.css';
@emilbayes
emilbayes / index.js
Last active October 5, 2015 10:41
requirebin sketch
'use strict'
var d3 = require('d3')
var speakerInput = window.document.getElementById('speaker')
var dateInput = window.document.getElementById('date')
var wordInput = window.document.getElementById('words')
var speechInput = window.document.getElementById('speech')
var csvOutput = window.document.getElementById('output')
@emilbayes
emilbayes / bundle.js
Created September 18, 2015 10:03
Poisson disc sample test
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
var d3 = require('d3')
var c = require('d3-convention')()
var prng = require('xorshift').constructor([172, 26, 125, 42])
var sample = require('poisson-disc-sampler')(c.innerWidth, c.innerHeight, 4, prng.random.bind(prng))
var ctn = 0
d3.timer(function () {
for (var i = 0; i < 10; i++) {
@emilbayes
emilbayes / index.js
Created May 8, 2015 12:37
requirebin sketch
'use strict';
//Inspired by http://bl.ocks.org/mbostock/517fdb49f959cb1461e2
var poissonDiscSampler = require('poisson-disc-sampler');
var d3 = require('d3');
var raf = require('raf');
var width = window.innerWidth;
var height = window.innerHeight;
var drift = 30;
@emilbayes
emilbayes / capped-array.js
Created March 24, 2015 21:52
Capped Array with equivalent API to Array
'use strict';
/*
var a = cappedArray(3); //limited to 3 items
var b = cappedArray(1, 2, 3); //limited to 3 items, populated with [1, 2, 3]
a.concat(b, 10); //deepEqaul to `cappedArray(2, 3, 10);`
*/
module.exports = function cappedArray(size) {
var self = [];
@emilbayes
emilbayes / attempted-solution.js
Created March 16, 2015 09:42
I need callbacks on _read
var stream = require('stream');
var outer = 0, inner = 0;
var collectorStream = stream.Readable({
highWaterMark: 1,
objectMode: true,
read: function() {
var self = this;
var id1 = outer++;
@emilbayes
emilbayes / package.json
Created March 12, 2015 10:17
Minimal password protected server
{
"name": "minimal-protected-server",
"version": "0.0.0",
"description": "Minimal password protected server",
"main": "server.js",
"dependencies": {
"basic": "0.0.3",
"st": "^0.5.3"
}
}
@emilbayes
emilbayes / json-pointer.js
Created March 10, 2015 14:57
Minimalistic JSON Pointer (RFC 6901) implementation. Does not support URI Fragments, but otherwise compliant
'use strict';
exports.get = function(document, pointer) {
//Empty pointer references the whole document
if(pointer === '') return document;
//Split the pointer into reference tokens and unescape
var referenceTokens = pointer.slice(1).split('/').map(unescape);
//Decent down the object iteratively
return referenceTokens.reduce(function(object, token) {
@emilbayes
emilbayes / example.js
Last active August 29, 2015 14:16
Stream Example
var stream = require('stream');
var messageStream = require('./message-stream');
var jsonify = new stream.Transform({
writableObjectMode: true,
transform: function(chunk, enc, cb) {
this.push(JSON.stringify(chunk, null, 2) + '\n');
cb();
}
});