Skip to content

Instantly share code, notes, and snippets.

View burtlo's full-sized avatar

Lynn Frank burtlo

View GitHub Profile
@burtlo
burtlo / google.rb
Created September 7, 2012 22:05
Capybara without other testing frameworks
require 'capybara'
require 'capybara/dsl'
Capybara.configure do |config|
config.run_server = false
config.app_host = 'http://www.google.com'
end
Capybara.current_driver = :selenium
@burtlo
burtlo / private.xml
Created September 26, 2012 13:30
TMUX: Rebinding CAPS LOCK to CTRL + B
<?xml version="1.0"?>
<root>
<appdef>
<appname>Terminal</appname>
<equal>com.apple.Terminal</equal>
</appdef>
<item>
<name>TMUX Key Remappings</name>
<item>
<name>TMUX: Right Control to Ctrl+B</name>
@burtlo
burtlo / a_test.rb
Created October 31, 2012 09:15
Looking at ways to provide auto-reloading to an application outside of the Rails space.
class A
def hello ; puts "hello" ; end
def goodbye ; puts "goodbye" ; end
end
@burtlo
burtlo / source.rb
Created November 29, 2012 18:07
Working around autoload. When forcing source files to be loaded is important.
def safely_load(mod,constant)
mod.const_get constant
rescue NameError
puts "#{mod}::#{constant} was not defined autoloadable, but caused NameError"
rescue LoadError
puts "#{mod}::#{constant} was not loadable"
end
def preload(mod)
@burtlo
burtlo / check_phone_number.rb
Last active December 12, 2015 03:09
This is code for checking the validity of phone numbers for Event Manager
def check_valid_phone_number(phone_number)
number_length = phone_number.length
if number_length == 10
phone_number
elsif number_length == 11 and phone_number[0] == '1'
phone_number[1..10]
else
invalid_number
end
packages = %w[ack gmp libvpx pkg-config
apple-gcc42 gnupg libxml2 postgresql
asciidoc gnutls libxmlsec1 proctools
autojump graphviz lighttpd qt
boo hub little-cms ragel
boost imagemagick lzo readline
bsdmake ios-sim mogenerator redis
clojure jasper mono rename
cmake john mpc rtmpdump
docbook jpeg multimarkdown scala
@burtlo
burtlo / rails_features.md
Created February 17, 2013 06:39
Some common errors after finishing the Jumpstart Lab Blogger tutorial a number of times.

Rake Routes

Problem

Running rake routes with a new rails application displays no information.

Solution

@burtlo
burtlo / Rakefile
Last active December 14, 2015 01:39
An example of a Rakefile
$:.push('lib')
require 'sales_engine'
def display_load_path
puts "Current `$LOAD_PATH` (or `$:`):"
puts "Load Path: #{$:.join("\n")}"
end
desc "Add TEST directory to the load path"
task :load_path do
@burtlo
burtlo / sales_engine.rb
Created February 22, 2013 02:56
Example of using Ruby's Meta-programming to build finders and reduce duplication.
module HasAttributes
def attribute(name) #id
# With the given name add an instance method with that name
# define_method(name) do
# instance_variable_get("@#{name}")
# end
attr_reader name
# With the given name add a class method find_by_NAME
@burtlo
burtlo / example2.rb
Created February 26, 2013 16:31
Space Ages - functional style
require 'date'
# puts "What are you? #{ARGV} #{ARGV.class}"
# Called as in `ruby example2.rb 1977 10 30`
# birthdate = ARGV.map {|arg| arg.to_i }
birthdate = [ 1977, 10, 30 ]
# year, month, day = [ 1977, 10, 30 ]
# birth_in_seconds = Date.new(year,month,day).to_time.to_i