This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module PageViewsByMonth | |
def map | |
<<-MAP | |
function() {…} | |
MAP | |
end | |
def reduce | |
<<-REDUCE | |
function() {…} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function __git_dirty { | |
git diff --quiet HEAD &>/dev/null | |
[ $? == 1 ] && echo "!" | |
} | |
function __git_branch { | |
__git_ps1 "(%s)" | |
} | |
function __my_rvm_ruby_version { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function parse_git_branch() { | |
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' | |
} | |
RED="\[\033[0;31m\]" | |
YELLOW="\[\033[0;33m\]" | |
GREEN="\[\033[0;32m\]" | |
PS1="$RED\$(date +%H:%M) \w$YELLOW \$(parse_git_branch)$GREEN\$ " |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pp' | |
require 'rubygems' | |
require 'mongo_mapper' | |
MongoMapper.database = 'testing' | |
class Comment | |
include MongoMapper::EmbeddedDocument | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
super | |
puts 'a' | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Stylesheet | |
include MongoMapper::Document | |
class Processor | |
def self.errors | |
[] | |
end | |
attr_reader :contents |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ValidatesExistenceOfPlugin | |
def self.included(model) | |
model.plugin ValidatesExistenceOfPlugin | |
end | |
module ClassMethods | |
def validates_existence_of(*args) | |
add_validations(args, ValidatesExistenceOfPlugin::ValidatesExistenceOf) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Patch until MM 0.7.6 which fixes this: | |
# http://github.com/jnunemaker/mongomapper/commit/a721b66d9bc9ef78a5ce32dd2eb36d24abd4b953 | |
module SetWithTypecasting | |
def self.included(model) | |
model.plugin SetWithTypecasting | |
end | |
module ClassMethods | |
def set(*args) | |
criteria, updates = criteria_and_keys_from_args(args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'mongo' | |
require 'pp' | |
db = Mongo::Connection.new.db('testing') | |
db.collections.each { |c| c.remove } | |
articles = db['articles'] | |
ratings = db['ratings'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'mongo' | |
uid, aid = BSON::ObjectID.new, BSON::ObjectID.new | |
db = Mongo::Connection.new.db('testing') | |
db.drop_collection('ratings') | |
db.create_collection('ratings') | |
ratings = db['ratings'] | |
ratings.create_index([[:user_id, Mongo::ASCENDING], [:article_id, Mongo::ASCENDING]], :unique => true) |