Skip to content

Instantly share code, notes, and snippets.

View jkresner's full-sized avatar

ಠ_ಠ jkresner

  • airpair, inc.
  • San Francisco
View GitHub Profile
BB = require 'badass-backbone'
M = require './models'
V = require './views'
# Inherit from BadassAppRouter to get Badass Backbone conventions
module.exports = class Router extends BB.BadassAppRouter
logging: on
pushState: off # Set off for simple example
"""
BadassRouter takes the philosophical position that only one router can be
used for one html page / single page app. It is conceptually the top most
container object other than window that contains all instances associated with the app.
"""
module.exports = class BadassRouter extends Backbone.Router
# Set logging on /off - Very dandy during dev to see flow of routes
logging: off
@jkresner
jkresner / pre-push
Last active December 17, 2015 07:29
Poor man's continuous integration to run javascript tests on every git push http://hackerpreneurialism.com/post/50386628477/poor-mans-continuous-integration-automated-node-tests
#!/bin/sh
killall node
brunch watch --server -c config-test.coffee &
mocha test/server/all.coffee
mocha-phantomjs http://localhost:3333/test/index.html
""" BadassView add 3 basic bits of functionality to a normal Backbone.View
1) Auto-logging of initialize, render & save
2) Auto setting constructor args as attributes on view instances
3) Short elm() to access an html element based on it's name attribute
"""
module.exports = class BadassView extends Backbone.View
# Set logging on /off
# Why? : During dev it's handy to see the flow your views execute in
logging: on
@jkresner
jkresner / mock-passport-middleware.coffee
Created April 19, 2013 05:47
Mocking user / session with passportJS authentication. This gist helps you test code that requires a user that has been authenticated by passport JS
module.exports =
initialize: (sessionUserObject) ->
(req, res, next) ->
passport = @
passport._key = 'passport'
passport._userProperty = 'user'
passport.serializeUser = (user, done) -> done null, user
passport.deserializeUser = (user, done) -> done null, user
@jkresner
jkresner / skills-data.coffee
Created April 13, 2013 21:55
node.js testing an express mongoose REST api with supertest
module.exports = [
{ "name": "Brunch.io", "shortName": "brunch", "soId": "brunch", "_id": "514825fa2a26ea020000000b", "__v": 0 },
{ "name": "C#", "shortName": "c#", "soId": "c#", "_id": "514825fa2a26ea020000000e", "__v": 0 } ]
@jkresner
jkresner / Procfile
Created April 13, 2013 09:05
Deploy brunch to heroku
web: ./node_modules/.bin/coffee app.coffee
@jkresner
jkresner / aTest.coffee
Created April 13, 2013 08:44
TDD nodejs, mocha, mongo, mongoose with a test database
mongoose = require 'mongoose'
wipeDbAfterTests = true
describe "Your test suite", ->
# connect to our mongo test database, note how done is passed to mongoose connect
before (done) ->
mongoose.connect "mongodb://localhost/airpair_test", done
@jkresner
jkresner / Collections.coffee
Last active December 12, 2015 04:48
Filter + PagingCollection Improved. A Filtering collection is a collection that has 2 views of it's models. (1) The original set of models and a filtered view using some custom filtering logic defined in the child collection of the base FilteringCollection class. A PagingCollection inherits from FilteringCollection and can keep track of and retu…
""" FilteringCollection
(1) Holds an original AND a filtered view of it's models
(2) Can sort filtered models on any arbitrary attribute
- sort can be invoked multiple times with different attributes to get
sorted by A then B """
class FilteringCollection extends Backbone.Collection
# Use coffee's constructor function so we can enforce initialization code +
# let the child class use the standard Backbone initialize function to
@jkresner
jkresner / after.coffee
Created January 24, 2013 17:47
Refactoring Coffee Loop: 1) Always refer to jquery elements inside of backbone views with this.$ (@$) => forces jquery to search a subset of the dom (better for bugs & speed) 2) Coffee looping is clean
render_carousel: ->
@$('.carousel-images').append('<img src="'+img.url+'">') for img in images