Skip to content

Instantly share code, notes, and snippets.

View tanepiper's full-sized avatar

Tane Piper tanepiper

View GitHub Profile
@tanepiper
tanepiper / gist:943476
Created April 27, 2011 00:22 — forked from catalogchoice/gist:934418
coffeescript name space
namespace = (target, name, block) ->
[target, name, block] = [(if typeof exports isnt 'undefined' then exports else window), arguments...] if arguments.length < 3
top = target
target = target[item] or= {} for item in name.split '.'
block target, top
@tanepiper
tanepiper / singleton.coffee
Created May 19, 2011 08:55 — forked from meltingice/singleton.coffee
Example singleton class and example for Coffeescript
class Singleton
# We can make private variables!
instance = null
# Static singleton retriever/loader
@get: ->
if not @instance?
instance = new @
instance.init()
@tanepiper
tanepiper / README.md
Created May 25, 2011 12:54 — forked from bergie/README.md
Falsy Values tutorials
@tanepiper
tanepiper / editor.js
Created May 31, 2011 14:19 — forked from Floby/editor.js
open the default editor from node
var fs = require('fs');
var child_process = require('child_process');
var spawn = child_process.spawn;
function openEditor(file) {
var cp = spawn(process.env.EDITOR, [file], {
customFds: [
process.stdin,
process.stdout,
process.stderr
@tanepiper
tanepiper / console.log.js
Created July 12, 2011 07:24 — forked from tmpvar/.gitignore
A console.log implementation that plays "nice" with large amounts of data. Keeps node alive until the output has flushed to screen.
/*
A console.log that won't leave you hanging when node exits
*/
console.log = function(d) {
var res = process.stdout.write(d + '\n');
// this is the first time stdout got backed up
if (!res && !process.stdout.pendingWrite) {
process.stdout.pendingWrite = true;
@tanepiper
tanepiper / jquery.extend.js
Created August 3, 2011 21:11 — forked from FGRibreau/jquery.extend.js
jQuery extend for NodeJS / Object & Array Deep Copy for NodeJS
/*
jQuery.extend extracted from the jQuery source & optimised for NodeJS
Twitter: @FGRibreau / fgribreau.com
Usage:
var Extend = require('./Extend');
// Extend
var obj = Extend({opt1:true, opt2:true}, {opt1:false});
[
{
id: 1,
category_id: 1,
merchant: {
id: 1,
title: 'BobsResturant',
address: 'Edinburgh',
telephone: '01311000011',
latitude: 55.946312,
@tanepiper
tanepiper / dnode-auth.js
Created December 8, 2011 23:09 — forked from sorensen/custom-dnode-session.js
Mongoose Authentication
// Authentication middleware
// -------------------------
// Shim for DNode's current version of socket.io,
// which cannot pass `null` references, and turning
// the mongoose model to a pure JSON object
function shim(err, doc, fn) {
if (!err) err = 0
if (doc) doc = JSON.parse(JSON.stringify(doc))
@tanepiper
tanepiper / custom-dnode-session.js
Created December 10, 2011 13:50 — forked from sorensen/custom-dnode-session.js
DNode/Express Mongoose Authentication
// DNode Session
// =============
var connect = require('connect')
module.exports = function(opt) {
var key = opt.key || 'connect.sid'
, store = opt.store
, interval = opt.interval || 120000
@tanepiper
tanepiper / ms.js
Created December 21, 2011 00:45 — forked from rauchg/ms.md
/**
# ms.js
No more painful `setTimeout(60 * 4 * 3 * 2 * 1 * Infinity * NaN * '☃')`.
ms('2d') // 172800000
ms('1.5h') // 5400000
ms('1h') // 3600000
ms('1m') // 60000