This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Usage: | |
// $(context).delegate(selector,eventType[,eventData],handler); | |
// $(context).undelegate(selector[,eventType][,handler]); | |
jQuery.each({ delegate : "live", undelegate : "die" }, function(k, v) { | |
jQuery.fn[k] = function() { | |
var sel = Array.prototype.shift.apply(arguments), args = arguments; | |
return this.each(function() { | |
$.fn[v].apply($({ selector : sel, context : this }), args); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// using node v0.2.4 | |
var sys = require('sys'), | |
events = require('events'); | |
// create a custom EventEmitter | |
function CustomEmitter() { | |
// call "super" constructor | |
events.EventEmitter.call(this); | |
} | |
// inherit from EventEmitter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// dummy func | |
function noop() {} | |
// optimized via if/else | |
function testIfElse() { | |
var len = arguments.length; | |
if (len === 1) { | |
noop(arguments[0]); | |
} else if (len === 2) { | |
noop(arguments[1]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _parsedUrl; | |
Object.defineProperty(req, 'parsedUrl', { | |
get: function() { | |
if (!_parsedUrl) { | |
_parsedUrl = url.parse(req.url, true); | |
} | |
return _parsedUrl; | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
How do we provide more descriptive error messages for max-recursion situations? | |
*/ | |
var depth = 0; | |
(function recurseBaby() { | |
// log at every 500 calls | |
(++depth % 500) || console.log(depth); | |
// bail out ~100K depth in case you're special and don't error out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'), | |
mongoose = require('mongoose'), | |
Model = require('./lib/model'), | |
Tap = Model.Tap; | |
app.post('/tap', function(req, res, next) { | |
var tap = new Tap(); | |
tap.name = req.body.name; | |
tap.beer = req.body.beer; | |
tap.update({ name: tap.name }, { upsert: true }, function(err) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('silent error', function() { | |
/* | |
// ReferenceError bubbles up just fine | |
before(function() { | |
assert('foo'); | |
}); | |
*/ | |
/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.PHONY: clean install test test-tap test-api | |
clean: | |
rm ./test/results.tap | |
install: | |
npm install | |
test: | |
mocha -R list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jmar777:gaas-license-verification jeremymartin$ jitsu create | |
info: Welcome to Nodejitsu | |
info: It worked if it ends with Nodejitsu ok | |
info: Executing command create | |
info: Authenticated as jmar777 | |
warn: | |
warn: Your package.json file is missing required fields: | |
warn: | |
warn: scripts.start | |
warn: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jmar777:gaas-license-verification jeremymartin$ jitsu deploy | |
info: Welcome to Nodejitsu | |
info: It worked if it ends with Nodejitsu ok | |
info: Executing command deploy | |
info: Authenticated as jmar777 | |
info: Analyzing your application dependencies in app.js | |
warn: Local version appears to be old. | |
warn: Your package.json version will be incremented for you automatically. | |
warn: About to write /Users/jeremymartin/Projects/gaas-license-verification/package.json | |
data: |
OlderNewer