Skip to content

Instantly share code, notes, and snippets.

@dmitriy-kiriyenko
dmitriy-kiriyenko / active_model_lint.rb
Created February 23, 2012 13:37
ActiveModel lint tests for rspec
# put the file into spec/support
shared_examples_for "ActiveModel" do
include ActiveModel::Lint::Tests
# to_s is to support ruby-1.9
ActiveModel::Lint::Tests.public_instance_methods.map{|m| m.to_s}.grep(/^test/).each do |m|
example m.gsub('_',' ') do
send m
end
end
@soemarko
soemarko / theme.html
Created November 26, 2011 16:18
embed github gist to tumblr
<!-- Add the following lines to theme's html code right before </head> -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script src="http://static.tumblr.com/fpifyru/VCxlv9xwi/writecapture.js"></script>
<script src="http://static.tumblr.com/fpifyru/AKFlv9zdu/embedgist.js"></script>
<!--
Usage: just add <div class="gist">[gist URL]</div>
Example: <div class="gist">https://gist.github.com/1395926</div>
-->
@eirc
eirc / .rvmrc
Created October 20, 2011 07:53 — forked from jimeh/decode.rb
Ruby-based Benchmark of MessagePack vs. JSON vs. Yajl vs. Protobuffers vs. MultiJson vs. Marshal vs. YAML vs. BSON
rvm --create ree@benchmarks
@nesquena
nesquena / index_users_emails.rb
Created July 14, 2011 00:11
Add concurrent index in Postgres Rails migration
class IndexUsersEmails < ActiveRecord::Migration
def self.up
execute "END"
add_pg_index :users, :email, :lock => false
execute "BEGIN"
end
end
@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
@bobthecow
bobthecow / tab.bash
Last active November 10, 2023 08:47
Open new Terminal tabs from the command line
#!/bin/bash
#
# Open new Terminal tabs from the command line
#
# Author: Justin Hileman (http://justinhileman.com)
#
# Installation:
# Add the following function to your `.bashrc` or `.bash_profile`,
# or save it somewhere (e.g. `~/.tab.bash`) and source it in `.bashrc`
#
@headius
headius / gist:702298
Created November 16, 2010 19:08
Maven gems...I love you.
~/projects/jruby ➔ gem install -v1.5.5 org.jruby.jruby-complete
Installing from Maven using install at /Users/headius/apache-maven-3.0/bin
Successfully installed org.jruby.jruby-complete-1.5.5-java
1 gem installed
Installing ri documentation for org.jruby.jruby-complete-1.5.5-java...
Installing RDoc documentation for org.jruby.jruby-complete-1.5.5-java...
~/projects/jruby ➔ gem install -v1.5.3 org.jruby.jruby-complete
Installing from Maven using install at /Users/headius/apache-maven-3.0/bin
Successfully installed org.jruby.jruby-complete-1.5.3-java
module Mongoid
module DeepCloning
def deep_clone(attrs = {}, obj = nil)
returning obj || self.class.new do |o|
o.write_attributes(@attributes.merge(attrs).except("_id", "versions").except(*o.class.associations.keys))
yield o if block_given?
o.save
@attributes.each_pair do |key, value|
next unless proxy = self.associations[key]
case proxy.association
class Account
include Mongoid::Document
include Mongoid::Timestamps
field :subdomain, :type => String
embeds_many :users
accepts_nested_attributes_for :users
validates_presence_of :name, :subdomain
validates_uniqueness_of :subdomain, :case_sensitive => false
@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')