Attention: the list was moved to
https://github.com/dypsilon/frontend-dev-bookmarks
This page is not maintained anymore, please update your bookmarks.
var fs = require('fs'); | |
var infile = process.argv[2]; | |
if (!infile) return console.log("need infile"); | |
var data = fs.readFileSync(infile, 'utf8').split('\n'); | |
var outlines = []; | |
data.forEach(function(item) { |
Attention: the list was moved to
https://github.com/dypsilon/frontend-dev-bookmarks
This page is not maintained anymore, please update your bookmarks.
// Lack of tail call optimization in JS | |
var sum = function(x, y) { | |
return y > 0 ? sum(x + 1, y - 1) : | |
y < 0 ? sum(x - 1, y + 1) : | |
x | |
} | |
sum(20, 100000) // => RangeError: Maximum call stack size exceeded | |
// Using workaround |
var request = require('request').defaults({json: true}), | |
transfuse = require('transfuse'), | |
JSONStream = require('JSONStream'); | |
function transform(couchdb, funcString, headers) { | |
var down = request({url: couchdb + '/_all_docs?include_docs=true'}), | |
up = request({url: couchdb + '/_bulk_docs', method: "POST", headers: headers}), | |
tr = transfuse(['rows', /./, 'doc'], funcString, JSONStream.stringify("{\"docs\":[\n", "\n,\n", "\n]}\n")); | |
down.pipe(tr) | |
tr.pipe(up) |