Skip to content

Instantly share code, notes, and snippets.

View fredsterss's full-sized avatar
🤔

Fred Stevens-Smith fredsterss

🤔
View GitHub Profile
# backbone fetch + async lib helper method, automatically routes
# the callback from success/error to the async required callback
async.fetch = (model) ->
return (callback) ->
model.fetch
success: (model, response) ->
callback null, model
@fredsterss
fredsterss / app.js
Created December 7, 2012 22:51 — forked from johnkpaul/app.js
IE9- and Backbone.history's pushState
//in your application, rather than using window.location to get the current url
App.getLocation = function(){
return window.location.protocol + '//' + window.location.host
+ '/' + Backbone.history.options.root + Backbone.history.getFragment()
}
@fredsterss
fredsterss / gist:4237171
Created December 7, 2012 22:49
Pushtate for Backbonejs hack in IE
Backbone.history.start({
pushState: Modernizr.history,
silent: true
});
if (!Modernizr.history) {
rootLength = Backbone.history.options.root.length;
fragment = window.location.pathname.substr(rootLength);
search = window.location.search;
return Backbone.history.navigate(fragment + search, {
@fredsterss
fredsterss / eg.coffee
Created August 10, 2012 08:19
KILL ALL ZOMBIES
###
Example view usage
###
# add popovers to all elements
# with the popover class, but
# don't trigger the fuckers
getSteps: () ->
# hold the steps for this test in a collection
@stepCollection = new StepCollection({ testId: @testModel.get('_id') })
# when a step is added to the collection create a new step view
@stepCollection.bind 'all', @added
# fetch the collection
checkTurk: () ->
# If the turk browser chars do not match assignment requirements, redirect
requirements = @assignmentModel.get('requirements')
if /\d/.test(requirements.browser) is true and requirements.browser != (@browser.browser + @browser.version)
# The beef is requirements does not appear in the view
new JobHoldingView({ assignmentId: @assignment, state: @state, browser: @browser, requirements: 'lol' })
@fredsterss
fredsterss / lol.coffee
Created July 6, 2012 20:20
Backbone phail
checkTurk: () ->
# If the turk browser chars do not match assignment requirements, redirect
requirements = @assignmentModel.get('requirements')
if /\d/.test(requirements.browser) is true and requirements.browser != (@browser.browser + @browser.version)
new JobHoldingView({ assignmentId: @assignment, state: @state, browser: @browser })
# or when the version is not required but the browser doesn't match
else if /\d/.test(requirements.browser) is false and requirements.browser != @browser.browser