Skip to content

Instantly share code, notes, and snippets.

/**
* Mixin to let object fire events and let consumers
* listen to those events.
*
* @param object {Object} - producer of events.
* @param contract {Array of strings} - optional events contract.
*
* Examples:
* var obj = eventify({});
* // now you can listen to object's events:
var createArray = function (length) {
var arr = [];
for(var i = 0; i < length; ++i) {
arr[i] = 0.1;
}
return arr;
},
length = 10000,
arr1 = createArray(length),
arr2 = createArray(length);
function runtIt(n) {
'use strict';
/* The Computer Language Benchmarks Game
http://benchmarksgame.alioth.debian.org/
contributed by Isaac Gouy
Optimized by Roy Williams
"Deoptimized" to plain JS objects by Anvaka*/
/**
* @type {number}
/* The Computer Language Benchmarks Game
http://benchmarksgame.alioth.debian.org/
contributed by Isaac Gouy
Optimized by Roy Williams*/
/**
* @type {number}
*/
var PI = 3.141592653589793;
function runTest(n) {
'use strict';
/* The Computer Language Benchmarks Game
http://benchmarksgame.alioth.debian.org/
contributed by Isaac Gouy
Optimized by Roy Williams
Changed to JS arrays by Anvaka
*/
/**
// Do you think this is valid JS?
// Hint: copy this code to your dev tools conosle.
var emptyString = "
";
🌀 🌁 🌂 🌃 🌄 🌅 🌆 🌇 🌈 🌉 🌊 🌋 🌌 🌍 🌎 🌏
🌐 🌑 🌒 🌓 🌔 🌕 🌖 🌗 🌘 🌙 🌚 🌛 🌜 🌝 🌞 🌟
🌠 🌡 🌢 🌣 🌤 🌥 🌦 🌧 🌨 🌩 🌪 🌫 🌬 🌭 🌮 🌯
🌰 🌱 🌲 🌳 🌴 🌵 🌶 🌷 🌸 🌹 🌺 🌻 🌼 🌽 🌾 🌿
🍀 🍁 🍂 🍃 🍄 🍅 🍆 🍇 🍈 🍉 🍊 🍋 🍌 🍍 🍎 🍏
🍐 🍑 🍒 🍓 🍔 🍕 🍖 🍗 🍘 🍙 🍚 🍛 🍜 🍝 🍞 🍟
🍠 🍡 🍢 🍣 🍤 🍥 🍦 🍧 🍨 🍩 🍪 🍫 🍬 🍭 🍮 🍯
🍰 🍱 🍲 🍳 🍴 🍵 🍶 🍷 🍸 🍹 🍺 🍻 🍼 🍽 🍾 🍿
🎀 🎁 🎂 🎃 🎄 🎅 🎆 🎇 🎈 🎉 🎊 🎋 🎌 🎍 🎎 🎏
🎐 🎑 🎒 🎓 🎔 🎕 🎖 🎗 🎘 🎙 🎚 🎛 🎜 🎝 🎞 🎟
@anvaka
anvaka / 0.nodes.js
Last active December 26, 2015 12:18
Trying to come up with API for graph traversal. API delays calculation of actual traversal as much as it can. That is, you do not actually starting graph traversal, until you call forEach() method.
// How to get all nodes?
traverse(graph)
.nodes()
.forEach(function(node) {
// node is here
});
// how to get all neighbors of startNodeId?
var grandChildren = traverse(graph)
.nodes()
@anvaka
anvaka / option1.js
Last active January 1, 2016 19:59
Imagine you have graph layout algorithm, which uses a physical engine. The engine has dozens of configuration options. What do you think is the best way to expose these options?
// engine is injected into layout:
var layout = forceBasedLayout(engine);
// Modify global gravity force:
engine.gravity(9.8);
// Modify drag coefficient:
engine.drag(0.1);
// ... you can also chain code above
// engine.gravity(9.8).drag(0.1);