Skip to content

Instantly share code, notes, and snippets.

// 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) { /*...*/ }
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);
@gurdotan
gurdotan / gist:8899480
Created February 9, 2014 13:59
MongoDB corollary of SQL's "SELECT DISTINCT ... GROUP BY"
db.events.aggregate(
{'$group' : {_id : "$platform", devices: {"$addToSet" : "$device_id"} } },
{"$unwind" : "$devices" },
{"$group" : {_id : "$_id", count: {"$sum" : 1}}}
)
var interval = setInterval(function() {
var expandPoints = $(".octicon.octicon-unfold");
expandPoints ? expandPoints.click() : clearInterval(interval);
}, 2000);
@gurdotan
gurdotan / slc-initd-example.sh
Created December 24, 2014 10:36
Node.js SLC init.d daemon script example
#!/usr/bin/env bash
#
# An example init script for running a Node.js process as a service
# using Strongloop's slc as the process monitor. For more configuration options
# associated with slc, see: http://docs.strongloop.com/display/public/SLC/slc+run.
# This script assumes you've installed slc globally with `npm install -g strongloop`.
#
# You will need to set the environment variables noted below to conform to
# your use case, and change the init info comment block.
#
@gurdotan
gurdotan / economy.json
Created December 29, 2014 09:58
Example SOOMLA economy metadata
{
"currencyPacks" : [
{
"purchasableItem" : {
"marketItem" : {
"consumable" : 1,
"price" : 1.99,
"androidId" : "com.my.game.packs.bag_of_coins",
"iosId" : "com.my.game.packs.bag_of_coins"
},
@gurdotan
gurdotan / package.json
Created March 23, 2015 10:43
Unity Package Mass Labelling script - Node.js
{
"name": "unity-mass-labeler",
"version": "0.0.1",
"description": "",
"main": "mass-labeler.js",
"dependencies": {
"lodash": "^3.5.0",
"recursive-readdir": "^1.2.0"
},
"devDependencies": {},
@gurdotan
gurdotan / gist:5b4418b9ff2be6f17a38
Last active August 29, 2015 14:18
MongoDB: Find users by creation date
db.users.find({created_at: {$gt: new ISODate('2015-03-29 00:53:55.997Z')}}).sort({_id: 1}).forEach(function(d) {
var firstName = d.name.split(/\s+/)[0];
var match = d.name.match(/.*\s+(.*)/);
var lastName = match ? match[1] : '';
print(d.email + '\t' + firstName + '\t' + lastName);
});
@gurdotan
gurdotan / gist:47e23a480348a02b754c
Created April 16, 2015 09:37
MongoDB aggregation pipeline: group by date (ISO format)
db.users.aggregate(
{
"$match": {
created_at: { $gte: ISODate("2014-09-01T00:00:00Z") }
}
},
{
"$project": {
_id: 0,
"isoDate": { $substr: [ "$created_at", 0, 10 ] }
@gurdotan
gurdotan / gist:b35600a7dcea167c12c8
Created April 22, 2015 11:18
MongoDB: most popular email domains
var emails = {};
db.users.find().sort({_id: -1}).forEach(function(d) {
var email = d.email.split('@')[1];
emails[email] |= 0;
emails[email]++;
});
var sortable = [];
for (var email in emails)
sortable.push([email, emails[email]])