Skip to content

Instantly share code, notes, and snippets.

@yzarubin
yzarubin / X-Error Controller Example.js
Last active August 29, 2015 14:16
Creating robust promise-based controllers with X-Error
var buildCtrl = function(promiseFn){
return function(req, res) {
promiseFn(req)
.then(function(data){
res.json(200, data);
}, function(e){
res.status(e.httpCode || 500)
@yzarubin
yzarubin / binary-index-tree.js
Last active May 10, 2016 02:35
Binary Index Tree in JavaScript
function BinaryIndexTree(size) {
this._tree = new Array(size + 1);
this._size = size;
for (var i = 0; i <= size; ++i) {
this._tree[i] = 0;
}
}
BinaryIndexTree.prototype.update = function(idx, value) {