Here's the cool shit from railsconf. An overview of all talks is here, https://github.com/newhavenrb/railsconf2012
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
| class Object | |
| def or(fallback) | |
| self || fallback | |
| end | |
| end | |
| 1.or :name | |
| => 1 | |
| nil.or :name |
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
| hash = { | |
| "one" => "two", | |
| :one => "two", | |
| Class.new => :foo, | |
| 1 => :foo, | |
| 1.555 => :foo, | |
| true => :foo, | |
| false => :blah, | |
| nil => :nil, | |
| lambda {} => :lambda |
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
| class Foo; class Bar; class Baz; end; end; end | |
| "Foo::Bar::Baz".split('::').inject(Kernel) { |out, str| out.const_get(str) } | |
| #=> Foo::Bar::Baz |
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
| module Cacher | |
| def self.extended(base) | |
| base.class_eval do | |
| before do | |
| if subject.respond_to?(:caches_action) && cache_path = example.metadata[:cache] | |
| subject.caches_action cache_path | |
| end | |
| end | |
| end | |
| 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
| if ! has("gui_macvim") | |
| finish | |
| endif | |
| " Window settings {{{ | |
| " Hide toolbar and scrollbars | |
| set guioptions-=T | |
| set guioptions-=r | |
| set guioptions-=R |
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
| " A ghetto gister for Vim. | |
| " Requires gist <https://github.com/defunkt/gist> | |
| " | |
| " Usage: | |
| " :'<,'>Gist | |
| command -range=% Gist call s:Gist(<line1>, <line2>, <f-args>) | |
| function! s:Gist(line1, line2, ...) | |
| let d1 = join(getline(a:line1, a:line2), "\n") |
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 'spec_helper' | |
| class Foo | |
| def bar; :foo_bar; end | |
| end | |
| describe Foo do | |
| subject { Foo.new } | |
| it do |
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 'rspec/mocks' | |
| describe Object do | |
| it "should not care how many times a stubbed method is called" do | |
| Object.should_receive(:some_method).any_number_of_times | |
| end | |
| 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
| # Breaks in Chrome | |
| RewriteRule /somepath/(.*) /some-other/file.php?file=$1 [L,NC] | |
| # Works | |
| RewriteRule /somepath/(.*) http://%{HTTP_HOST}/some-other/file.php?file=$1 [L,NC] |