- You can only validate for presence if the property is null, blank ('') is a value
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
applyExtra = (Batman) -> | |
Batman.mixin Batman.Encoders, | |
railsDate: | |
encode: (value) -> value | |
decode: (value) -> | |
a = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value) | |
if a | |
return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4], +a[5], +a[6])) | |
else | |
Batman.developer.warn "Unrecognized rails date #{value}!" |
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
class User extends Batman.Model | |
@accessor 'age', set: (k, v) -> | |
@set('age', +v) #=> Will cause infinite loop | |
@[k] = v #=> Use this instead |
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 tar = require('tar-async'), | |
streamBuffers = require('stream-buffers'), | |
fs = require('fs'), | |
zlib = require('zlib'); | |
var myWritableStreamBuffer = new streamBuffers.WritableStreamBuffer({ | |
initialSize: (100 * 1024), // start as 100 kilobytes. | |
incrementAmount: (10 * 1024) // grow by 10 kilobytes each time buffer overflows. | |
}); |
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 Connection, Db, Server, build, exec, fixtures, fs, print, spawn, _ref, _ref2; | |
_ref2 = require('mongodb'), Db = _ref2.Db, Connection = _ref2.Connection, Server = _ref2.Server; | |
_ = require('underscore'); | |
util = require('util'); | |
traverse = require('traverse'); | |
var the_db = new Db('geowars', new Server("localhost", 27017, {})); | |
var translations = { | |
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
if isNaN Date.parse "2011-01-01T12:00:00-05:00" | |
Date.parse = ((parse) -> | |
# The date time string format as specified by ES 5.1 section 15.9.1.15. | |
pattern = ///^ | |
(\d{4}) # Year | |
(?:-(\d{2}) # Optional month | |
(?:-(\d{2}) # Optional date | |
(?: # Optional time component | |
T(\d{2}) # Hours | |
:(\d{2}) # Minutes |
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
UserHuntInfo.getMonstersInRange = function(latitude, longitude, range, placedMonsters) { | |
checkTypes(arguments, "number", "number", "number", Array); | |
return placedMonsters.filter(function(monster) { | |
return distanceOverEarth(latitude, longitude, monster.latitude, monster.longitude) <= (range/1000); | |
}); | |
}; | |
// vs | |
UserHuntInfo.getMonstersInRange = function(latitude, longitude, range, placedMonsters) |
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
zmv '(*.mkv)' '${(U)1:r}.${(L)1:e}' # current directory only | |
zmv '(**/)(*.mkv)' '$1${(U)2:r}.${(L)2:e}' # recursive traversal |
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
# Needs | |
# http://crypto-js.googlecode.com/files/2.3.0-crypto-sha256-hmac.js | |
pad = (n) -> if n < 10 then "0" + n else n | |
# Sat, 08 Oct 2011 16:55:39 GMT | |
timestamp = () -> | |
now = new Date() | |
year = now.getUTCFullYear() | |
month = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][now.getUTCMonth()] | |
dow = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'][now.getUTCDay()] |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Canvastest</title> | |
<meta http-equiv="X-UA-Compatible" content="IE=Edge" /> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script> | |
<script type="text/javascript" src="../lib/es5-shim.js"></script> | |
<script type="text/javascript" src="../lib/batman.js"></script> | |
<script type="text/javascript" src="../lib/batman.solo.js"></script> | |
<script type="text/javascript" src="../lib/coffee-script.js"></script> |