Skip to content

Instantly share code, notes, and snippets.

View seanlerner's full-sized avatar

Sean Lerner seanlerner

View GitHub Profile
@seanlerner
seanlerner / seans-ruby-helpers.rb
Last active March 11, 2022 16:59
Sean's Ruby Helpers
<<-HOW_TO_USE
Paste this line into any ruby console if you dare:
require 'net/http'; url = 'https://gist.githubusercontent.com/seanlerner/092ce4caec301d758b524adbd715242a/raw/seans-ruby-helpers.rb'; eval(Net::HTTP.get(URI(url)))
HOW_TO_USE
def exception_message(exception)
if exception.message.include?("undefined method `include'")
@seanlerner
seanlerner / flatten_array_without_flatten.rb
Created February 7, 2018 01:17
Flatten Array of Integers Without Using Flatten
def flatten_array(input)
input.to_s.gsub(/\[|,|\]/, ' ').split.map(&:to_i)
end
# TEST 1
input = [[1, 2, [3]], 4]
expected = [1, 2, 3, 4]
actual = flatten_array(input)
puts
@seanlerner
seanlerner / gilded_rose.rb
Last active April 24, 2017 15:37
Gilded Rose Ruby Solution
class GildedRose
attr_reader :name, :days_remaining, :quality
∞ = Float::INFINITY
CHEESE = {
'Normal Item' => { -∞..0 => -2, 1..∞ => -1 },
'Aged Brie' => { -∞..0 => 2, 1..∞ => 1 },
'Conjured Mana Cake' => { -∞..0 => -4, 1..∞ => -2 },