Skip to content

Instantly share code, notes, and snippets.

~/projects/dgnetwork[bundler]% ruby --version
ruby 1.9.1p376 (2009-12-07 revision 26041) [i386-darwin10.2.0]
source :gemcutter
gem 'rails', '2.3.5'
gem 'httparty'
gem 'mad_mimi_mailer', '0.0.8'
gem 'fastercsv'
gem 'crummy'
gem 'prawn'
gem 'barby'
gem 'friendly_id'
# The idea for this technique taken from: http://blog.wolfman.com/articles/2007/07/14/using-rspec-to-test-haml-helpers
module HelperHamlSupport
def new(*args, &block)
super.tap do |obj|
obj.extend Haml
obj.extend Haml::Helpers
obj.init_haml_helpers
end
end
end
# Rack::Test doesn't support hitting external webservers. However, when a user enters their credit card info,
# it is submitted directly to braintree, so we need to intregration test with hitting an external server.
# This hack enabled this, by swapping out the Rack::Test's rack app with a Rack::Client instance.
# Rack::Client acts just like a rack app, but under the covers it delegates to Net::HTTP.
require 'rack/client'
module RackTestHack
def new(*a, &b)
---
- !ruby/struct:VCR::HTTPInteraction
request: !ruby/struct:VCR::Request
method: :get
uri: http://maps.google.com:80/maps/geo?q=Seattle%2C+WA&output=xml&key=ABQIAAAAM1mKqHK9XdhE_YEkQ7oqnhR8EBP7TfhOOIrsLnV5Hk7LABXvFhRRL3Y8fJfBk0KFeIkQgKLdCVcFCQ&oe=utf-8
body:
headers:
accept:
- "*/*"
host:
>> puts User.first.methods.select { |m| m =~ /_with(out)?_/ }.sort
destroy_with_callbacks
destroy_with_transactions
destroy_without_callbacks
destroy_without_transactions
extend_with_included_modules_from
load_with_new_constant_marking
reload_with_autosave_associations
reload_with_dirty
reload_without_autosave_associations
>> p = Proc.new { |a, b| a }
=> #<Proc:0x00000001036962f8@(irb):2>
>> p.call(5)
=> 5
>> l = lambda { |a, b| a }
=> #<Proc:0x000000010368e8c8@(irb):4>
>> l.call(5)
ArgumentError: wrong number of arguments (1 for 2)
from (irb):4
from (irb):5:in `call'
class DocumentAnalyzer
SPLIT_STRATEGY = lambda { |doc| doc.split(' ').size }
def initialize(document)
@document = document
end
def word_count(counting_strategy = SPLIT_STRATEGY)
counting_strategy.call(@document)
end
[VM] mmarston@mmarston0.dev.pages:~$ ./run_remote mate -w foo.rb
ssh mmarston mate /Volumes/DevVM/-w
[VM] mmarston@mmarston0.dev.pages:~$ 2010-06-28 16:57:51.823 mate[84317:90f] An uncaught exception was raised
2010-06-28 16:57:51.826 mate[84317:90f] *** -[NSArray objectAtIndex:]: index (-1 (or possibly larger)) beyond bounds (0)
2010-06-28 16:57:51.826 mate[84317:90f] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSArray objectAtIndex:]: index (-1 (or possibly larger)) beyond bounds (0)'
*** Call stack at first throw:
(
0 CoreFoundation 0x959dbbba __raiseError + 410
1 libobjc.A.dylib 0x98a37509 objc_exception_throw + 56
2 CoreFoundation 0x95a202f1 -[__NSArray0 objectAtIndex:] + 209
#!/usr/bin/env ruby
require 'pathname'
remote_host = 'mmarston'
path_to_local_on_remote = Pathname.new('/Volumes/DevVM')
user_home = Pathname.new(File.expand_path('~'))
given_path = Pathname.new(File.expand_path(ARGV[1]))
command = ARGV[0]
dir = path_to_local_on_remote + given_path.relative_path_from(user_home)