Skip to content

Instantly share code, notes, and snippets.

View jhurliman's full-sized avatar
🐨

John Hurliman jhurliman

🐨
View GitHub Profile
@jhurliman
jhurliman / gist:1303191
Created October 21, 2011 05:53
Add a custom timeout to FB.getLoginStatus()
/* Add this somewhere after FB.init() and before any calls to FB.getLoginStatus() */
// Add a timeout to FB.getLoginStatus()
var FB_STATUS_TIMEOUT = 1000 * 30;
var origGetLoginStatus = FB.getLoginStatus;
FB.getLoginStatus = function(callback, force) {
// Start a timer
var timedOut = false;
var timeout = setTimeout(function() {
timedOut = true;
@jhurliman
jhurliman / gist:1271679
Created October 8, 2011 00:33
lockedStore.js
LockedStore = function() { };
LockedStore.prototype = {
table: [],
/**
* index - Index of the value to check out.
* callback(value, fn) - Fired when a lock is acquired on the requested value. First
* parameter is the requested value, second parameter is a callback that must be
* fired to check the value back in and expects the new value as a single parameter.
@jhurliman
jhurliman / base64.js
Created September 29, 2011 06:39 — forked from Marak/base64.js
An extremely simple implementation of base64 encoding / decoding using node.js Buffers (plus url-safe versions)
/*
* base64.js: An extremely simple implementation of base64 encoding / decoding using node.js Buffers
*
* (C) 2010, Nodejitsu Inc.
* (C) 2011, Cull TV, Inc.
*
*/
var base64 = exports;
@jhurliman
jhurliman / express-error-handling.js
Created September 28, 2011 07:47
Basic error handling in Express
app.configure(function() {
// Setup a socket error handler for all requests
app.use(socketErrorHandler);
// Catch any attempts to call res.send multiple times for the same client
app.use(onlyOneResponse);
});
function socketErrorHandler(req, res, next) {
// Check if this socket is being reused and already has an error handler
if (!req.socket.listeners('error').length) {
@jhurliman
jhurliman / gist:1107975
Created July 26, 2011 20:49
node.js request statusCode
var status = res ? res.statusCode : (err && err.length === 3) ? err : '-1';
function clientIP(req)
{
if (config.using_proxy) {
var forwardedFor = req.headers['x-forwarded-for'];
return forwardedFor ? forwardedFor : req.connection.remoteAddress;
}
return req.connection.remoteAddress;
}
// Load the Facebook API
window.fbAsyncInit = function() {
FB.init({
appId : 'YOUR_APP_ID',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
// Browser-specific hacks to make FB Connect more reliable