This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function loop (fn, startValue) { | |
var deferred = Q.defer(), | |
finished = false; | |
function end (val) { | |
finished = true; | |
deferred.resolve(val); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var asap = require("asap") | |
asap.sub = function (onerror) { | |
var parent = this; | |
var self = function (task) { | |
parent(function () { | |
try { | |
task(); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def edgesFunc(G): | |
if callable(G): | |
return G | |
items = _itemsFunc(G) | |
return lambda v: items(G[v]) | |
# (list of dictionaries) | |
def bgraph(x, dicttype=dict): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*eslint-env es6*/ | |
const hasOwn = ({}).hasOwnProperty; | |
// Check if two objects are equal by comparing own enumerable properties. | |
const isEqualShallow = (a, b) => { | |
if (a === b) return true; | |
if (!a || !b) return false; | |
const akeys = Object.keys(a); | |
const bkeys = Object.keys(b); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const spawn = generatorFunction => function() { | |
const gen = generatorFunction.apply(this, arguments); | |
return new Promise(resolve => { | |
const handle = (it) => { | |
if (it.done) { | |
return it.value; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is a quick example on how we could wait for real loaded state | |
// by monitoring traffic. If needed, traffic filtering could be added. | |
var dataByTabId = {} | |
function getDataByTabId (tabId) { | |
if (!dataByTabId[tabId]) { | |
dataByTabId[tabId] = { | |
reqCounter: 0, | |
callbacks: [], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function timeout (ms, x) { | |
return new Promise((resolve, reject) => { | |
let timeoutId = setTimeout(() => { | |
timeoutId = null | |
reject('timeout') | |
}, ms) | |
const onSettle = () => { | |
if (timeoutId != null) { | |
clearTimeout(timeoutId) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
const objToStringMethod = Object.prototype.toString | |
const reRegExpChar = /[\\^$.*+?()[\]{}|]/g | |
const reUnescapedSpaces = /(?<!\\)\s+/g | |
const reHasSpace = /\s/ | |
const compact = raw => reHasSpace.test(raw) ? raw.replace(reUnescapedSpaces, '') : raw | |
const escape = val => String(val).replace(reRegExpChar, '\\$&') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const identity = x => x | |
/** | |
* Creates a predicate function to check if a value is not seen before | |
* | |
* @param {function} [by = x=>x] | |
* @returns {function} predicate function | |
* | |
* @example | |
* |