Skip to content

Instantly share code, notes, and snippets.

View trevmex's full-sized avatar
👨‍👩‍👧‍👦

Trevor Menagh trevmex

👨‍👩‍👧‍👦
View GitHub Profile
describe "route" do
# explicit listing
specify "days#index" do
route get('/days').should generate 'days#index' # wraps assert_generates
route 'days#index'.should recognize get('/days') # wraps assert_recognizes
end
# combined listing
specify "days#index" do
route get('/days').should be 'days#index' # This is generate and recognize (wraps assert_routing)
describe "routing" do
it "recognizes and generates #index" do
get("/days").should have_routing('days#index')
end
it "generates #index" do
get("/days").should generate('days#index')
end
it "recognizes #index" do
# options_for_select_tag: Create an options string for the Rails select_tag method.
# This is a wrapper for Rails' options_for_select method.
# The options are the same as the Rails select method, but this allows us to use it with the select_tag method.
#
# @param {String[]} container An array of strings representing the list of options.
# @param {String|String[]|Hash} selected_or_options A single value or an array of values that will be selected options in the final output, or a hash of options as follows:<br />
# - :selected - can be a single value or an array of values that will be selected options in the final output.
# - :include_blank - set to true or a prompt string if the first option element of the select element is a blank. Useful if there is not a default value required for the select element.<br />
# - :prompt - set to true or a prompt string. When the select element doesn‘t have a value yet, this prepends an option with a generic prompt — "Please select" — or the given prompt string.<br />
# - :d
describe 'routing another way' do
it { should have_resources(:days) }
it { should get('/days' => 'days#index') }
it { should match('/days' => 'days#index', :via => :get) }
it { should recognize('/days', :via => :get).as('days#index') }
it { should generate('days#index').from('/days', :via => :get) }
it { should recognize('/students/1/days', :via => :get).as('days#index', :student_id => '1') }
end
# Extend String to include an encryption method
#
# For this to work, you must place this in the lib directory of your Rails project.
# You will also need three files in your config directory:
# * public.pem: Your public key file
# * private.pem: Your private key file
# * passphrase.txt: Your passphrase
class String
require 'openssl'
require 'base64'
require 'ostruct'
players = Array.new
def new_player(roster, options)
player = OpenStruct.new
player.name = options[:name]
player.sex = options[:sex]
roster.push(player)
# Extract Method (http://refactoring.com/catalog/extractMethod.html)
#
# not refactored
#
def self.display_name(login)
ad_entry = self.find(login)
first_name_match = /FirstName:\s*(.*)$/.match(self.find(login))
last_name_match = /LastName:\s*(.*)$/.match(self.find(login))
class CutItUp
def singleton_class
class <<self; self; end
end
def lol
puts "LOL"
end
def delete_method(method)
class Foo
def my_attr_accessor(*args)
args.each do |arg|
# def the_arg
# @the_arg
# end
self.instance_eval("def #{arg}; @#{arg}; end")
# def the_arg=(the_arg)
# @the_arg = the_arg
require 'rest-client'
require 'json'
twit = Object.new
def twit.get_user_timeline(user_id)
@user_timeline = JSON.parse(RestClient.get("http://api.twitter.com/1/statuses/user_timeline.json?user_id=#{user_id}"))
self.instance_eval do
def statuses