Instantly share code, notes, and snippets.

View benchmark-compare-keys-vs-loop-obj-iteration.spec.js
require("microtime");
const
_ = require('lodash'),
Benchmark = require('benchmark'),
suite = new Benchmark.Suite,
result = [],
seedSize = 10000,
seedData = Array(seedSize).fill().map(() => String(Math.round(Math.random() * seedSize))).reduce((obj, val) => {
View benchmark-unique-string-set-vs-obj.benchmark.js
const
_ = require('lodash'),
Benchmark = require('benchmark'),
suite = new Benchmark.Suite,
result = [],
seedSize = 10000,
seedData = Array(seedSize).fill().map(() => String(Math.round(Math.random() * seedSize)));
suite
View fake_nsp_package.js
#!/usr/bin/env node
const
resolve = require('path').resolve,
loadJSON = function (file) {
return JSON.parse(require('fs').readFileSync(file).toString());
},
dependencySources = ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies',
View bunde_dependencies.js
#!/usr/bin/env node
/**
* Read a package.json file and then replace all dependencies and
* optionally dev dependencies into bundled dependencies.
*/
var p = '',
writeFile = require('fs').writeFile,
resolve = require('path').resolve;
View tail-slack.sh
#!/bin/bash
tail -n0 -F "$1" | while read LINE; do
(echo "$LINE" | grep -e "$3") && curl -X POST --silent --data-urlencode \
"payload={\"text\": \"$(echo $LINE | sed "s/\"/'/g")\"}" "$2";
done
View describe-it.min.js
(typeof tests!=='object')&&(tests={});var
it=((it=function(k,v){it.d.push(k);it.t[it.d]=1;it.b.forEach(it.c);try{v()}catch(e){it.t[it.d]=0;setTimeout&&setTimeout(function(){throw e;})}it.a.forEach(it.c);it.d.pop()}),
it.a=[],it.b=[],it.c=function(x){x()},it.d=[],it.d.toString=function(){return this.join(' ')},
it.t=tests,it.x=function(v){this.v=v},it.xp=it.x.prototype,it.xp.toBe=function(x){(this.v!==x)&&it._()},
it.xp.toNotBe=function(x){(this.v===x)&&it._()},it.xp.toEql=function(x){(this.v!=x)&&it._()},
it.xp.toNotEql=function(x){(this.v==x)&&it._()},it.xp.toBeOk=function(){!this.v&&it._()},
it.xp.toNotBeOk=function(){this.v&&it._()},it),describe=function(k,v){it.d.push(k);v();it.d.pop()},
expect=function(v){return new it.x(v)},beforeEach=it.b.push.bind(it.b),afterEach=it.a.push.bind(it.a);
View describe-it.js
/**
* @module describe-it
*
* This module defines global variables to provide unit test case runner functions compatible with mocha and jasmine.
* The codebase is written for brevity and facilitate being as lightweight as possible.
*
* The code is intended to be included in Postman Test Sandbox.
*/
/**
View SlackBootstrap.js
/**
* Bootstrap module for Slack notification on server startup
*
* Expects: config/slack.js
* - enabled
* - organisation
* - key
* - messages.spawn
* - payload
*/
View ServerStatsBootstrap.js
/**
* ServerStatsBootstrap.js
* Bootstrap module to log server version from package file
*/
module.exports = function (done) {
require('fs').readFile('package.json', function (err, data) {
// exit if error in reading file
if (err) {
sails.log.error('Unable to read package. %s', err);
return done();
View bootstrap.js
/**
* Bootstrap
* (sails.config.bootstrap)
*
* An asynchronous bootstrap function that runs before your
* Sails app gets lifted.
*/
module.exports.bootstrap = function (callback) {
// load all modules *Bootstrap.js in bootstrap directory
// and execute async