Skip to content

Instantly share code, notes, and snippets.

"use strict"
exports.container = function() {
var head = {
next: null
}
this.add = function(shell) {
head.next = {
shell: shell,
@voltrevo
voltrevo / gist:92f898919bb11275f17d
Last active August 29, 2015 14:19
ES6 Newton Demo
"use strict"
const newton = ({
f,
df,
initialGuess,
tolerance = Number.EPSILON,
maxIterations = 1000
}) => {
let x = initialGuess;
@voltrevo
voltrevo / promiseMap
Created May 13, 2015 00:35
A map that lazily creates promises so that you can refer to possibly not yet existing promises by their id.
var promiseMap = function() {
var api = {_: {}};
api._.map = {};
api._.getPromiseHandle = function(id) {
var promiseHandle = api._.map[id];
if (!promiseHandle) {
promiseHandle = {
@voltrevo
voltrevo / gist:e03538e95e3701309aa2
Last active August 29, 2015 14:22
mutex concept
'use strict'
var mutex = require('mutex') // (this doesn't exist, it's just an illustration)
var playerMutexes = getPlayerMutexes() // (as above)
var gameBoardMutexes = getGameBoardMutexes() // (as above)
var getPairs = function(arr) {
var results = []
'use strict';
var mapWithDefault = require('./mapWithDefault');
module.exports = function addEventing(obj) {
var handlers = mapWithDefault(function() {
return [];
});
obj.trigger = function(evtName) {
@voltrevo
voltrevo / interval.js
Created July 23, 2015 00:02
Alternative to setInterval / clearInterval
var interval = (function() {
var api = {};
var idMap = {};
var nextId = 0;
api.set = function(task, ms) {
var nextTime = Date.now() + ms;
var id = nextId++;
@voltrevo
voltrevo / stress.js
Created August 3, 2015 04:22
Simulate stress on javascript execution by spin locking intermittently
'use strict';
module.exports = function stress(interDelay, spinDelay, duration) {
var spinLock = function(spinDuration) {
var start = Date.now();
while (Date.now() - start < spinDuration) {
// Do nothing
}
};
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
'use strict';
module.exports = function(condition, loop, result) {
return Promise.resolve((function run() {
if (!condition()) {
return result();
}
return loop().then(run);
})());