Skip to content

Instantly share code, notes, and snippets.

View millisami's full-sized avatar
🎯
Focusing on landing a Web3 Job

Sachin Sagar Rai millisami

🎯
Focusing on landing a Web3 Job
View GitHub Profile

Ruby Debugger

Most of the time simple output statements using warn, raise, or a logger will help you find your issue. But sometimes you need the big guns, and that means ruby-debug.

Ruby-Debug

The ruby-debug package has had some rocky times during the transition from Ruby 1.8.7 to 1.9.2 and beyond. But now, finally, the debugger is reliable and usable.

Installation

class Foo < ActiveRecord::Base
include Models::Scopes::Order
default_scope recently_updated # didn't realize you could do this
end
@justinko
justinko / callback_disabler.rb
Created September 2, 2011 00:20
Disable raw filter callbacks in RSpec
# In spec/support/callback_disabler.rb
module CallbackDisabler
def self.store_callbacks(model, filters)
model = constantize(model)
filters.each do |filter|
model.send("_#{filter}_callbacks").each do |callback|
stored_callbacks[model] << {
filter: filter, kind: callback.kind, raw_filter: callback.raw_filter
}
@adambair
adambair / gist:1299611
Created October 19, 2011 20:46
pry is awesome.
# use instead of rails console
pry -r ./config/environment.rb
# for debugging in code put this anywhere:
binding.pry
# then check your console (rails server window) and type:
help
# win
@zliang-min
zliang-min / example.rb
Created November 10, 2011 18:30
You don't need a library for everything. For example, git.io :)
Git.io.generate 'https://gist.github.com/gists/1355677'
Git.io.generate 'https://github.com/gimi', 'gimi'
Git.io.recognize 'http://git.io/gimi'
@millisami
millisami / application.rb
Created April 7, 2012 15:31 — forked from finack/application.rb
Example Chef Deploy Revision for Rails 3+
app = node[:rails][:app]
rails_base app[:name] do
ruby_ver app[:ruby_ver]
gemset app[:gemset]
end
%w{config log pids cached-copy bundle system}.each do |dir|
directory "#{app[:app_root]}/shared/#{dir}" do
owner app[:deploy_user]
Order.class_eval do
checkout_flow do
go_to_state :address
go_to_state :delivery
go_to_state :payment, :if => lambda { payment_required? }
go_to_state :confirm, :if => lambda { confirmation_required? }
go_to_state :complete
remove_transition :from => :delivery, :to => :confirm
end
end
@datenimperator
datenimperator / Gemfile
Created September 7, 2012 18:55
Sinatra, sprockets, compass, bootstrap-sass playing together
source :rubygems
gem 'shotgun', :group=>:development
gem 'rack-cache'
gem 'sinatra', :require => 'sinatra/base'
gem 'sinatra-support'
gem 'haml'
class Chef
class Recipe
def skip_unsupported_platform
unless supported_platform?
Chef::Log.info("Unsupported platform #{node[:platform]} in #{cookbook_name}::#{recipe_name}, skipping recipe")
Chef::Log.debug("You said to skip unsupported platforms in #{cookbook_name}::#{recipe_name}")
Chef::Log.debug("and #{node['platform']} is unsupported by cookbook #{cookbook_name}. Update the cookbook's metadata")
Chef::Log.debug("if this is a supported platform, or remove #{cookbook_name}::#{recipe_name} from the node.")
end
end

Zero downtime deploys with unicorn + nginx + runit + rvm + chef

Below are the actual files we use in one of our latest production applications at Agora Games to achieve zero downtime deploys with unicorn. You've probably already read the GitHub blog post on Unicorn and would like to try zero downtime deploys for your application. I hope these files and notes help. I am happy to update these files or these notes if there are comments/questions. YMMV (of course).

Other application notes:

  • Our application uses MongoDB, so we don't have database migrations to worry about as with MySQL or postgresql. That does not mean that we won't have to worry about issues with the database with indexes being built in MongoDB or what have you.
  • We use capistrano for deployment.

Salient points for each file: