Skip to content

Instantly share code, notes, and snippets.

@draeton
draeton / anchor.js
Created January 9, 2012 15:15
Anchor - A URL parsing utility
/**
* Anchor - A URL parsing utility
*
* Copyright 2012, Matthew Cobbs
* MIT licensed
*
* Methods:
*
* getSearchVars - returns a key-value object with the parameters in the URL search
* setSearchVars(o) - sets parameters using a key-value object in the URL search
@DanBUK
DanBUK / net.Stream.setConnTimeout.hack.js
Created January 11, 2011 22:55
This hack enables node.js to handle connection timeouts.
var net = require('net');
var sys = require('sys');
// START setConnTimeout hack
net.Stream.prototype._orig_connect = net.Stream.prototype.connect;
net.Stream.prototype.connect = function () {
var self = this;
if (typeof self.conn_timeout !== 'undefined' && self.conn_timeout > 0) {
self.addListener('connect', function () {
clearTimeout(self.conn_timer);
@creationix
creationix / server.js
Created January 4, 2011 05:13
creationix.com with new node unstable https apis.s
var secure = __dirname + "/secure/";
var handler = require('stack')(
require('creationix/log')(),
require('creationix/auth')(/^\/secure\//, require(secure + "users.js")),
require('creationix/static')("/", __dirname, "index.html")
);
var read = require('fs').readFileSync;
var options = {
#!/usr/bin/env node
// requires node v0.3
// telnet.js 80 google.com
net = require('net');
a = process.argv.slice(2);
if (!a.length) {
console.error("telnet.js port [ host=localhost ]");
process.exit(1);
}
s = require('net').Stream();
@pgriess
pgriess / sendfile.js
Created September 16, 2010 20:53
Using sendfile(2) with NodeJS
var assert = require('assert');
var net = require('net');
var open = process.binding('fs').open;
var sendfile = process.binding('fs').sendfile;
if (process.argv.length < 4) {
console.error('usage: sendfile <port> <path>');
process.exit(1);
}
/*
FUSE: Filesystem in Userspace
Copyright (C) 2001-2007 Miklos Szeredi <[email protected]>
This program can be distributed under the terms of the GNU LGPLv2.
See the file COPYING.LIB.
*/
#ifndef _FUSE_LOWLEVEL_H_
#define _FUSE_LOWLEVEL_H_