Skip to content

Instantly share code, notes, and snippets.

View phildionne's full-sized avatar

Philippe Dionne phildionne

View GitHub Profile
# 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)
# 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']
class WrongNumberOfPlayersError < StandardError ; end
class NoSuchStrategyError < StandardError ; end
public
def rps_result(m1, m2)
# YOUR CODE HERE
end
def invalid?(turn)
RSpec.configure do |config|
config.around do |example|
VCR.use_cassette('stripe-customer') do |cassette|
example.run
end
end
end
@phildionne
phildionne / bootstrap_link_renderer.rb
Last active December 18, 2015 12:48
WillPaginate link renderer for Twitter Bootstrap. Use in Sinatra/Padrino.
@phildionne
phildionne / cachemire.rb
Last active December 24, 2015 02:09 — forked from plehoux/cachemire.rb
module Cachemire
extend ActiveSupport::Concern
included do
class_attribute :cache_store
end
module ClassMethods
private
@phildionne
phildionne / Gemfile
Last active December 24, 2015 03:29 — forked from stephencelis/minidress.rb
Minidress
source 'https://rubygems.org'
gem 'bundler', '~> 1.3'
gemspec
@phildionne
phildionne / lazy.rb
Last active August 29, 2015 13:56 — forked from fbernier/lazy.rb
# 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
@phildionne
phildionne / apartment.rb
Last active August 29, 2015 14:16
Rails + Apartment + PostGIS + activerecord-postgis-adapter
Apartment.configure do |config|
config.persistent_schemas = %w{ shared_extensions }
end
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],