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 interval = setInterval(function() { | |
var expandPoints = $(".octicon.octicon-unfold"); | |
expandPoints ? expandPoints.click() : clearInterval(interval); | |
}, 2000); |
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
db.events.aggregate( | |
{'$group' : {_id : "$platform", devices: {"$addToSet" : "$device_id"} } }, | |
{"$unwind" : "$devices" }, | |
{"$group" : {_id : "$_id", count: {"$sum" : 1}}} | |
) |
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 BackboneViewExtensions = { | |
mixin : function(from) { | |
var to = this.prototype; | |
// we add those methods which exists on `from` but not on `to` to the latter | |
_.defaults(to, from); | |
// ...and we do the same for events and triggers | |
_.defaults(to.events, from.events); |
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
// Define a router for the games sub-application | |
var GamesRouter = Backbone.Router.extend({ | |
routes: { | |
"": "root", | |
"games": "index", | |
"games/:id": "showGame" | |
}, | |
root : function() { /*...*/ }, | |
index : function() { /*...*/ }, | |
showGame : function(id) { /*...*/ } |
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
RootApp.on("switchApp", function(appName, args) { | |
// Assuming the Root app has already instantiated all sub-apps | |
// and cached the instances by their names, fetch the app instance | |
var currentApp = RootApp.getSubappInstance(appName); | |
// If the app we're switching to is the currently active one, do nothing | |
if (RootApp.currentApp === currentApp) return; | |
// Stop the previously running app. Safe-guard with `if` in case |
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 MyCollection = Backbone.Collection.extend({ | |
fetchSingle : function() { | |
if (this.currentFetch && this.currentFetch.state() === "pending") this.currentFetch.abort(); | |
this.currentFetch = this.fetch.apply(this, _.toArray(arguments)); | |
return this.currentFetch; | |
} | |
}); |
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
h = Hash[ *a.collect { |v| [ v, v ] }.flatten ] |
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 uploadFormAndFile = function(form, file) { | |
var formData = new FormData(); | |
formData.append("email", form.email); | |
formData.append("name", form.name); | |
formData.append("thumbnail", file); | |
var uploadDeferred = $.Deferred(), | |
xhr = new XMLHttpRequest(); |
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
// Based on http://www.intridea.com/blog/2011/2/8/fun-with-jquery-deferred | |
$.wait = function(time) { | |
var deferred = $.Deferred(function(dfd) { | |
setTimeout(dfd.resolve, time); | |
}); | |
// Can return susbset of Deferred object | |
// without any state mutating functionality: | |
// |
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
(function() { | |
Backbone.Model.prototype._save = Backbone.Model.prototype.save; | |
Backbone.Model.prototype.save = function(attrs, options) { | |
var that = this; | |
if (!options) { options = {}; } | |
if (this.savingNewRecord) { | |
// store or replace last PUT request with the latest version, we can safely replace old PUT requests with new ones | |
// but if there are callbacks from a previous PUT request, we need to make sure they are all called as well | |
_(['success','error']).each(function(event) { | |
// convert all callbacks to a single array of callbacks) |