Skip to content

Instantly share code, notes, and snippets.

View itspriddle's full-sized avatar
🤘
clickity clack

Joshua Priddle itspriddle

🤘
clickity clack
View GitHub Profile
@itspriddle
itspriddle / or.rb
Created July 6, 2012 15:32
Why not Object#or
class Object
def or(fallback)
self || fallback
end
end
1.or :name
=> 1
nil.or :name
hash = {
"one" => "two",
:one => "two",
Class.new => :foo,
1 => :foo,
1.555 => :foo,
true => :foo,
false => :blah,
nil => :nil,
lambda {} => :lambda
class Foo; class Bar; class Baz; end; end; end
"Foo::Bar::Baz".split('::').inject(Kernel) { |out, str| out.const_get(str) }
#=> Foo::Bar::Baz
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
if ! has("gui_macvim")
finish
endif
" Window settings {{{
" Hide toolbar and scrollbars
set guioptions-=T
set guioptions-=r
set guioptions-=R
" 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")
require 'spec_helper'
class Foo
def bar; :foo_bar; end
end
describe Foo do
subject { Foo.new }
it do
@itspriddle
itspriddle / rspec_any_instance_test.rb
Created March 26, 2012 22:00 — forked from tfwright/rspec_any_instance_test.rb
Demonstrates unexpected behavior from .any_instance
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
# 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]