View gist:841656
# How we store all time views across the entire system for
# All in one document that gets incremented using MongoDB $inc modifier in
# every track. The $inc increments t, year.t, year.month.t,
# so we get to the day numbers. These are in EST, as we are in EST and these
# stats are just for us. :) Nothing amazing, but thought I would share.
# >> pp View.all_time
"_id" => "all_time",
"t" => 502352,
View gist:833256
Why You Should Never Use An ORM
Having built two object mappers in Ruby (MongoMapper and ToyStore), I would like to
throw out a crazy thought. What if, on your next project, you ditch the ORM.
No ActiveRecord. No DataMapper. No anything. Just you and a lower level driver, whispering
sweet nothings into Ruby classes and modules. Could you? Would you? DARE you?
We Rubyists are all about aesthetics, right? We love declaring has_many and belongs_to!
Scope this! Boom! Instant magic happens behind the scenes. Fancy proxies are assembled,
View zlib_mongo_grid.rb
require 'pp'
require 'zlib'
require 'benchmark'
require 'rubygems'
require 'active_support/gzip'
require 'mongo_mapper'
MongoMapper.database = 'testing'
View example.rb
# gem install sunspot_rails
class Foo
include MongoMapper::Document
include Sunspot::Rails::Searchable
key :title, String
searchable do
text :title
View map_reduce.rb
module PageViewsByMonth
def map
function() {…}
def reduce
function() {…}
View gist:468109
function __git_dirty {
git diff --quiet HEAD &>/dev/null
[ $? == 1 ] && echo "!"
function __git_branch {
__git_ps1 "(%s)"
function __my_rvm_ruby_version {
function parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
PS1="$RED\$(date +%H:%M) \w$YELLOW \$(parse_git_branch)$GREEN\$ "
View atomic_embedded_pull.rb
require 'pp'
require 'rubygems'
require 'mongo_mapper'
MongoMapper.database = 'testing'
class Comment
include MongoMapper::EmbeddedDocument
View gist:412580
# I need class C to call the foo method for each module included
# that has the method foo. Order does not matter as much as each
# method getting called. alias method chain?
module A
def foo
puts 'a'
View stylesheet.rb
class Stylesheet
include MongoMapper::Document
class Processor
def self.errors
attr_reader :contents