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
process.env.NODE_ENV = 'test' unless process.env.NODE_ENV? | |
sys = require "sys" | |
_ = require "underscore" | |
dir = "jasmine-node/lib/jasmine-node/" | |
filename = "jasmine-2.0.0.rc1" | |
# Copy 'it', 'describe',... to global | |
for key, value of require("#{dir}#{filename}") |
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
withSerializedSync = function(cls) { | |
var sync = cls.prototype.sync || Backbone.sync; | |
cls.prototype.sync = function() { | |
var args = arguments.length ? Array.prototype.slice.call(arguments,0) : []; | |
if (!this._lastSync) { | |
this._lastSync = sync.apply(this, args); | |
} else { | |
var _this = this; | |
this._lastSync = this._lastSync.then(function() { | |
return sync.apply(_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
isoDateRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/ | |
isIsoDate = (value) -> | |
return value unless typeof(value) is 'string' | |
isoDateRegex.test(value) | |
isIsoDateOptimized = (value) -> | |
return value unless typeof(value) is 'string' | |
return value unless value.length is 24 |
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
export MARKPATH=$HOME/.marks | |
function jump { | |
cd -P "$MARKPATH/$1" 2>/dev/null || echo "No such mark: $1" | |
} | |
function mark { | |
mkdir -p "$MARKPATH"; ln -s "$(pwd)" "$MARKPATH/$1" | |
} | |
function unmark { | |
rm -i "$MARKPATH/$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
Set mixed { '0': { name: 'Foo' }, | |
'1': | |
{ path: 'mixed', | |
instance: undefined, | |
validators: [], | |
setters: [ [Function] ], | |
getters: [], | |
options: { type: [Function: Mixed] }, | |
_index: null } } | |
Set mixed { '0': 'Bar', |
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 MyModel = Backbone.Model.extend({}); | |
withSerializedSync(MyModel); |
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
#!/usr/bin/env node | |
var vm = require('vm'); | |
var repl = require('repl'); | |
var CoffeeScript = require('coffee-script'); | |
repl.start({ | |
prompt: "coffee> ", | |
eval: function(code, context, file, cb) { | |
try { |
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
$ node fibrous_repl.js | |
Starting fibrous REPL... | |
> var fs = require('fs'); | |
undefined | |
> data = fs.sync.readFile('/etc/passwd', 'utf-8'); | |
... | |
> console.log(data); | |
## | |
# User Database | |
# |
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 vm = require('vm'); | |
var repl = require('repl'); | |
var fibrous = require('fibrous'); | |
console.log("Starting fibrous REPL..."); | |
repl.start({ | |
eval: fibrous(function(code, context, file) { | |
return vm.runInContext(code, context, file); | |
}) | |
}); |
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 mongoose = require('mongoose') | |
var mongoUrl = "mongodb://localhost:27017/test" | |
var connectWithRetry = function() { | |
return mongoose.connect(mongoUrl, function(err) { | |
if (err) { | |
console.error('Failed to connect to mongo on startup - retrying in 5 sec', err); | |
setTimeout(connectWithRetry, 5000); | |
} | |
}); |
NewerOlder