This file contains hidden or 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' | |
require 'logger' | |
class LoggerBenchmark | |
def initialize | |
@logger = Logger.new("/dev/null") | |
end | |
def benchmark | |
n = 10000 |
This file contains hidden or 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
# Without setting thr LANG, I'd get errors from Ruby like this: | |
# YAML Exception reading 2012-09-23-state-of-e-commerce-in-india.md: invalid byte sequence in US-ASCII | |
# /Users/arnabdeka/Dropbox/websites/arnab.github.com/plugins/backtick_code_block.rb:13:in `gsub': invalid byte sequence in US-ASCII (ArgumentError) | |
# from /Users/arnabdeka/Dropbox/websites/arnab.github.com/plugins/backtick_code_block.rb:13:in `render_code_block' | |
# ... | |
# I got the idea while reading this rubygems issue: https://github.com/rubygems/rubygems/issues/314 | |
export LANG=en_US.utf-8 |
This file contains hidden or 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
;; Gist-ed from in https://github.com/arnab/emacs-starter-kit | |
(defun fontify-frame (frame) | |
(interactive) | |
(if window-system | |
(progn | |
(if (> (x-display-pixel-width) 2000) | |
(set-frame-parameter frame 'font "Inconsolata 19") ;; Cinema Display | |
(set-frame-parameter frame 'font "Inconsolata 16"))))) |
This file contains hidden or 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
before_filter: allow_cors_requests | |
def allow_cors | |
headers["Access-Control-Allow-Origin"] = "*" | |
headers["Access-Control-Allow-Methods"] = %w{GET POST PUT DELETE}.join(",") | |
headers["Access-Control-Allow-Headers"] = %w{Origin Accept Content-Type X-Requested-With X-CSRF-Token}.join(",") | |
head(:ok) if request.request_method == "OPTIONS" | |
# or, render text: '' | |
# if that's more your style | |
end |
This file contains hidden or 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
# From inside a Rails root directory | |
# After you call save_and_open_page in Capybara (and you don't have or want launchy) | |
open -a "Google Chrome" "tmp/capybara/"`ls -tr tmp/capybara/ | head -2 | tail -1` |
This file contains hidden or 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
# Works with Rails 3.2.x (and this keeps changing due to the large amounts of gems and their author's philosophies differing all the time) | |
# 1. Create new Rails app | |
rails new <thing> --skip-testunit | |
# 2. Add the following to Gemfile: | |
group :development, :test do | |
gem 'rspec-rails' | |
gem 'cucumber-rails', :require => false |
This file contains hidden or 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
mv ~/.emacs.d ~/.emacs.d.bak | |
cd ~/.emacs.d | |
git clone <your-clone-of-esk> |
This file contains hidden or 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
before_script: "bundle exec rake db:migrate" |
This file contains hidden or 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
# From http://weblog.jamisbuck.org/2007/3/7/raising-the-right-exception | |
exceptions = [] | |
tree = {} | |
ObjectSpace.each_object(Class) do |cls| | |
next unless cls.ancestors.include? Exception | |
next if exceptions.include? cls | |
next if cls.superclass == SystemCallError # avoid dumping Errno's | |
exceptions << cls | |
cls.ancestors.delete_if {|e| [Object, Kernel].include? e }.reverse.inject(tree) {|memo,cls| memo[cls] ||= {}} |
This file contains hidden or 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
def some_method(other_method, args) | |
puts "before" | |
other_method.call args | |
puts "after" | |
end | |
def other_method(stuff) | |
puts "other_method called with #{stuff.inspect}" | |
end |