Skip to content

Instantly share code, notes, and snippets.

@Hypercubed
Hypercubed / index.js
Created June 3, 2016 16:26
requirebin sketch
var barracks = require('barracks');
var dispatcher = barracks();
dispatcher.on('hello', function (name) {
document.write('Hello ' + name);
});
dispatcher.on('hello', function (name) {

Tests

✔ Platform [pass: 1, fail: 0, duration: 1ms]
✔ init [pass: 22, fail: 0, duration: 1ms]
✔ emit [pass: 27, fail: 0, duration: 12ms]
✔ emit with context [pass: 42, fail: 0, duration: 5ms]
✔ emit one value - two listeners [pass: 57, fail: 0, duration: 2ms]
✔ emit one value - one listener [pass: 40, fail: 0, duration: 1ms]
✔ emit many listeners [pass: 30, fail: 0, duration: 1ms]

Tests

✔ emit objects [pass: 30, fail: 0, duration: 6.8s]
✔ emit one parameter [pass: 38, fail: 0, duration: 9ms]

Summary

  • duration: 6.9s
  • assertions: 68
@Hypercubed
Hypercubed / .gitignore
Last active June 3, 2016 00:29
chuhai async
node_modules
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<script src="https://d3js.org/d3-dispatch.v0.4.min.js"></script>
<script>
var dispatch = d3_dispatch.dispatch('foo');
dispatch.on('foo', handle);
@Hypercubed
Hypercubed / chrome-v50.md
Last active May 17, 2016 07:19
EventsSpeedTests emit objects

Chrome 50.0.2661.102 on OS X 10.11.2

emit objects

EventEmitter ................................... 184,353 op/s
EventEmitter2 .................................. 1,366,034 op/s
EventEmitter3 .................................. 4,718,065 op/s
RXJS ........................................... 1,388,534 op/s
ReactiveProperty ............................... 5,766,001 op/s

JS-Signals ..................................... 175,555 op/s

@Hypercubed
Hypercubed / flatten.js
Created April 21, 2016 11:09 — forked from thetutlage/flatten.js
Flatten an array in Javascript without recursion
'use strict'
var Benchmark = require('benchmark')
var suite = new Benchmark.Suite;
var list = [1, 2, 3, [[4]], [[[5]]], [6], [[7]]]
function flattenRecursive (list) {
var flatList = []
list.forEach(function (item) {
const dict = require('dictionary-js');
const words = Object.keys(dict);
const xwords = xx => words.filter(x => x[0] === xx);
const kwords = xwords('K')
const iwords = xwords('I')
function randomWord (list) {
return list[Math.floor(Math.random() * list.length)];
};
{
"presets": [ "es2015-rollup" ]
}
@Hypercubed
Hypercubed / index.js
Created February 23, 2016 02:43
requirebin sketch
var Tokenizer = require('tokenizer');
var t = new Tokenizer();
t.on('token', function(token, type) {
console.log(token);
});
t.on('end', function() {
console.log(arguments);
});