Skip to content

Instantly share code, notes, and snippets.

@benatkin
benatkin / server.js
Created January 8, 2012 08:57
downgrading node.js permission after binding to port 80
var express = require('express');
var app = express.createServer();
app.set('view engine', 'jade');
app.set('port', parseInt(process.env.PORT || 5000, 10));
app.get('/', function(req, res) {
res.render('index');
diff --git a/node/handler/APIHandler.js b/node/handler/APIHandler.js
index a057bfc..7476818 100644
--- a/node/handler/APIHandler.js
+++ b/node/handler/APIHandler.js
@@ -75,8 +75,8 @@ exports.handle = function(functionName, fields, req, res)
//check the api key!
if(fields["apikey"] != apikey)
{
- res.send({code: 4, message: "no or wrong API Key", data: null});
- return;
@creationix
creationix / route.js
Created December 5, 2011 19:12
Sanity check for async template idea
Creationix.route("GET", "/", function (req, res, params, next) {
render("frontindex", {
title: query("index", "title"),
links: query("index", "links"),
articles: loadArticles
}, function (err, html) {
if (err) return next(err);
res.writeHead(200, {
"Content-Length": Buffer.byteLength(html),
"Content-Type": "text/html; charset=utf-8"
@isaacs
isaacs / streams.md
Created September 26, 2011 00:58
A spec for streams

Status of this Document

This is a proposal. It does not match the code as of writing.

This describes the minimum contract that Stream objects must adhere to in order to properly interoperate with pipes.

Stream Class

The parent class for all stream objects. Implements the pipe

@laurie71
laurie71 / Vector.cc
Created May 20, 2011 01:18
test harness for proxying c++ classes in v8/node
#include "Vector.h"
Persistent<FunctionTemplate> Vector::ctor;
void
Vector::Initialize(Handle<Object> target) {
HandleScope scope;
ctor = Persistent<FunctionTemplate>::New(FunctionTemplate::New(New));
ctor->InstanceTemplate()->SetInternalFieldCount(1);
@guybrush
guybrush / nodeconf_2011.md
Created May 6, 2011 07:22
a list of slides from nodeconf 2011
var fs = require('fs');
OAuth = require('oauth').OAuth;
var config = JSON.parse( fs.readFileSync(__dirname + '/default_config.json') );
var oauth = config.oauth;
console.warn(oauth);
var oa = new OAuth(oauth.requestTokenURL
, oauth.accessTokenURL
@creationix
creationix / newisevil.js
Created August 11, 2010 20:38 — forked from brianleroux/wtftim.js
new is evil!
var Person = function( name ){ this.name = name };
Person.create = function(name) { return new Person(name) };
Brian = new Person('brianleroux');
Tim = Person.create('tim');
// Lame, I would do this one of three ways depending on how it will be used
// If the example really was this simple and there was nothing else involved,
// I would use object literals. No need to overcomplicate things
function createPool (port, host, https, credentials) {
var pool = new events.EventEmitter();
pool.clients = [];
var getClient = function () {
for (var i=0;i<pool.clients.length;i+=1) {
if (!pool.clients[i].busy) {
return pool.clients[i];
}
}
/** Testing sax push parsing
*
* The output file should have almost identical
* to the input file
*
* Known issues with this example output
*
* - Doesn't escape entities. You can do it
* manually on the character content.
* - Doesn't replicate self-closing tags.