Skip to content

Instantly share code, notes, and snippets.

@logicalparadox
logicalparadox / Backbone.sync.js
Created September 2, 2011 00:07
Backbone.sync drop in replacement to use socket.io for CRUD operations
// Updated version included in: https://github.com/logicalparadox/backbone.iobind
@logicalparadox
logicalparadox / spy.js
Created December 6, 2011 01:18
Tiny javascript spy for testing.
function Spy (fn) {
if (!fn) fn = function() {};
function proxy() {
var args = Array.prototype.slice.call(arguments);
proxy.calls.push(args);
proxy.called = true;
fn.apply(this, args);
}
<html>
<head>
<title>Swarm Javascript Library Specifications</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" charset="utf-8"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"
type="text/javascript"
charset="utf-8">
</script>
<script src="../node_modules/mocha/mocha.js"
@logicalparadox
logicalparadox / templates.js
Created December 28, 2011 22:53
Compile a folder of jade templates for client side use.
var folio = require('folio')
, katu = require('katu')
, jade = require('jade')
, fs = require('fs')
, path = require('path');
var paths = []
, basepath = path.join(__dirname, '..', '..', 'src', 'templates')
var getFiles = function (p) {
@logicalparadox
logicalparadox / getPath.js
Created January 3, 2012 19:52
Get deep value in object using a stringed path.
var obj = {
a: {
b: 'testB'
}
, c: 'testC'
, d: [
{ e: 'world' }
]
};
@logicalparadox
logicalparadox / About.md
Created January 8, 2012 07:01
Designing `loggable` custom error constructors for Node.js.

Custom Errors

I am working on a custom error constructor for my seed project. I had a few objectives in mind when I started.

  • When in production, these errors need to be able to be serialized for logging.
  • When in development, I can easily throw these errors should I need additional feedback on to what is going on.
  • Any addon plugins made can use or extend the custom error type and still satisfy the first two objective with ease.

Screenshot

Stability ratings: 0-5
0 - Deprecated. This feature is known to be problematic, and changes are
planned. Do not rely on it. Use of the feature may cause warnings. Backwards
compatibility should not be expected.
1 - Experimental. This feature was introduced recently, and may change
or be removed in future versions. Please try it out and provide feedback.
If it addresses a use-case that is important to you, tell the node core team.
@logicalparadox
logicalparadox / config-index.js
Created March 17, 2012 17:53
Load env config
var env = process.env.NODE_ENV || 'development';
var config = {
development: {}
, test: {}
, staging: {}
@logicalparadox
logicalparadox / iptables.rules
Created March 20, 2012 23:44
Getting Node.js process to run on port 80 without sudo
# NAT interface routing
*nat
# Setup
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [2:128]
:OUTPUT ACCEPT [2:120]
:POSTROUTING ACCEPT [2:120]
# Redirect port 80 to port 8080
@logicalparadox
logicalparadox / gist:2331533
Created April 7, 2012 19:26 — forked from indexzero/gist:2331488
safe .toJSON()
function toString (obj) {
function _toString (i) {
if (obj[i] === null) return 'null'
if (typeof obj[i] === 'undefined') return 'undefined'
if (obj[i].toString) return obj[i].toString()
else return ''
}
return _toString
}