Skip to content

Instantly share code, notes, and snippets.

# Should the contestant switch to the other door?
@switch = true
@wins = 0; @losses = 0
100000.times do
# Hide the car
car_behind = rand(3)
# Contestant picks a door
contestant_pick = rand(3)
def model_exists?(model_name)
begin
potential_model = model_name.constantize
rescue NameError
return false
end
ActiveRecord::Base.send(:subclasses).include?(potential_model)
end
def model_exists?
begin
potential_model = yield
return ActiveRecord::Base.send(:subclasses).include?(potential_model)
rescue NameError
return false
end
end
# A mixin that makes a record "seeable" by users.
module Seeable
def self.included(base)
base.has_many :seeings, :as => :thing
end
# Note that user seeing this thing (now)
# Returns true if the user has previously seen the object, and false otherwise
# essentially the same as doing a seen_by? before noting the new seeing.
def seen_by!(user)
class ModelExtensionLoader
def self.activate!
class << ActiveRecord::Base
alias_method :old_inherited, :inherited
def inherited(model)
puts "Trying to load extensions #{model} extensions"
if extension = ModelExtensionLoader.safe_constantize("Extensions::#{model}")
model.send(:include, extension)
Rafer Hazen: It seems like I used to be able to SSH in to their account, and now I cannot. I have a working username and password.
Harriet Anderson: I apologize for any inconvenience this has caused you.
Harriet Anderson: To protect your account from unauthorized changes, can you please verify for me the answer to the Security Question:
Harriet Anderson: What is your pet's name?
Rafer Hazen: The client never gave me that information.
@rafer
rafer / gist:920399
Created April 14, 2011 20:19
ROB 4/14/2011 Trivia: Question 2
# Question 2: What does the following print?
class Bob
class << self
puts self.name
end
end
@rafer
rafer / gist:920410
Created April 14, 2011 20:23
ROB 4/14/2011 Trivia: Question 3
# Question 3. What does the following print?
p [String === "String", "String" === String]
p ["String".equal?("String"), "String".eql?("String"), "String" == "String"]
@rafer
rafer / gist:920414
Created April 14, 2011 20:24
ROB 4/14/2011 Trivia: Question 4
# Question 4. What does the following print
p [:a, :b][2,1]
p [:a, :b][3,1]
@rafer
rafer / gist:920423
Created April 14, 2011 20:25
ROB 4/14/2011 Trivia: Question 5
# Question 5. What's the output of the following?
def lambdicate
print "A"
lambda { return }.call
print "B"
end
def proctify
print "A"