Last active
December 11, 2015 01:28
-
-
Save madwork/4523383 to your computer and use it in GitHub Desktop.
Mac OS X 10.8 : RVM + Homebrew + Ruby 1.9.3 + .pryrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
# textmate as editor | |
Pry.config.editor = 'mate -w' | |
Pry.config.color = true | |
Pry.config.pager = true | |
# alias 'q' for 'exit' | |
Pry.config.commands.alias_command 'q', 'exit-all' | |
# Better colors - by default the headings for methods are too | |
# similar to method name colors leading to a "soup" | |
# These colors are optimized for use with Solarized scheme | |
# for your terminal | |
# Pry.config.ls.separator = "\n" # new lines between methods | |
Pry.config.ls.heading_color = :magenta | |
Pry.config.ls.public_method_color = :blue | |
Pry.config.ls.protected_method_color = :yellow | |
Pry.config.ls.private_method_color = :bright_black | |
# This prompt shows the ruby version (useful for RVM) | |
# Ex: [1.9.3] 0:(main) > | |
prompt_proc = lambda do |obj, nest_level, _| | |
ruby_info = "" | |
ruby_info << "\e[32m#{Rails.version}\e[0m@" if defined?(Rails) | |
ruby_info << "\e[31m#{RUBY_VERSION}\e[0m" | |
ruby_info = ruby_info | |
nest_info = "#{nest_level}" | |
obj_info = "\e[33m#{obj}\e[0m" | |
"[#{ruby_info}] #{nest_info}:(#{obj_info}) > " | |
end | |
Pry.prompt = [prompt_proc, prompt_proc] | |
def require_without_bundler gem_name | |
_gem_path = Dir.glob("#{Gem.path.grep(/global$/).first}/gems/#{gem_name}*/lib").first | |
if _gem_path | |
$LOAD_PATH << _gem_path | |
require gem_name | |
else | |
raise LoadError, "Please put #{gem_name} in your global" | |
end | |
end | |
# Load 'awesome_print' | |
begin | |
require_without_bundler 'awesome_print' | |
# The following line enables awesome_print for all pry output, | |
# and it also enables paging | |
Pry.config.print = proc {|output, value| Pry::Helpers::BaseHelpers.stagger_output("=> #{value.ai}", output)} | |
# If you want awesome_print without automatic pagination, use the line below | |
# Pry.config.print = proc { |output, value| output.puts value.ai } | |
rescue LoadError => err | |
# puts "gem install awesome_print" | |
end | |
# Load 'hirb' | |
begin | |
require_without_bundler 'hirb' | |
Pry.config.print = proc { |output, value| Hirb::View.view_or_page_output(value) || Pry::DEFAULT_PRINT.call(output, value) } | |
Hirb.enable | |
rescue LoadError => err | |
# puts "gem install hirb" | |
end | |
# Load plugins (only those I whitelist) | |
Pry.config.should_load_plugins = false | |
Pry.plugins['doc'].activate! | |
# Useful Collections | |
def a | |
Array.new(10){rand(100)} | |
end | |
def h | |
{ :foo => rand(100), :bar => rand(100) } | |
end | |
# Benchmarking | |
def bench(repetitions = 100, &block) | |
Benchmark.bm{|x| x.report{repetitions.times(&block)}} | |
end | |
# Launch Pry with access to the entire Rails stack. | |
# If you have Pry in your Gemfile, you can pass: ./script/console --irb=pry instead. | |
# If you don't, you can load it through the lines below :) | |
rails = File.join Dir.getwd, 'config', 'environment.rb' | |
if File.exist?(rails) && ENV['SKIP_RAILS'].nil? | |
require rails | |
if Rails.version[0..0] == "2" | |
require 'console_app' | |
require 'console_with_helpers' | |
elsif Rails.version[0..0] == "3" | |
require 'rails/console/app' | |
require 'rails/console/helpers' | |
else | |
warn "[WARN] cannot load Rails console commands (Not on Rails2 or Rails3?)" | |
end | |
puts "Rails environment [\e[31m#{Rails.env}\e[0m] loaded." | |
puts "RVM: \e[31m#{`rvm current`}\e[0m" | |
end | |
if defined?(Rails) && Rails.env | |
require 'logger' | |
Rails.logger = Logger.new($stdout) | |
# automatically call `reload` every time a new command is typed | |
# Pry.hooks.add_hook(:before_eval, :reload_everything) { reload! } | |
# Add Rails console helpers (like `reload!`) to pry | |
if defined?(Rails::ConsoleMethods) | |
extend Rails::ConsoleMethods | |
end | |
def r | |
reload! | |
end | |
def show obj | |
ap obj.send :column_names | |
end | |
# sql for arbitrary SQL commands through the AR | |
def sql query | |
ActiveRecord::Base.connection.execute query | |
end | |
def toggle_db_logging | |
if $db_logging_enabled | |
ActiveRecord::Base.logger = Logger.new(nil) if defined?(ActiveRecord) | |
Mongoid.logger = Logger.new(nil) if defined?(Mongoid) | |
$db_logging_enabled = false | |
else | |
ActiveRecord::Base.logger = Rails.logger if defined?(ActiveRecord) | |
Mongoid.logger = Rails.logger if defined?(Mongoid) | |
$db_logging_enabled = true | |
end | |
end | |
toggle_db_logging | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# RVM | |
curl https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer | bash -s stable | |
# .rvmrc | |
export rvm_path="/Users/user/.rvm" | |
export rvm_usr_path="/Users/user/.rvm/usr" | |
export rvm_project_rvmrc_default=1 | |
export rvm_project_rvmrc=1 | |
export rvm_pretty_print_flag=1 | |
export rvm_trust_rvmrcs_flag=1 | |
export CFLAGS="-O2 -arch x86_64" | |
export LDFLAGS="-L/usr/local/lib" | |
export CPPFLAGS="-I/usr/local/include" | |
# Homebrew with gcc | |
ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)" | |
brew update | |
brew install libksba | |
brew tap homebrew/dupes | |
brew install autoconf automake apple-gcc42 | |
# Ruby 1.9.3 (railsexpress) with RVM | |
rvm pkg install readline libyaml openssl | |
rvm install ruby-1.9.3-p374 -n railsexpress --patch railsexpress |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment