Skip to content

Instantly share code, notes, and snippets.

@Ptico
Ptico / spec.rb
Created October 7, 2011 15:30
Rspec functioning principle
# Core
class Object
def should(matcher)
puts matcher.match(self)
end
end
class Matcher
def initialize(expected, &block)
@expected = expected
@Ptico
Ptico / shoulda_am.rb
Created September 22, 2011 12:41
Shoulda activemodel matchers cheatsheet
# Shoulda activemodel cheatsheet
# DB
should have_db_column(:title).of_type(:string).with_options(default: 'Untitled', null: false)
should have_db_index(:email).unique(:true)
# Associations
should belong_to :company
should have_one(:profile).dependent(:destroy)
should have_many(:posts).dependent(:nullify)
require 'resque/tasks'
task "resque:setup" => :environment
namespace :queue do
task :start => :environment do
pidfile = Rails.root.join('tmp', 'pids', 'resque.pid')
logfile = Rails.root.join('log', 'resque.log')
errlogfile = Rails.root.join('log', 'resque_errors.log')
@Ptico
Ptico / ruby-1.9-tips.rb
Created February 27, 2011 22:18 — forked from igrigorik/ruby-1.9-tips.rb
Ruby 1.9 tips and tricks
def tip(msg); puts; puts msg; puts "-"*100; end
#
# 30 Ruby 1.9 Tips, Tricks & Features:
# http://www.igvita.com/2011/02/03/new-ruby-19-features-tips-tricks/
#
tip "Upgrading to Ruby 1.9 is simple: rvm install 1.9.2 && rvm --default 1.9.2"
tip "Ruby 1.9 supports named captures in regular expressions!"
# cap web:deploy:desable & cap web:deploy:enable
server {
...
if (-f $document_root/system/maintenance.html) { set $maintenance 1; }
if ($request_uri ~* (jpg|jpeg|gif|js|css)$) { set $maintenance 0; }
if ($maintenance) { rewrite ^(.*)$ /system/maintenance.html; break; }
...
}