This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative 'friendly_date_ranges' | |
require 'minitest/autorun' | |
class FriendlyDatesTest < Minitest::Test | |
def test_teen_day_formatting | |
input = '2015-07-11 2015-08-12' | |
results = FriendlyDates.new(input) | |
assert_equal '11th', results.date1.day | |
assert_equal '12th', results.date2.day | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BiDailyScheduler < HerokuScheduler | |
def should_run? | |
(Time.now.hour % 12) == hour | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Post < ActiveRecord::Base | |
extend PostUtils | |
default_scope { order(:id) } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Post < ActiveRecord::Base | |
extend PostUtils | |
default_scope { order(:id) } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Imagine you have a call center with three levels of employees: fresher, technical lead (TL), | |
# product manager (PM). There can be multiple employees, but only one TL or PM | |
# An incoming telephone call must be allocated to a fresher who is free. If a fresher | |
# can’t handle the call, he or she must escalate the call to technical lead. If the TL is | |
# not free or not able to handle it, then the call should be escalated to PM. Design the | |
# classes and data structures for this problem. Implement a method getCallHandler(). | |
class CallHandler | |
attr_reader :product_manager, :tech_lead, :freshers, :calls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FloorPlan | |
attr_reader :input, :layout, :rows, :cols | |
EMPTY = '.' | |
VISITED = '-' | |
def initialize(file) | |
@input = format(file) | |
@layout = format(file) | |
@rows = @layout.size |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative 'other_word_problem' | |
require_relative 'word_problem' | |
require 'benchmark' | |
TEST_COUNT = 10000 | |
Benchmark.bmbm do |b| | |
b.report("myWordy") do | |
TEST_COUNT.times do |i| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Node = Struct.new(:value, :next) | |
class LinkedList | |
def initialize(*values) | |
@head = Node.new(values.shift, nil) | |
values.each { |v| add(v) } | |
end | |
def add(value) | |
current = @head |