This file contains 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 wrappers = require('./wrappers'); | |
var http = require('http'); | |
var zlib = require('zlib'); | |
var util = require('util'); | |
var fs = require('fs'); | |
http.createServer(function(request, response) { | |
response.writeHead(200, { | |
'Content-Type': 'text/plain; charset=utf8', |
This file contains 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 g = 3; | |
function hackGlobal(fn) { | |
return function() { | |
var saveG = g; | |
try { | |
g = 5; | |
fn.apply(this, arguments); | |
} finally { | |
g = saveG; |
This file contains 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 count = 1000000; | |
function bench(fn, cb) { | |
var total = 0; | |
function loop(i) { | |
if (i === count) { | |
cb(null, total); | |
} else { |
This file contains 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() { | |
var GENERATOR_PROTO = Object.getPrototypeOf((function() { | |
yield; | |
})()); | |
function isGenerator(val) { | |
return typeof val === 'object' && Object.getPrototypeOf(val) === GENERATOR_PROTO; | |
} | |
var PENDING = {}; |
This file contains 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 Timer = require('uv').Timer; | |
function foo() { | |
var timer = new Timer(); | |
timer.start(1000, 0, function(err) { | |
f.send("ok"); | |
f.close(); | |
}) | |
var r = yield; | |
print("got " + r); |
This file contains 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
exports.generator = function() { | |
var found = []; | |
function isPrime(p) { | |
for (var i = 0; i < found.length; i++) { | |
var q = found[i]; | |
if (p % q === 0) return false; | |
if (q * q > p) return true; | |
} | |
return true; |
This file contains 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 fs = require('fs'); | |
var cache = {}, hit = 0, missed = 0; | |
function load(name, cb) { | |
var res = cache[name]; | |
if (res) { | |
process.nextTick(function() { | |
hit++; | |
cb(null, res); |
This file contains 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
if (!require('streamline/module')(module)) return; | |
function fibo(_, n) { | |
return n > 1 ? fibo(_, n - 1) + fibo(_, n - 2) : 1; | |
} | |
function fibo2(_, n) { | |
return n > 1 ? trampo(this, 0, fibo2, _, n - 1) + trampo(this, 0, fibo2, _, n - 2) : 1; | |
} |
This file contains 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 bench(name, fn) { | |
var result; | |
// 2 passes to let V8 optimize | |
for (var pass = 2; pass >= 0; pass--) { | |
var count = 1; | |
while (true) { | |
var t0 = Date.now(); | |
fn(count); | |
dt = (Date.now() - t0); | |
if (dt > 100) { |
This file contains 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"; | |
if (!require('streamline/module')(module)) return; | |
var fs = require('fs'); | |
var streams = require('streamline/lib/streams/server/streams'); | |
// cat ins > out | |
exports.chomp = function(ins, out, _) { | |
streams.usingWritable(_, fs.createWriteStream(out), function(_, outStream) { | |
for (var i = 0; i < ins.length; i++) { |