Skip to content

Instantly share code, notes, and snippets.

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

Trevor Menagh trevmex

👨‍👩‍👧‍👦
View GitHub Profile
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)
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
# 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))
/*
* user.watch v1.0: Cross-browser user.watch
* From http://code.eligrey.com/object.watch/
*
* By Elijah Grey, http://eligrey.com
* Tweaked by Trevor Lalish-Menagh, http://trevmex.com
*
* A shim that partially implements object.watch and object.unwatch
* in browsers that have accessor support.
*
myNS.caller = function () {
myNS.funct1();
myNS.funct2();
myNS.funct3();
};
describe("myNS.log", function () {
it("sends a string to the console log", function () {
spyOn(window.console, "log");
expect(myNS.log("test message")).toEqual("test message");
expect(window.console.log).toHaveBeenCalledWith("test message");
});
});