Skip to content

Instantly share code, notes, and snippets.

View gbrl's full-sized avatar

Gabriel Rambert gbrl

  • Earth
View GitHub Profile
2.2.0 :001 > def sayhi
2.2.0 :002?> puts "HI!"
2.2.0 :003?> end
=> :sayhi
2.2.0 :004 > def greeting(name)
2.2.0 :005?> puts "Hi, #{name}."
2.2.0 :006?> end
=> :greeting
2.2.0 :007 > greeting("Bill")
Hi, Bill.
@gbrl
gbrl / renter.rb
Last active April 26, 2016 23:32 — forked from davidvandusen/renter.rb
# must be baller and either furnished or rent cheaper than 2100
def rent?(furnished, rent, baller)
puts "Furnished is #{furnished}, rent is #{rent}, baller status is #{baller}"
if baller && (furnished || rent < 2100)
puts "Yeah, let's do it. \n"
return true
else
puts "Nah, I don't want it. \n"
return false
end
@gbrl
gbrl / sort.rb
Last active April 26, 2016 22:19 — forked from davidvandusen/sort.rb
# Sort the array from lowest to highest
def sort(arr)
a_length = arr.length
return arr if a_length == 1
return [] if a_length == 0
keep_going = true
while keep_going do
flagged = false
arr.each_with_index do |num,index|
unless (index + 1 == arr.length ) # Can't compare last number with next one since it doesn't exist.
def calculate(size,num_colours)
colour_price = 10
colour_price = 15 if num_colours > 2
total = ((size * 15) + (num_colours * colour_price)) * 1.15
total_in_currency = "%05.2f" % total
puts "Your total is $#{total_in_currency}"
end
# Enter size of sign, and number of colours as parameters
calculate(10,3)
require 'pp'
def count_letters(stuff)
result = {}
individual_characters = []
individual_characters = stuff.split("")
individual_characters.each do |char|
next if char == " "
if result[char].nil?
result[char] = 1
@states = {
OR: 'Oregon',
FL: 'Florida',
CA: 'California',
NY: 'New York',
MI: 'Michigan'
}
@states[:OH] = 'Ohio'
@states[:NC] = 'North Carolina'
@states = {
OR: 'Oregon',
FL: 'Florida',
CA: 'California',
NY: 'New York',
MI: 'Michigan'
}
@states[:OH] = 'Ohio'
@states[:NC] = 'North Carolina'
require 'pp'
# BUYING
# num_bottles = money/2
# REDEEMING
# num_bottles = caps * 0.25
# num_bottles = bottles * 0.5
def buy(investment=0)
require 'pp'
# I = 1
# V = 5
# X = 10
# L = 50
# C = 100
# D = 500
# M = 1000
def benchmark
start = Time.now
yield
running_time = Time.now - start
end
# Be careful, pasting this into IRB will take a long time to print.
# It's a loooong string. :)
long_string = "apple"*100000000