Instantly share code, notes, and snippets.

View Gemfile
gem 'lograge' # more readable logs
gem 'logstash-event' # for logstash json format
gem 'mono_logger' # threadsafe logging

This was my solution for a polymorphic many-to-many association

class ItemCountry < ActiveRecord::Base
  belongs_to :locatable, :polymorphic => true
  belongs_to :country
  # fields are :locatable_id, :locatable_type, :country_id

class Title < ActiveRecord::Base
  has_many :countries, :through => :item_countries, :as => :locatable
View bin-squash_migrations
#!/usr/bin/env bash
git ls-files db/migrate/*.rb | sort | tail -1 | \
ruby -e "[/\d+/]; init_schema=%(db/migrate/#{schema_version}_init_schema.rb);
%x(git rm -f db/migrate/*.rb;
mkdir db/migrate;
git mv db/schema.rb #{init_schema};
rake db:migrate;
git add db/schema.rb; git commit -m 'Squashed migrations')"
View rails32_http_patch_support.rb
# Rails 3.2 support for HTTP PATCH.
fail "Remove this patch" if Rails::VERSION::MAJOR > 3
# see
# Be very conservative not to monkey-patch any methods until
# the relevant files are loaded.
ActiveSupport.on_load(:action_controller) do
ActionDispatch::Request.instance_eval do
# Is this a PATCH request?
View interview_questions.txt
Good Interview Questions
"Give Him/Her the opportunity to impress you, and maybe even give you a revelation"
Ask open-ended questions, see
---> attitudes about the topic
---> how s/he thinks
---> what s/he's been thinking about lately
Q: Compare Ruby to another language.
View jdbc_sample.rb
require './lib/adsjdbc-'
java_import java.sql.Driver
java_import java.sql.DriverManager
java_import 'com.extendedsystems.jdbc.advantage.ADSDriver'
class AdsAdapter
def initialize(connect_string)
@connect_string = connect_string
View errors.html.erb
<% if Rails.env.development? || %>
More verbose errors
<% end %>
View Gemfile
# A sample Gemfile
source ""
gem 'mechanize'