Skip to content

Instantly share code, notes, and snippets.

View lenny's full-sized avatar

Lenny Marks lenny

  • American Physical Society
  • Long Island, NY
  • 04:39 (UTC -04:00)
View GitHub Profile
@lenny
lenny / fix_amp_eq.rb
Last active August 29, 2015 13:57
Script used while upgrading from Rails 2 to Rails 3/4
dir = ARGV[0]
raise "Usage: #{$0} <DIR>" if dir.nil?
Dir[File.join(dir, '**/*.haml')].each do |f|
s = File.read(f)
lines = []
s.each_line do |l|
l = l.gsub('&=', '=')
class BackgroundJobWatcher
attr_accessor :mailer, :error_io
class << self
def attempt(job_name, &blk)
new.attempt(job_name, &blk)
end
end
def initialize(opts = {})
class ExpensiveOperation
def self.lookup(question)
"This goes to the database"
end
end
class UsesExpensiveOperation
def initialize
@cache = {}
end
When I select the following previous correspondence items:
| type | date | filename |
| CTA | 01Jan09 | EMAIL |
When /^I select the following previous correspondence items:$/ do |table|
checkboxes = PreviousCorrespondenceSteps.get_checkboxes_for(table)
checkboxes.each {|b| b.set(true) }
config.after_initialize do
MVOR::Gateway.use_3ds_test_gateway
end
config.after_initialize do
AppConfig.payment_gateway_mode = :test
end
Daemon 0
LogFacility -
LogLevel 5
ListenHTTP
Address lenny.ridge
Port 3001
Service
URL "/MyApp1/.*"
@lenny
lenny / active_record_spec_helper.rb
Created November 20, 2010 18:32
spec helper for inclusion by specs that don't need/depend on the entire rails environment. In JRuby, specs that don't load entire rails env run significantly faster.
unless self.class.const_defined?('APP_ROOT')
APP_ROOT = File.expand_path(File.dirname(__FILE__) + '/../../../../../')
end
puts "#{File.basename(__FILE__)}: APP_ROOT: #{APP_ROOT}"
require File.expand_path("#{File.dirname(__FILE__)}/no_rails_env_spec_helper")
unless self.class.const_defined?('Rails')
require 'benchmark'
@lenny
lenny / v1.rb
Created August 24, 2011 20:45
rspec macros
1 require File.dirname(__FILE__) + "/spec_helper"
2
3 require 'email'
4
5 describe Email do
6 describe '.normalize', ' should strip email down to core address' do
7 def self.normalized(original, options)
8 it %{normalizes '#{original}' as '#{options[:should_be]}'} do
9 Email.normalize(original).should == options[:should_be]
10 end
@lenny
lenny / java_properties.rb
Created October 24, 2011 14:54
Ruby wrapper around Java Properties
# More rubyish/convenient interface to Java Properties(e.g. Loading connection config from properties file)
class JavaProperties
def initialize(name)
input_stream =
Java::Java.lang.Thread.currentThread.contextClassLoader.getResourceAsStream(name)
if input_stream
@properties = Java::java.util.Properties.new
@properties.load(input_stream)
input_stream.close