Skip to content

Instantly share code, notes, and snippets.

module Letters
class A
def to_s
"A"
end
end
end
describe Letters:A
subject { described_class.new }
@mpelzsherman
mpelzsherman / traverse.rb
Created July 1, 2014 04:48
Exploring Tree Algorithms with Ruby
class Node
@@visits = 0
@@queue = []
attr_accessor :value, :left_child, :right_child, :visited
def self.count_visit
@@visits += 1
@mpelzsherman
mpelzsherman / gist:c7e27fb7459abb0d5652
Created May 23, 2014 19:49
HappyEndingOrderingStrategy
class HappyEndingOrderingStrategy
def order(array)
array[1..-1].shuffle << array.last
end
end
@mpelzsherman
mpelzsherman / gist:c0896ae43a95b8572d7c
Created May 23, 2014 19:47
Random House using strategy pattern
class House
attr_accessor :os
def initialize(os=DefaultOrderingStrategy.new)
@os = os
end
def recite
(1..actors.length).map { |i| line(i) }.join("\n")
class Bottles
MAX_BOTTLE = 99
MIN_BOTTLE = 0
def song
verses(MAX_BOTTLE, MIN_BOTTLE)
end
def verses(high_bottle_number, low_bottle_number)
high_bottle_number.downto(low_bottle_number).map do |bottle_number|
class House
PHRASES = [
"the horse and the hound and the horn that belonged to",
"the farmer sowing his corn that kept",
"the rooster that crowed in the morn that woke",
"the priest all shaven and shorn that married",
"the man all tattered and torn that kissed",
"the maiden all forlorn that milked",
"the cow with the crumpled horn that tossed",
"the dog that worried",

Product management has come up with the idea of allowing website users to leave reviews and ratings for listings. This feedback will be entered similar to how leads are submitted, but the user must enter the following information:

  • name
  • email address
  • phone number
  • rating from 1 to 5
  • optional review

In addition to the above information, a CAPTCHA presenting three different apartment complexes (only one of which is correct) is used in conjunction with the user’s name and phone number to determine whether or not the user actually lived at the listing. After validating and verifying the information, the user gets redirected to a thank you page. After a review is successfully submitted, it will show up as the first entry in the reviews for the listing. Pre-existing “certified resident” reviews will be integrated along with reviews that are submitted through the site. On the search results page, users can sort on rating type or filter on review type and rating. A link on each listing will take the us

@mpelzsherman
mpelzsherman / save_all_listings.html
Last active December 11, 2015 15:49
A bookmarklet for saving all listings on an AG search results page.
<a href="javascript:$('.icon_favorites .sprite').each(function() { $(this).click(); });">Save all listings</a>