Skip to content

Instantly share code, notes, and snippets.

View andrewmp1's full-sized avatar

Drew Purdy andrewmp1

View GitHub Profile
@mindscratch
mindscratch / mongoid_id_monkey_patch.rb
Created August 15, 2011 09:24
Mongoid: return 'id' instead of '_id' when serializing documents as JSON
module Mongoid
module Document
def as_json(options={})
attrs = super options
attrs["id"] = attrs.delete "_id" if attrs.has_key? "_id"
attrs
end
end
end
@madhums
madhums / mapreduce.js
Created August 3, 2011 20:33
mapreduce using mongodb and mongoose
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/db_name');
// map function
var map = function(){
emit(this.field_to_group_by, {
other_fields: this.other_fields
// list other fields like above to select them
})
}
@dhh
dhh / gist:1014971
Created June 8, 2011 18:09
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
// ----------------------------------------------------------
// A short snippet for detecting versions of IE in JavaScript
// without resorting to user-agent sniffing
// ----------------------------------------------------------
// If you're not in IE (or IE version is less than 5) then:
// ie === undefined
// If you're in IE (>=5) then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
// if (ie) {}
@BDQ
BDQ / Import
Created December 3, 2008 21:37
namespace :spree do
desc "Export Products to CSV File"
task :export_products => :environment do
require 'fastercsv'
products = Product.find(:all)
puts "Exporting to #{RAILS_ROOT}/products.csv"
FasterCSV.open("#{RAILS_ROOT}/products.csv", "w") do |csv|
csv << ["id", "name", "description","sku", "master_price" ]