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 getFoos(nextOffset, results) { | |
nextOffset = nextOffset || 0; | |
results = results || [ ]; | |
return Promise.try(() => { | |
return getSomeFoos(nextOffset); | |
}).then(res => { | |
let newResults = results.concat(res.foos); | |
return res.hasMore ? | |
getFoos(res.nextOffset, newResults) : |
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
// paginate('get', '/foo', {...}) | |
const paginate = (method, path, opts, offset, results) => { | |
offset = offset || 0; | |
results = results || [ ]; | |
return Promise.try(() => | |
request(method, path, Object.assign(opts, { offset })) | |
).then(res => { | |
let newResults = results.concat(res.data); | |
if (!res.pagination) { return newResults; } |
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 Transform = require('stream').Transform; | |
const util = require('util'); | |
function ChunkStream(options) { | |
if (!(this instanceof ChunkStream)) | |
return new ChunkStream(options); | |
Transform.call(this, options); | |
this.chunkSize = options.chunkSize || 1500; | |
this._chunks = [ ]; |
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 sequentially(array, promiseFn) { | |
return array.reduce((acc, current) => | |
acc.then(results => | |
promiseFn(current).then(res => | |
results.concat(res) | |
) | |
) | |
, Promise.resolve([]); | |
} |
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
penguinfrk: 2309, | |
Chew: 2236, | |
piper: 2215, | |
goonerJimmy: 2180, | |
Chopin: 2173, | |
Blitz: 2137, | |
JuhuarKnight: 2072, | |
shinanai: 2069, | |
be_f: 2032, | |
sonic: 2002, |
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
// values 0 through 6 represent tetris pieces | |
// heap[1] is always the piece that has been seen the | |
// fewest number of times (or is tied with it) | |
heap = [unused, 0, 1, 2, 3, 4, 5, 6] | |
update(piece_id) { | |
// find the piece to update | |
for (ptr = 1; ptr <= 8; ptr++) { | |
if (heap[ptr] & 0x07 == piece_id) break; | |
} | |
if (ptr == 8) { |
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 resource = app.swag.createResource('Foo'); | |
resource.get('/foo', { | |
name: 'Foos', | |
params: { | |
filter: 'string', | |
itemsPerPage: 'integer' | |
}, | |
returns: 'SomeModel' //models are declared elsewhere/separately | |
}, function (req, res) { |
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 schema = Joi.object().keys({ | |
isRegister: Joi.any(), | |
username: Joi.string(), | |
password: Joi.string(), | |
email: Joi.string() | |
}).with('isRegister', 'username', 'password'); | |
app.post('/register', function (req, res) { | |
const isValid = schema.validate(Object.assign({ isRegister: true }, req.params)); | |
}); |
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 Joi = require('joi'); | |
const schema = { | |
a: Joi.number(), | |
b: Joi.number(), | |
}; | |
const value = { | |
a: 'AAA', | |
b: "BBB" |
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 Joi = require('joi'); | |
const util = require('util'); | |
const schema = Joi.object().keys({ | |
a: Joi.number().meta('bad a'), | |
b: Joi.number().meta('bad b') | |
}).error(errs => { | |
let obj = { }; | |
errs.forEach(err => { | |
obj[err.path] = Joi.reach(schema, err.path).describe().meta[0]; |