Skip to content

Instantly share code, notes, and snippets.

View stash's full-sized avatar
🎯
Focusing

Jeremy Stashewsky stash

🎯
Focusing
View GitHub Profile
@stash
stash / node-redis-data-pubsub.js
Created September 30, 2011 21:09
Streaming data pubsub - node.js + redis
var redis = require('redis');
var pubcli = redis.createClient(6380, '127.0.0.1');
var subcli = redis.createClient(6380, '127.0.0.1');
var datacli = redis.createClient(6380, '127.0.0.1', {return_buffers:true});
var have = 0;
datacli.lrange('data.theresource', 0, -1, function(err,chunks) {
console.log("initial data!",chunks);
@stash
stash / basic.js
Created October 5, 2011 15:31
Logging with runtime level selection in node.js
var N = process.argv[2] || 1000000;
function log () {
console.log.apply(console,arguments);
}
for (var i=0; i<N; i++) {
log("this is message"+i);
}
// didn't run to completion, stopped at ~5m18s
/*** tough-cookie/lib/cookie.js ***/
/* I added the following to the end of the file for testing purposes */
memstore = require('./memstore');
module.exports.MemoryCookieStore = memstore.MemoryCookieStore; // ok to keep the original label ~stash
/*** jsonstore.js ***/
var tough = require('tough-cookie');
// ...
@stash
stash / app.js
Created January 5, 2012 20:22
socket.io transport tracing
process.env['NODE_ENV'] = 'production';
var app = require('http').createServer(handler)
, io = require('socket.io').listen(app)
, fs = require('fs')
app.listen(80);
function handler (req, res) {
fs.readFile(__dirname + '/index.html',
function (err, data) {
@stash
stash / vows-oom.js
Created January 9, 2012 22:58
Strange out-of-memory
var vows = require('vows');
var assert = require('assert');
var https = require('https');
vows.describe("dies?").addBatch({
"pretend this is doing several https requests": {
topic: function() {
var cb = this.callback;
// https is important; http doesn't produce an error
var req = https.request({host:'encrypted.google.com',path:'/',method:'GET'}, function(res) {
@stash
stash / https-no-drain.js
Created January 31, 2012 19:18
No 'drain' for HTTPS servers
var fs = require('fs');
var path = require('path');
var https = require('https');
var http = require('http');
var pem = fs.readFileSync(path.resolve(__dirname,'./test.pem'));
var util = require('util');
var protocol = process.argv[2] == 'http' ? http : https;
var agent = new protocol.Agent();
@stash
stash / policy-flooder.js
Created February 16, 2012 21:13
flash policy flooder
var net = require('net');
var async = require('async');
var spew = new Buffer('<policy-file-request/>\0');
var NUM = process.argv[2] || 10;
var CONCURRENCY = process.argv[3] || 10;
var got = 0;
function worker(task, next) {
@stash
stash / proxy.js
Created March 15, 2012 17:48
HTTP proxy in 5 minutes
var http = require('http');
var server = http.createServer(function(req,res) {
var opts = {
method: 'GET', host: 'news.ycombinator.com', port: 80, path: req.url
};
var proxyReq = http.request(opts, function(proxyRes) {
var chunks = '';
@stash
stash / optify.js
Created March 27, 2012 16:40
optify.js - refactor long function parameters into "pass an opts object" style
/*
* optify.js - refactor long function parameters into "pass an opts object" style
*
* vim instructions:
* 1) Using shift-v, select `function (a,b,c,d,e,cb) {`
* 2) Type ":!node ~/optify"
* 3) Selection is replaced with:
* function (opts,cb) {
* var a = opts.a;
* var b = opts.b;
@stash
stash / Makefile.patch
Created June 7, 2012 15:26
Compiling tmux on SmartOS
--- tmux-1.6/Makefile 2012-06-07 15:23:20.835144809 +0000
+++ tmux-1.6-modified/Makefile 2012-06-07 15:22:47.803578987 +0000
@@ -211,7 +211,7 @@
CPP = gcc -E
# Preprocessor flags.
-CPPFLAGS = -I/opt/local/include -I/opt/local/include/ncurses -D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED $(am__append_4) $(am__append_5) \
+CPPFLAGS = -I/opt/local/include -I/opt/local/include/ncurses $(am__append_4) $(am__append_5) \
$(am__append_7) $(am__append_8)
CYGPATH_W = echo