Skip to content

Instantly share code, notes, and snippets.

View searls's full-sized avatar
💚

Justin Searls searls

💚
View GitHub Profile
@searls
searls / server.md
Created January 18, 2012 21:54
Sprocket's hack to

Just take this source from sprockets' server.rb:

          if attributes_for(env["PATH_INFO"]).path_fingerprint
            headers["Cache-Control"] << ", max-age=31536000"

          # Otherwise set `must-revalidate` since the asset could be modified.
          else
            headers["Cache-Control"] << ", must-revalidate"
 end
describe "app.Agent", ->
Given -> @car = new Backbone.Model
Given -> spyOn(@car, "get")
Given -> @car.get.when('phone').thenReturn("123-456-789")
Given -> @car.get.when('name').thenReturn("juice")
Then -> expect(@car.get).toHaveBeenCalledWith('phone')
Then -> expect(@car.get).toHaveBeenCalledWith(jasmine.any(String))
Then -> expect(@car.get).toHaveBeenCalledWith jasmine.argThat (arg) ->
arg.length < 5
window.mapRelations = (model,doThis,exclusions=[]) ->
result = doThis.call(model,model)
exclusions.push(model)
if model instanceof Backbone.RelationalModel && !model.isLocked()
model.acquire()
_(model.getRelations()).each (relation) =>
related = relation.related
unless _(exclusions).include(related)
if related instanceof Backbone.Collection
result[relation.key] = []
@searls
searls / profile.js
Created January 25, 2012 14:56
just used this for profiling jasmine specs (trying to isolate slow specs)
//outside of any describe() block so they run for every single spec.
beforeEach(function() {
window.timings = window.timings || []
timings.push({
startTime: new Date(),
spec: this
});
});
afterEach(function() {
describe "AirDrop", ->
describe "including source", ->
context "with packaging", ->
context "with individual paths", ->
Given -> drop = AirDrop("drop").include("spec/fixtures/includes/b.js").include("spec/fixtures/includes/a.js").package()
context "files in order", ->
Then -> expectSourceToMatchFile drop, "#{__dirname}/fixtures/packaged/ba.js"
context "files included twice", ->
class SerializableView extends Backbone.View
render: (layout) ->
if layout
layout(@).render(@serialize?() or @serialize).then =>
_.defer => @trigger('rendered')
else
$(@el).html(JST[@template](@serialize?() or @serialize))
@trigger('rendered')
@
Running Jasmine specs...
.........................F..............................F......................................................................................................................................................................................................................FFFF..................F.....................................................................F...FF........FF....F..FF.FF.............................................F..........................FF.................................................................
FAIL: 530 tests, 20 failures, 0.934 secs.
difference = (left, right) ->
leftDifference = {}
rightDifference = {}
result = [leftDifference,rightDifference]
_(left).each (leftVal,key) ->
rightVal = right[key]
if rightVal != leftVal
leftDifference[key] = leftVal
rightDifference[key] = rightVal
result
data =
a: 0
b: "foo"
result = _(data).reject((v,k) -> k == 'b')
expect(result).toEqual(a: 0) #but fail! it returns: [0]
@searls
searls / undermore.coffee
Created February 1, 2012 23:58
object without properties
_.mixin
withoutProperties: (object,failTest) ->
newObj = _(object).clone()
_(object).each (val,key) ->
delete newObj[key] if failTest(val,key) == true
newObj