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
# A triangle method | |
def triangle(a, b, c) | |
if (a <= 0) || (b <= 0) || (c <= 0) | |
raise TriangleError, "a or b or c can't be 0 or negative" | |
elsif ((a + b) <= c) || ((a + c) <= b) || ((c + b) <= a) | |
raise TriangleError, "sum of first and second smallest must be > third" | |
elsif (a == b) && (b == c) |
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
# Anagram | |
def combine_anagrams(words) | |
h = Hash.new | |
words.each do |word| | |
(h[word.downcase.chars.sort.join] ||= []) << word | |
end | |
h.values | |
end | |
words = ['Cars', 'for', 'potatoes', 'rAcs', 'four', 'scar', 'crEams', 'scream'] |
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 WrongNumberOfPlayersError < StandardError ; end | |
class NoSuchStrategyError < StandardError ; end | |
public | |
def rps_result(m1, m2) | |
# YOUR CODE HERE | |
end | |
def invalid?(turn) |
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
RSpec.configure do |config| | |
config.around do |example| | |
VCR.use_cassette('stripe-customer') do |cassette| | |
example.run | |
end | |
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
module WillPaginate | |
module ViewHelpers | |
# WillPaginate link renderer for Twitter Bootstrap | |
class BoostrapLinkRenderer < WillPaginate::Sinatra::LinkRenderer | |
protected | |
def page_number(page) | |
unless page == current_page | |
tag(:li, link(page, page, :rel => rel_value(page))) |
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
module Cachemire | |
extend ActiveSupport::Concern | |
included do | |
class_attribute :cache_store | |
end | |
module ClassMethods | |
private |
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
source 'https://rubygems.org' | |
gem 'bundler', '~> 1.3' | |
gemspec |
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
# Enumerator#lazy is very slow and should only be used when iterating over large/infinite collections | |
# where you know you are going to get your results quite early in the iteration. | |
require 'benchmark/ips' | |
Benchmark.ips do |r| | |
r.report("map") do | |
(0..50).map{ |i| 'lol' if i.even? } | |
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
Apartment.configure do |config| | |
config.persistent_schemas = %w{ shared_extensions } | |
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
FactoryGirl.define do | |
# Points according to Geojson specifications (X, Y) or (Longitude, Latitude) | |
sequence :point do | |
[ | |
[38.15704300068319, 82.64793458394706], | |
[65.25863617658615, -24.040317703038454], | |
[-144.94273960590363, 20.84642690140754], | |
[137.46707799844444, 80.3652603412047], | |
[-131.11246040090919, 3.13029068056494], | |
[-37.99821515567601, 70.2160071535036], |
OlderNewer