Skip to content

Instantly share code, notes, and snippets.

@opsb
opsb / Mongoid_embeds_many_destroy_all_bug
Created December 10, 2010 09:10
Mongoid embeds_many bug - loses create after some some destroy_all/create sequences
require 'rubygems'
require 'mongoid'
require 'rspec'
require 'method_lister'
Mongoid.configure do |config|
name = "association_bug"
config.master = Mongo::Connection.new.db(name)
end
@opsb
opsb / mongoid embeds many bug with field
Created December 10, 2010 17:05
mongoid embeds many bug with field on child
require 'rubygems'
require 'mongoid'
require 'rspec'
require 'method_lister'
Mongoid.configure do |config|
name = "association_bug"
config.master = Mongo::Connection.new.db(name)
end
@opsb
opsb / gist:772117
Created January 9, 2011 22:56
Redefine db:test:purge task to clear database instead of drop
Rake::TaskManager.class_eval do
def delete_task(task_name)
@tasks.delete(task_name.to_s)
end
Rake.application.delete_task("db:test:purge")
end
namespace :db do
namespace :test do
task :purge do
ActiveRecord::Migrator.migrate("db/migrate/", 0)
def stop_tomcat
puts "stopping tomcat"
end
def start_tomcat
puts "starting tomcat"
end
def restart
stop_tomcat
require 'rubygems'
require 'rspec'
def split(original)
original.split("/").inject([]) do |result, element|
result + [(result.last||[]) + [element]]
end.reverse.map{ |variation| variation.join("/") }
end
describe "#category" do
require 'generator'
def before_yield(n)
puts "stopped at #{n}"
n
end
build_plan = Generator.new do |build_plan|
(1..10).each{ |n| build_plan.yield before_yield(n) }
end
+----+----------+----------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------+---------------------+-----------+-----------+-----------+------------+---------------------+---------------------+
| id | priority | attempts | handler
+----+----------+----------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------+---------------------+-----------+-----------+-----------+------------+---------------------+---------------------+
| id | priority | attempts | handler
@opsb
opsb / StrftimeOrdinal.rb
Created March 23, 2011 18:43
Extend strftime with ordinalize
module StrftimeOrdinal
def self.included(base)
base.class_eval do
alias_method :old_strftime, :strftime
def strftime(format)
old_strftime format.gsub("%o", day.ordinalize)
end
end
end
end
@opsb
opsb / heroku_environments.bash
Created April 2, 2011 10:52
manage multiple heroku environment for same app
function stage() { heroku $@ --app $(basename `pwd`)-stage ;}
function production() { heroku $@ --app $(basename `pwd`)-production ;}