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 highlight = (obj, path) => { | |
let steps = path.split('.'), | |
prop = steps.shift(); | |
if (obj[prop] && steps.length) | |
return highlight(obj[prop], steps.join('.')); | |
else if (obj[prop]) | |
obj[prop] = '<span style=\'background-color:yellow;\'>' + obj[prop] + '</span>'; | |
else | |
return undefined; |
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'; | |
let Hapi = require('hapi'), | |
h2o2 = require('h2o2'); | |
let server = new Hapi.Server(); | |
let proxies = {}; | |
server.connection({ |
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'; | |
import Stream from 'stream'; | |
import config from 'config'; | |
import Hapi from 'hapi'; | |
let server = new Hapi.Server(config.server); | |
server.connection(config.connection); |
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
let valve = new Throtl.Valve({ | |
limit: 20, | |
objectMode: true | |
}); | |
reply(null, usersController | |
.readStream() | |
.pipe(valve) | |
.pipe(through.obj(function (user, enc, next) { |
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'; | |
var data = { | |
foo: 'bar', | |
baz: { | |
qux: 'zaq', | |
oof: 'rab' | |
} | |
}, | |
_ = require('lodash'); |
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 accepts a raw UDP buffer & decodes it into an object | |
let ber = require('asn1').Ber; | |
var PduType = { | |
160: "GetRequest", | |
161: "GetNextRequest", | |
162: "GetResponse", | |
163: "SetRequest", | |
164: "Trap", | |
165: "GetBulkRequest", |
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 Cylon = require('cylon'); | |
Cylon.robot({ | |
connections: { | |
sphero: { adaptor: 'sphero', port: '/dev/tty.Sphero-RPG-AMP-SPP' } | |
}, | |
devices: { | |
sphero: { driver: 'sphero' } | |
}, |
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
// http://math.stackexchange.com/questions/42640/calculate-distance-in-3d-space | |
/** | |
* Calculate the square root of a number | |
* @param {Number} n The number for which to find a square root | |
* @returns {Number} Returns the square root of n | |
*/ | |
function sqrt(n) { | |
return Math.sqrt(n); | |
} |
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 request = require('request'), | |
fs = require('fs'), | |
fnlimit = require('fnlimit'); | |
//http://www.pctmap.net/pctdownloads/ca_section_a_map.zip | |
var files = [ | |
'ca_section_a', | |
'ca_section_b', | |
'ca_section_c', | |
'ca_section_d', |
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 findRandom(limit) { | |
return Promise(function(resolve, reject) { | |
Model.count({}, function(err, count) { | |
var skip = _.random(0, count - limit); | |
Model.find().skip(skip).limit(limit).exec(function(err, docs) { | |
if (err) | |
return reject(err); | |
resolve(docs); | |
}); | |
}); |