Skip to content

Instantly share code, notes, and snippets.

@spollack
spollack / streamlineLoader.js
Created January 8, 2014 22:38
A thunk to load a single streamline source file (passed as a command line parameter) from vanilla node. Useful for one-offs. A similar approach can be taken to run mocha tests that include streamline code. The use of the optimist package here is pure sugar, and could be skipped if desired. In a typical full app, the main file would do the stream…
require('streamline').register({
fibers: true,
cache: true,
verbose: true
});
var argv = require('optimist')
.usage('Usage: $0 -r streamlineFilePath')
.demand(['r'])
.argv;
@spollack
spollack / example1a.js
Created January 4, 2014 21:11
Node + Streamline Blog Examples
function login_callbacks(email, password, onCompletion) {
db.crudOp('account', 'read', {conditions:{email:email}}, function (error, dbAccount) {
if (error) {
return onCompletion(error, null);
}
bcrypt.compare(password, dbAccount.password_hash, function (error, match) {
if (error) {
return onCompletion(error, null);
}
if (!match) {
@spollack
spollack / gist:7312619
Last active December 27, 2015 10:39
example of monkey-patching express to handle streamlinejs middleware. tested under express 2.x, but the same approach should work under express 3.x too.
var app = express.createServer();
var verbs = ['get', 'post', 'put', 'delete']; // whatever verbs you want to patch here...
patchExpressForStreamlineMiddleware(app, verbs, noop);
// now, you can make a call like this:
// app.get('/mypath', myStreamlineFunction)
// and have it work correctly. sequences of middleware will work too:
// app.get('/mypath2', myStreamlineFunction1, myStreamlineFunction2, myStreamlineFunction3)
@spollack
spollack / compiled
Last active December 25, 2015 00:39
example that demonstrates how streamline 0.8.1 in fibers mode is not preserving line numbers when invoking non-streamline functions, if the call spans multiple lines
/*** Generated by streamline 0.8.1 (fibers) - DO NOT EDIT ***/var fstreamline__ = require("streamline/lib/fibers/runtime"); (fstreamline__.create(function(_) {var test_ = fstreamline__.create(test, 0), foo_ = fstreamline__.create(foo, 0); function test(_) {
foo(_);
fstreamline__.invoke(null, bar, [_], 0);
};
function foo(_) {
// set a breakpoint on the next line
console.log('should not print before breakpoint hit');
console.log('should print after breakpoint hit');
}
@spollack
spollack / streamline_perf._js
Created September 6, 2013 23:22
A script that demonstrates a performance dropoff in streamline between versions 0.6.0 and 0.8.0.
var zlib = require('zlib');
test(_);
function test(_) {
var startTime = new Date();
var items = [];
@spollack
spollack / leak.js
Last active December 12, 2015 04:48
var zlib = require('zlib');
var iteration = 0;
var maxRss = 0;
(function leak() {
if (iteration % 1000 === 0) {
var usage = process.memoryUsage();