Skip to content

Instantly share code, notes, and snippets.

View billywhizz's full-sized avatar
🤓
always be learning

Andrew Johnston billywhizz

🤓
always be learning
View GitHub Profile
@billywhizz
billywhizz / tcp.js
Created December 6, 2011 18:53
minimal node.js tcp server
var TCP = process.binding("tcp_wrap").TCP;
try {
var crypto = process.binding("crypto");
var SecureContext = crypto.SecureContext;
} catch (e) {
throw new Error("node.js not compiled with openssl crypto support.");
}
function noop() {};
function createCredentials(key, cert, ciphers) {
@billywhizz
billywhizz / handletest.js
Created January 12, 2012 17:30
server listen on existing libuv handle
var net = require("net");
var TCP = process.binding("tcp_wrap").TCP;
var Pipe = process.binding("pipe_wrap").Pipe;
var sock1 = new TCP();
sock1.bind("0.0.0.0", 80);
var sock2 = new Pipe();
sock2.bind("/tmp/handle.sock");
var server1 = net.createServer(function(c) {
@billywhizz
billywhizz / nodeftpd.js
Created January 13, 2012 20:03
ftp api
var FTPServer = require("nodeftpd").Server;
var options = {
host: "localhost",
pasvip: "127.0.0.1",
port: 21,
portrange: {
lo: 1025,
hi: 2048
},
@billywhizz
billywhizz / bench.js
Created February 14, 2012 23:50
node.js static file serving benchmark
var TCP = process.binding("tcp_wrap").TCP;
var Buffer = process.binding("buffer").SlowBuffer;
var HTTPParser = process.binding("http_parser").HTTPParser;
function setupSocket(peer) {
function shutdownHandler(status, handle, req) {
// TODO: ensure we only shutdown once
if(status != 0) {
if(peer.onerror) {
var err = new Error("shutdown");
@billywhizz
billywhizz / haiku.js
Created March 1, 2012 11:16
haiku test
res.writeHead(200);
throw(new Error("poof!"));
res.end();
@billywhizz
billywhizz / http.js
Created March 29, 2012 03:49
node.js url escaping example
var http = require("http");
http.createServer(function (req, res) {
console.log(require("url").parse(req.url, true));
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(80, '0.0.0.0');
@billywhizz
billywhizz / results.txt
Created April 10, 2012 17:02
streamline.js overhead
test.js:
29,222,676 calls per second
test-named:
50,505,050 calls per second
test-streamline.js:
332,557 calls per second
@billywhizz
billywhizz / bencCallbacks.js
Created April 12, 2012 12:40
response to bruno's streamline benchmark
"use strict";
var fs = require('fs');
var cache = {}, hit = 0, missed = 0;
var count = parseInt(process.argv[2]) || 1000000;
var fname = __dirname + "/benchCallbacks.js";
function bench(cb) {
var total = 0;
var current = 0;
function handleResult(err, data) {
@billywhizz
billywhizz / statement-cache.diff
Created October 25, 2012 17:49
node-oracle statement cache patch
diff --git a/src/oracle_bindings.cpp b/src/oracle_bindings.cpp
old mode 100644
new mode 100755
index bbcf611..1ea38a2
--- a/src/oracle_bindings.cpp
+++ b/src/oracle_bindings.cpp
@@ -84,6 +84,7 @@ void OracleClient::EIO_Connect(uv_work_t* req) {
std::ostringstream connectionStr;
connectionStr << "//" << baton->hostname << ":" << baton->port << "/" << baton->database;
baton->connection = baton->environment->createConnection(baton->user, baton->password, connectionStr.str());
@billywhizz
billywhizz / Array.sliceAfter.js
Created June 6, 2013 22:48
get slice of sorted array greater than passed in value
Array.prototype.sliceAfter = function(expr) {
var index = 0;
var found = this.some(function(v, i, a) {
if(v > expr) {
index = i;
return true;
}
});
if(!found) return [];
return this.slice(index);