Skip to content

Instantly share code, notes, and snippets.

View cpetschnig's full-sized avatar

Christoph Petschnig cpetschnig

  • SINC GmbH
  • Leipzig, Germany
  • 04:01 (UTC +02:00)
View GitHub Profile
@cpetschnig
cpetschnig / profiling-example.rb
Created November 16, 2010 15:51
Custom runtime evaluation/profiling
class Array
@@caller_counter = {}
def include_with_caller?(value)
key = caller[0,4].join('|')
@@caller_counter[key] = (@@caller_counter[key] || 0) + 1
include_without_caller?(value)
end
alias_method_chain :include?, :caller
def self.callers
@@caller_counter
@cpetschnig
cpetschnig / .irbrc
Created April 13, 2011 09:48
IRB customization: load wirble, looksee and awesome_print; cheat bundler
require 'rubygems'
@irb_extensions = []
def require_for_irb_with_fallback_for_bundler_constraints(gem_name, load_file = nil)
load_file ||= gem_name
begin
begin
require load_file
rescue LoadError => e
@cpetschnig
cpetschnig / cap_deploy_clean_menu_exit.rb
Created May 5, 2011 11:31
Avoid stack trace when canceling the Capistrano menu
# Put this code in your deploy.rb, if you are annoyed by
# the stack trace when aborting the capistrano with ^C
# (under MIT License)
require 'active_support/core_ext/module'
# avoid having a whole page of stack trace when you abort the menu with `^C`
HighLine.module_eval do
def get_line_with_interrupt_catching
get_line_without_interrupt_catching
@cpetschnig
cpetschnig / gist:1286665
Created October 14, 2011 09:23
Show Term::ANSIColor effects
# Show Term::ANSIColor effects
(Term::ANSIColor.methods - Module.methods).sort.each{|x| print "#{x}: ".ljust(15); begin; puts Term::ANSIColor.send(x, 'foo bar'); rescue; puts 'error'; end }
@cpetschnig
cpetschnig / even_more_debugging_output.rb
Created November 8, 2011 07:32
Trace the origin of your Rails logging output
class ActiveSupport::BufferedLogger
def add(severity, message = nil, progname = nil, &block)
return if @level > severity
message = (message || (block && block.call) || progname).to_s
# If a newline is necessary then create a new message ending with a newline.
# Ensures that the original message is not mutated.
message = "#{message}\n" unless message[-1] == ?\n
buffer << message
@cpetschnig
cpetschnig / gist:1570765
Created January 6, 2012 14:07
env settings
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \1 $SYM/'
}
BLUE="\[\e[1;34m\]"
BLUE_="\[\e[0;34m\]"
BROWN_="\[\e[0;33m\]"
RESET="\[\e[0;0m\]"
SYM="$BLUE_Δ"
@cpetschnig
cpetschnig / i18n_lookup.rb
Created January 11, 2012 13:32
Log failed I18n lookups in Rails
class I18n::Backend::Simple
module Implementation
protected
def lookup(locale, key, scope = [], options = {})
init_translations unless initialized?
keys = I18n.normalize_keys(locale, key, scope, options[:separator])
keys.inject(translations) do |result, _key|
@cpetschnig
cpetschnig / detailed_logger.rb
Created June 6, 2012 11:29
Show the source of your Rails log messages. Put this file in your config/initializers directory.
require 'active_support/buffered_logger'
class ActiveSupport::BufferedLogger
def add(severity, message = nil, progname = nil, &block)
add_debugging_details(severity)
@log.add(severity, message, progname, &block)
end
private
require 'looksee'
Looksee.styles.each_key { |key| Looksee.styles[key] = "%s" }
@cpetschnig
cpetschnig / gist:3069758
Created July 8, 2012 07:19
Ubuntu system requirements for Ruby
sudo apt-get install git curl build-essential bison openssl libreadline6 libreadline6-dev zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev libffi-dev tk-dev