Skip to content

Instantly share code, notes, and snippets.

@mikeal
mikeal / gist:2504336
Created April 27, 2012 00:11
Date parsing JSON
JSON._dateReviver = function (k,v) {
if (v.length !== 24 || typeof v !== 'string') return v
try {return new Date(v)}
catch(e) {return v}
}
JSON.parseWithDates = function (obj) {
return JSON.parse(obj, JSON._dateReviver);
}
@TooTallNate
TooTallNate / starwars.js
Created April 4, 2012 06:59
NodeJS script to play ACSII Star Wars (using a hidden cursor)
/**
* A little script to play the ACSII Star Wars, but with a hidden
* cursor, since over telnet the cursor remains visible
*/
var net = require('net')
var cursor = require('ansi')(process.stdout)
// connect to Star Wars server
@erikh
erikh / hack.sh
Created March 31, 2012 07:02 — forked from DAddYE/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@jedp
jedp / gist:1894029
Created February 23, 2012 17:54
example node.js event emitter
var util = require('util');
var events = require('events');
var redis = require('redis');
var RedisQueueConsumer = function (port, host) {
events.EventEmitter.call(this);
this.port = port || 6379;
this.host = host || '127.0.0.1';
};
// Includes functions for exporting active sheet or all sheets as JSON object (also Python object syntax compatible).
// Tweak the makePrettyJSON_ function to customize what kind of JSON to export.
var FORMAT_ONELINE = 'One-line';
var FORMAT_MULTILINE = 'Multi-line';
var FORMAT_PRETTY = 'Pretty';
var LANGUAGE_JS = 'JavaScript';
var LANGUAGE_PYTHON = 'Python';
@jfhbrook
jfhbrook / hat.js
Created February 10, 2012 20:20
Howdy, stranger. Meet broadway.
// hat.js
exports.name = 'hat';
exports.attach = function attachHat (opts) {
// This plugin *depends* on the "head" plugin being loaded.
if (!this.head) {
throw new Error('You can\'t wear a `hat` without a `head`!');
}
@3rd-Eden
3rd-Eden / remote.js
Created February 4, 2012 22:32
Uniform remote address interface for Node.js
var http = require('http')
, request = http.IncomingMessage.prototype;
/**
* Add a uniform interface for remote address in Node.js
*
* @api private
*/
request.__defineGetter__('remote', function remote () {
@tj
tj / Makefile
Created October 20, 2011 00:36
tiny bash test runner
TESTS = $(shell find test/test.*.js)
test:
@./test/run.sh $(TESTS)
.PHONY: test
@fdmanana
fdmanana / gist:832610
Created February 17, 2011 20:27
The CouchDB replicator database

1. Introduction to the replicator database

A database where you PUT/POST documents to trigger replications and you DELETE to cancel ongoing replications. These documents have exactly the same content as the JSON objects we used to POST to /_replicate/ (fields "source", "target", "create_target", "continuous", "doc_ids", "filter", "query_params".

Replication documents can have a user defined "_id". Design documents (and _local documents) added to the replicator database are ignored.

The default name of this database is _replicator. The name can be changed in the .ini configuration, section [replicator], parameter db.

2. Basics

/**
* A `tail -f` implementation in Node.js.
*
* Bratish Goswami
* bratishgoswami AT gmail DOT com
*
*/
var sys = require("sys"),
fs = require('fs'),