Skip to content

Instantly share code, notes, and snippets.

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 / 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

@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 / 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) {
<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 / 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);
}
@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