Skip to content

Instantly share code, notes, and snippets.

View benlovell's full-sized avatar
🕺
Dancing

Ben Lovell benlovell

🕺
Dancing
  • Ben Lovell Ltd
  • London, United Kingdom
View GitHub Profile
@benlovell
benlovell / url_dsl.rb
Created December 27, 2009 16:17 — forked from defunkt/url_dsl.rb
require 'open-uri'
# url dsl -- the ultimate url dsl!
#
# You just can't beat this:
#
# $ irb -r url_dsl
# >> include URLDSL
# => Object
# >> http://github.com/defunkt.json
=> Booting WEBrick
=> Rails 2.3.5 application starting on http://0.0.0.0:3000
/Users/benlovell/.rvm/gems/ruby-1.9.1-p376/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:440:in `rescue in load_missing_constant': uninitialized constant ActiveMerchant::Billing::ActiveMerchantError (NameError)
from /Users/benlovell/.rvm/gems/ruby-1.9.1-p376/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:436:in `load_missing_constant'
from /Users/benlovell/.rvm/gems/ruby-1.9.1-p376/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:80:in `const_missing_with_dependencies'
from /Users/benlovell/.rvm/gems/ruby-1.9.1-p376/gems/activemerchant-1.5.1/lib/active_merchant/billing/response.rb:4:in `<module:Billing>'
from /Users/benlovell/.rvm/gems/ruby-1.9.1-p376/gems/activemerchant-1.5.1/lib/active_merchant/billing/response.rb:2:in `<module:ActiveMerchant>'
from /Users/benlovell/.rvm/gems/ruby-1.9.1-p376/gems/activemerchant-1.5.1/lib/active_merchant/billing/response.
require 'rubygems'
require 'sinatra'
get '/' do
ENV['envvar']
end
Feature: Static content pages
As a store owner
I want to provide my customers with specific information
So that they can learn about my store
Scenario: Visit our Showroom
When I go to the visit our showroom page
Then I should see the heading "Visit Our Showroom"
@benlovell
benlovell / rspec_stub_chain_if_spec.rb
Created September 27, 2012 10:54 — forked from deepak/rspec_stub_chain_if_spec.rb
mocking stub chains with an assertion if the final call is made
# mocking stub chains with an assertion if the final call is made
# check https://github.com/rspec/rspec-mocks/issues/133 and
# https://groups.google.com/d/topic/rspec/Dc98rP-3IFM/discussion
require 'rspec'
class DevOps
attr_reader :monitor
def initialize(monitor = Monitor.new)
@benlovell
benlovell / test.rb
Created November 10, 2012 12:01
Sinatra auth
require 'rubygems'
require 'sinatra'
class Protected < Sinatra::Base
use Rack::Auth::Basic, "Protected Area" do |username, password|
self.authenticate username, password
end
get '/' do
"secret"
@benlovell
benlovell / app.rb
Created November 21, 2012 11:45
Sinatra attachments
get "/"
headers["Content-Disposition"] = "attachment;filename=the_file.txt"
headers["Content-Type"] = "..."
end
" https://github.com/carlhuda/janus/blob/master/janus/vim/core/janus/after/plugin/vimrc_after.vim
" Customization
"
" This loads after the janus plugins so that janus-specific plugin mappings can
" be overwritten.
if filereadable(expand("~/.yadr/vim/after/.vimrc.after"))
source ~/.yadr/vim/after/.vimrc.after
endif
@benlovell
benlovell / tests.txt
Created January 10, 2013 13:54
With and without ampersands.
[1,2,3,4,5].inject(0, &:+)
============= :__script__ ==============
Arguments: 0 required, 0 post, 0 total
Arity: 0
Locals: 0
Stack size: 5
Lines to IP: 1: 0..29
0000: meta_push_1
@benlovell
benlovell / mri.txt
Created January 10, 2013 14:02
MRI optimises this
(&:+)
= disasm: <RubyVM::InstructionSequence:<compiled>@<compiled>>==========
0000 trace 1 ( 1)
0002 duparray [1, 2, 3, 4, 5]
0004 putobject 0
0006 putobject :+
0008 send :inject, 2, nil, 0, <ic:0>
0014 leave
(:+)