Skip to content

Instantly share code, notes, and snippets.

View dshaw's full-sized avatar
🦄
Always bet on Node.js ✨

Dan Shaw dshaw

🦄
Always bet on Node.js ✨
View GitHub Profile
// ----------------------------------------------------------
// A short snippet for detecting versions of IE in JavaScript
// without resorting to user-agent sniffing
// ----------------------------------------------------------
// If you're not in IE (or IE version is less than 5) then:
// ie === undefined
// If you're in IE (>=5) then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
// if (ie) {}
var sys = require("sys"),
http = require("http"),
ws = require('./deps/node-websocket-server/lib/ws'),
fs = require("fs");
var iostat = require("child_process").spawn("iostat",["-w 1"]);
var httpServer = http.createServer();
var server = ws.createServer({debug:true},httpServer);
// Format iostat date
diff --git a/lib/connect/middleware/session.js b/lib/connect/middleware/session.js
index a83cb16..7d1c17c 100644
--- a/lib/connect/middleware/session.js
+++ b/lib/connect/middleware/session.js
@@ -32,7 +32,7 @@ exports = module.exports = function sessionSetup(options){
var key = options.key || 'connect.sid';
// Default memory store
- var store = options.store || new (require('./session/memory'));
+ var store = exports.store = options.store || new (require('./session/memory'));
@rhussmann
rhussmann / SignInWithTwitter.js
Created September 6, 2010 06:05
Simple 'sign in with Twitter' implementation in node.js
var http = require('http'),
sys = require('sys'),
URL = require('url'),
querystring = require('querystring'),
OAuth = require('oauth').OAuth;
var oa = new OAuth('https://api.twitter.com/oauth/request_token',
'https://api.twitter.com/oauth/access_token',
'YOUR APP CONSUMER KEY HERE',
'YOUR APP CONSUMER SECRET HERE',
@isaacs
isaacs / node-and-npm-in-30-seconds.sh
Last active April 14, 2025 11:07
Use one of these techniques to install node and npm without having to sudo. Discussed in more detail at http://joyeur.com/2010/12/10/installing-node-and-npm/ Note: npm >=0.3 is *safer* when using sudo.
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.org/install.sh | sh
function doHash(str, seed) {
var m = 0x5bd1e995;
var r = 24;
var h = seed ^ str.length;
var length = str.length;
var currentIndex = 0;
while (length >= 4) {
var k = UInt32(str, currentIndex);
package preloadagent;
/**
Copyright 2010 Sam Pullara
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
@tj
tj / foo.js
Created October 6, 2010 17:14
function InstantiateFunction(data, name) {
// We need a reference to kApiFunctionCache in the stack frame
// if we need to bail out from a stack overflow.
var cache = kApiFunctionCache;
var serialNumber = %GetTemplateField(data, kApiSerialNumberOffset);
var isFunctionCached =
(serialNumber in cache) && (cache[serialNumber] != kUninitialized);
if (!isFunctionCached) {
try {
cache[serialNumber] = null;
// Declare an object literal as a namespace
var Utils = {};
// Define an sort of ES5 forEach (this is demo only, so it's fast and loose)
Utils.forEach = function(arr, callback) {
var iter = 0,
len = arr.length;
module.exports = function(app){
app.set('view engine', 'jade');
// etc
}