Skip to content

Instantly share code, notes, and snippets.

View stellaraccident's full-sized avatar

Stella Laurenzo stellaraccident

  • Amd
  • Seattle Washington, US
View GitHub Profile
@stellaraccident
stellaraccident / runtests.js
Created March 22, 2011 00:22
My testrunner stub
#!/usr/bin/env node
require.paths.unshift(__dirname + '/local/lib');
process.chdir(__dirname);
var files=process.argv.slice(2).map(function(v) {
return v;
});
if (files.length===0) {
// Just run the whole directory
@stellaraccident
stellaraccident / control-block-http-example1.js
Created March 21, 2011 20:05
Bulletproof node coding snippets
request: function(options) {
var future=new Future();
var req=http.request(options, function(res) {
var text='';
res.setEncoding('utf8');
res.on('data', function(chunk) {
text+=chunk;
});
res.on('end', Block.guard(function() {
/**
* Implements the http protocol bindings for the session client api.
* All of the guts are actually passed down to a handler object that
* is passed in at construction time.
*/
var connect=require('connect');
function ClientApiHttp(handler) {
var pageRouter=connect.router(function(app) {
app.post('/registerUserAgent', handleRegisterUserAgent);
@stellaraccident
stellaraccident / armor.js
Created February 15, 2011 20:31
connect style middleware to proxy requests to another server
/**
* Pattern for performing error handling given standard node
* callback patterns (ie. error passed as first argument).
*/
function Armorer(nextCallback) {
this.nextCallback=nextCallback;
this.cleanupCallbacks=[];
}
Armorer.prototype={
onCleanup: function(callback) {
@stellaraccident
stellaraccident / proxy.js
Created February 15, 2011 20:31
connect style middleware to proxy requests to another server
/**
* Simple proxy intended to be used as middleware to direct parts
* of an HTTP namespace to other servers.
*
* Copyright (c) 2011, Stella Laurenzo
*/
var util=require('util'),
url=require('url'),
http=require('http'),
armor=require('./armor');
diff --git a/lib/http.js b/lib/http.js
index 9506a8c..73b507e 100644
--- a/lib/http.js
+++ b/lib/http.js
@@ -884,8 +884,18 @@ function httpSocketSetup(socket) {
}
-function Server(requestListener) {
- if (!(this instanceof Server)) return new Server(requestListener);
@stellaraccident
stellaraccident / rcutil.ecmabackport.js
Created January 25, 2011 22:39
Some boilerplate JavaScript bits from otherwise not published sources
/**
* rcutil.ecmabackport.js
* Backport various new ecmascript functions to older runtime
* environments.
*/
(function() {
var _Object=Object, _FunctionPrototype=Function.prototype,
_Array=Array, _ArrayPrototype=_Array.prototype;
// Take advantage of old ecmascript defaults of the global
@stellaraccident
stellaraccident / armor.js
Created January 23, 2011 16:36
Illustrate exception handling with a simple proxy middleware
/**
* Pattern for performing error handling given standard node
* callback patterns (ie. error passed as first argument).
*/
function Armorer(nextCallback) {
this.nextCallback=nextCallback;
this.cleanupCallbacks=[];
}
Armorer.prototype={
onCleanup: function(callback) {