Skip to content

Instantly share code, notes, and snippets.

@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}}}
)
@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]])
@gurdotan
gurdotan / gist:1219199
Created September 15, 2011 13:19
git-diffall installation
cd ~
mkdir tools
cd tools
git clone https://github.com/thenigan/git-diffall.git
sudo ln -s ~/tools/git-diffall/git-diffall /usr/bin/git-diffall
@gurdotan
gurdotan / gist:1661805
Created January 23, 2012 08:40
SSH history autocomplete
complete -W "$(echo $(grep '^ssh ' ~/.bash_history | sort -u | sed 's/^ssh //'))" ssh
@gurdotan
gurdotan / gist:3986841
Created October 31, 2012 12:42
Backbone View event bubbling
_.extend(Backbone.View.prototype, {
bubbleEventsTo : function(targetView) {
this.on("all", function() {
Backbone.View.prototype.trigger.apply(targetView, arguments);
});
return this;
})
(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)