Skip to content

Instantly share code, notes, and snippets.

@jnunemaker
jnunemaker / database.yml
Created November 12, 2009 14:59
mongo initializer to load config from database.yml, authenticate if needed and ensure indexes are created
development: &global_settings
database: textual_development
host: 127.0.0.1
port: 27017
test:
database: textual_test
<<: *global_settings
production:
@jerodsanto
jerodsanto / firebug_logger.rb
Created December 9, 2009 16:23 — forked from simonjefford/firebug_logger.rb
Rack::FirebugLogger
module Rack
class FirebugLogger
def initialize(app, options = {})
@app = app
@options = options
end
def call(env)
status, headers, orig_response = @app.call(env)
return [status, headers, orig_response] unless (headers["Content-Type"] =~ /html/ && env['firebug.logs'])
This plugin for Merb and Rails provides a simple and extremely flexible way to upload files.
ORM Support: ActiveRecord, DataMapper, Sequel, MongoMapper
Storage Support: S3, MongoDB's GridFS, filesystem...
Oh yeah and works with RMagick, ImageScience, MiniMagic
http://github.com/jnicklas/carrierwave/
@TomK32
TomK32 / active_record_to_mongo_mapper_migration.rb
Created January 29, 2010 21:46
An ActiveRecord migration to migrate your database to MongoDB using MongoMapper
# The basic idea is that we take the existing data via ActiveRecord
# and create new documents in MongoDB using MongoMapper.
# This method is necessary as we want to keep all the associations of existing dataset
# and by the way, clean up empty columns
# We rely on models still being ActiveRecord::Base, I bet you can figure out how the look like.
# And have the newer MongoDB ones here in a module, painful as we have to set the collection_name
# Don't put a +timestamps!+ into your MongoMapper models yet because this would change the updated_at if existing
# As you see in the MongoDB models, a few loose their indepence, e.g. Source as I
# plan to add other sources besides flickr, or Page and Album which only make sense in
# their parent Website
@toyflish
toyflish / enviroment.rb
Created April 19, 2010 17:25
rails 2.3.5, Activerecord-sessionstore takes session-id from get-vars if passed by shockwave flash (uploadify) using rack-middleware
# part of config/enviroment.rb
...
Rails::Initializer.run do |config|
# Load model files from sub folders
config.load_paths += Dir["#{RAILS_ROOT}/app/models/*"].find_all { |f| File.stat(f).directory? }
# Load middleware - initially used by flash-session-hack
config.load_paths << "#{RAILS_ROOT}/app/middleware"
@mrrooijen
mrrooijen / carrierwave_tasks.rb
Created June 2, 2010 00:27
Rake Tasks for Carrier Wave for reprocessing versions.
##
# CarrierWave Amazon S3 File Reprocessor Rake Task
#
# Written (specifically) for:
# - CarrierWave
# - Ruby on Rails 3
# - Amazon S3
#
# Works with:
# - Any server of which you have write-permissions in the Rails.root/tmp directory
@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
#testing the speed of creating a new object via the association with mongoid
c = Club.first
####### 43 seconds #######
begin
500.times do |i|
c.people.create(:name => 'Jim')
end
end
@jferris
jferris / new.rb
Created November 5, 2010 18:23
New FactoryGirl definition syntax
FactoryGirl.define do
sequence :email do |n|
"user#{n}@example.com"
end
factory :user do
email
password "test"
aliased_as :author
end
@ches
ches / gist:718234
Created November 27, 2010 20:20 — forked from jpemberthy/gist:349242
Very simple taggable behavior for Mongoid
# Basic tagging system for mongoid documents.
# jpemberthy 2010
#
# class User
# include Mongoid::Document
# include Mongoid::Document::Taggable
# end
#
# @user = User.new(:name => "Bobby")
# @user.tag_list = "awesome, slick, hefty"