Skip to content

Instantly share code, notes, and snippets.

View gautamrege's full-sized avatar

Gautam Rege gautamrege

View GitHub Profile
@gautamrege
gautamrege / gist:725020
Created December 2, 2010 09:14
VIM - presentation. Most frequently uses VIM shortcuts.
1. Why use VIM?
VIM rocks!
VI or VIM?
I hate the mouse!
I am a text person
I love touch-typing (huh - what is touch typing% again..)
You have production server with only SSH access!
2. Vim -- you already knew
Command mode & Insert mode
@gautamrege
gautamrege / Redis_Pubsub_Client.rb
Created December 31, 2010 13:07
Redis Pubsub Client with event persistence
require 'redis'
require 'multi_json'
class PubSubRedis < Redis
def initialize(options = {})
@timestamp = options[:timestamp].to_i || 0 # 0 means -- no backlog needed
super
end
@gautamrege
gautamrege / 01_frozen_scope.rb
Created October 18, 2011 07:41
Frozen values in scope and chained scopes
=begin
'frozen' value for end_at in scope :active
The same frozen value is propogated to :national scope!
The Time.now will be set to the first time the scope is evaluated.
This is explained at http://api.rubyonrails.org/classes/ActiveRecord/NamedScope/ClassMethods.html
* NON-WORKING SOLUTION *
=end
class Something
@gautamrege
gautamrege / notify.js
Created January 28, 2012 14:43
Notification node server
var express = require('express')
, app = express.createServer()
, io = require('socket.io').listen(app);
app.use(express.bodyParser());
app.listen(13002);
var connections = {}
@gautamrege
gautamrege / module.rb
Created May 24, 2012 13:57
Cherry picking Modules
module A
def foo
puts "A:foo"
end
end
module B
def foo
puts "B:foo"
end
@gautamrege
gautamrege / ruby_iteration
Created March 26, 2013 17:50
Ruby iteration
Started POST "/reports/distributor" for 127.0.0.1 at 2013-03-19 15:02:16 +0530
Processing by ReportsController#distributor as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"0auleqI26KHq7LL373WpzslaGJWy45LMhnPeEpWedoc=", "search"=>{"project_id"=>"5139f91fb9b67dbe3a000004", "distributor_id"=>"", "start_date"=>"01/03/2013 - 00:00 AM", "end_date"=>"20/03/2013 - 23:59 PM"}, "commit"=>"Search"}
MOPED: 127.0.0.1:27017 COMMAND database=admin command={:ismaster=>1} (0.5579ms)
MOPED: 127.0.0.1:27017 QUERY database=phalcomm_production collection=users selector={"$query"=>{"_id"=>"513f0f9db9b67d884a000002"}, "$orderby"=>{:_id=>1}} flags=[] limit=-1 skip=0 batch_size=nil fields=nil (0.4704ms)
MOPED: 127.0.0.1:27017 QUERY database=phalcom
@gautamrege
gautamrege / mapreduce
Created March 26, 2013 18:03
Map Re-reduce
Started POST "/reports/distributor" for 127.0.0.1 at 2013-03-19 20:28:49 +0530
Processing by ReportsController#distributor as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"0auleqI26KHq7LL373WpzslaGJWy45LMhnPeEpWedoc=", "search"=>{"project_id"=>"5139f91fb9b67dbe3a000004", "distributor_id"=>"", "start_date"=>"07/03/2013 - 00:00 AM", "end_date"=>"19/03/2013 - 23:59 PM"}, "commit"=>"Search"}
MOPED: 127.0.0.1:27017 COMMAND database=admin command={:ismaster=>1} (0.7286ms)
MOPED: 127.0.0.1:27017 QUERY database=phalcomm_production collection=users selector={"$query"=>{"_id"=>"513f0f9db9b67d884a000002"}, "$orderby"=>{:_id=>1}} flags=[] limit=-1 skip=0 batch_size=nil fields=nil (0.5398ms)
MOPED: 127.0.0.1:27017 QUERY database=phalcomm_production collection=organisations selector={"$query"=>{"_id"=>"5139f184b9b67d8e73000001"}, "$orderby"=>{:_id=>1}} flags=[] limit=-1 skip=0 batch_size=nil fields=nil (0.4199ms)
MOPED: 127.0.0.1:27017 QUERY database=phalcomm_production collectio
@gautamrege
gautamrege / map_rereduce.js
Last active December 15, 2015 13:39
Map ReReduce and join example
map = function() {
if (this.is_cancelled == false) {
data = { bookings: [ this._id ],
booking_amount: this.booking_amount,
amt_received: 0,
cancellations: 0
}
} else {
data = { bookings: [],
booking_amount: 0,
@gautamrege
gautamrege / general_entity.rb
Created July 30, 2013 06:25
Mongodb Text index search
class GeneralEntity
include Mongoid::Document
extend Moped::Search # to enable facetted text index search
field :org_name, type: String
# other fields
embeds_one :contact, as: :contactable
index({"contact.state" => 1, # filter with text index
@gautamrege
gautamrege / address.rb
Created October 31, 2013 02:51
Saving Embedded document with :name option
class Address
include Mongoid::Document
field :street, type: String
field :city, type: String
field :state, type: String
field :zipcode, type: String
field :country, type: String
embedded_in :author, name: :permanent_address