Skip to content

Instantly share code, notes, and snippets.

View vladvinnikov's full-sized avatar

Vladimir Vinnikov vladvinnikov

View GitHub Profile

Benchmark Bundler

Because loading gems can take longer than you think

$ curl -fsSL https://gist.github.com/raw/5022636/benchmark.rb | ruby
............................................................[DONE]

Gem                            Time(sec)     Pct %
--------------------------------------------------
class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))
end
end
BCX::Application.routes.draw do
draw :api
draw :account
draw :session
# = MONKEY PATCH: Memoize Mysql2 Columns
#
# Reduces SHOW FIELDS selects in production to essentially 0 calls.
#
# == Reason:
#
# * We have some pages that are (with rails 3.0.12) generating nearly 1200 SHOW
# FIELDS sql statements.
# * These come from ActiveRecord::Associations during complex join semantics.
# * Esentially, through some relations, Arel::Table instances don't have
after "deploy:symlink", "deploy:restart_workers"
##
# Rake helper task.
# http://pastie.org/255489
# http://geminstallthat.wordpress.com/2008/01/27/rake-tasks-through-capistrano/
# http://ananelson.com/said/on/2007/12/30/remote-rake-tasks-with-capistrano/
def run_remote_rake(rake_cmd)
rake_args = ENV['RAKE_ARGS'].to_s.split(',')
cmd = "cd #{fetch(:latest_release)} && #{fetch(:rake, "rake")} RAILS_ENV=#{fetch(:rails_env, "production")} #{rake_cmd}"
module RedisHelper
# decode Redis value back to Ruby object
def self.decode(json)
self.new(ActiveSupport::JSON.decode(json)["#{self.name.downcase}"])
end
# encode Ruby object for Redis
def encoded
self.updated_at = nil
self.to_json
RSpec.configure do |config|
config.around do |example|
# For examples using capybara-webkit for example.
# Remove this if you don't use it or anything similar
if example.metadata[:js]
example.run
ActiveRecord::Base.connection.execute("TRUNCATE #{ActiveRecord::Base.connection.tables.join(',')} RESTART IDENTITY")
else
ActiveRecord::Base.transaction do
@vladvinnikov
vladvinnikov / install_ruby_debug.sh
Created March 24, 2012 15:27 — forked from janv/install_ruby_debug.sh
Install Ruby-debug with RVM using Ruby 1.9.3-p0-falcon
#!/bin/sh
curl -LO http://rubyforge.org/frs/download.php/75414/linecache19-0.5.13.gem
curl -LO http://rubyforge.org/frs/download.php/75415/ruby-debug-base19-0.11.26.gem
gem install linecache19-0.5.13.gem
gem install ruby-debug-base19-0.11.26.gem -- --with-ruby-include=$HOME/.rvm/rubies/ruby-1.9.3-p0-falcon/include/ruby-1.9.1/ruby-1.9.3-p0/
rm linecache19-0.5.13.gem
rm ruby-debug-base19-0.11.26.gem
@vladvinnikov
vladvinnikov / gist:1675048
Created January 25, 2012 06:18 — forked from ambar/gist:1534274
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt