Skip to content

Instantly share code, notes, and snippets.

View thurloat's full-sized avatar

Adam Thurlow thurloat

View GitHub Profile
@thurloat
thurloat / ops.coffee
Created January 11, 2013 19:17
yawwwn
ops =
"=": (l,r) -> l is r
">": (l,r) -> l > r
"<": (l,r) -> l < r
">=": (l,r) -> l >= r
"<=": (l,r) -> l <= r
"<>": (l,r) -> l <> r
"is null": (l) -> l is null
"is not null": (l) -> l is not null
if sort? and (sort.get "items").length > 0
parts = for item in (sort.get "items")
dir = if item[0] == "-"? then "DESC" else "ASC"
"#{ if dir == "ASC" then item else item.slice 1 } #{ dir }"
sql += " ORDER BY #{ parts.join ", " }"
@thurloat
thurloat / jasmine-async.coffee
Created December 3, 2012 23:33
jasmine-async.coffee
@asyncIt = (desc, test) ->
spec = jasmine.getEnv().it desc
__spy = new sinon.spy
__done = no
_NATIVE_ERR = window.onerror
spec.runs ->
@thurloat
thurloat / shade.css
Created November 29, 2012 21:41
less shade
body {
background: #808080;
background: #333333;
background: #b3b3b3;
background: #2b2b2b;
}
@thurloat
thurloat / jasmine.asynctest.coffee
Created November 19, 2012 20:12
Jasmine Asynchronous Spec Functionality
@withAppIt = (desc, test) ->
spec = jasmine.getEnv().it desc
__app = null
__spy = new sinon.spy
__done = no
_NATIVE_ERR = window.onerror
# Perform the regular cleanup after a TestApplication test gets run. Restore
# ajax, and reset the DB.
@thurloat
thurloat / example.java
Created April 27, 2012 17:08
Jackson JSON ignore on deserialize only
package com.thurloat.foo;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonProperty;
/**
* In order to write a composite data property (stats) out to JSON without reading
* it back in, you need to explicitly ignore the property, as well as the setter and
* then apply the @JsonProperty annotation to the getter.
**/
@thurloat
thurloat / runtime.coffee
Created April 12, 2012 20:10
Hardcore Coffeescript
class @SyncView
for season in ["spring", "summer", "fall", "winter"]
for field in ["title", "story"]
fieldPropertyName = season + field.charAt(0).toUpperCase() + field.substr(1)
pName = "#{ fieldPropertyName }ToModel"
TrendFormView.prototype[pName] = _.bind (s, f) ->
@seasonFieldToModel s, f
, TrendFormView.prototype, season, field
@thurloat
thurloat / BackboneViewFactory.js
Created February 7, 2012 16:25 — forked from anonymous/Backbone ViewFactory
Backbone ViewFactory
var ViewFactory = (function() {
function ViewFactory(pubSub) {
this.pubSub = pubSub;
this.registry = {};
this.registry['factory'] = this;
}
ViewFactory.prototype.register = function(key, value) {
return this.registry[key] = value;
@thurloat
thurloat / qa.coffee
Created February 6, 2012 13:23 — forked from honza/qa.coffee
Quicksort in Haskell & Python
qs = (arr) ->
[].concat qs(i for i in arr when i < arr[0]), [arr[0]], qs(i for i in arr when i > arr[0]) if arr.length <= 1 else arr
@thurloat
thurloat / ModularView.coffee
Created January 22, 2012 02:17
Modular Coffeescript Views using Observer
# All of your views should inherit from the BaseView. As a result you get the
# globalEvents functionality for free. The globalEvents hash is similar to that
# of the built-in Backbone events hash. It automatically binds event names to
# instance methods.
#
# class TestView extends ModularView
#
# globalEvents:
# "PhoneRang": "answerPhone"
#