Skip to content

Instantly share code, notes, and snippets.

View krokrob's full-sized avatar
🥞
Data Warehousing

Kevin ROBERT krokrob

🥞
Data Warehousing
View GitHub Profile
def timer
start_time = Time.now
puts 'starting a long algorithm....'
yield
puts 'process done!'
end_time = Time.now
return end_time - start_time
end
# timer do
musicians = ['David Gilmour', 'Roger Waters', 'Richard Wright', 'Nick Mason']
upcased_first_names = musicians.map do |musician|
first_name = musician.split.first
upcased_first_name = first_name.upcase
puts "[DEBUG] #{musician}'s first name is #{upcased_first_name}"
upcased_first_name
end
p upcased_first_names
musicians = ['David Gilmour', 'Roger Waters', 'Richard Wright', 'Nick Mason']
# EACH
musicians.each do |musician|
puts "Hello #{musician}"
end
puts '-------------'
# EACH WITH INDEX
# musicians.each do |musician|
# generer un nombre aleatoire entre 1 et 100
price = rand(1..100)
# demander un nombre a l utilisateur
# comparer les 2 nombres
guess = 0
until price == guess
puts "What's your guess?"
guess = gets.chomp.to_i
# si bonne reponse: indiquer que c'est gagné
# si mauvaise reponse
# TODO: Implement a method which returns
# the number of days until next Xmas
require 'date'
def compute_result(year, today)
xmas = Date.new(year,12,25)
xmas - today
end
def days_until_xmas
# interface.rb
# Pseudo-code:
# 1. Print welcome and the horses names
# display a welcome message
puts "Welcome to the horse race!"
# store horses names in an array
horses = [
'Grand Cardinal',
'Jolly Jumper',
require_relative 'calculator'
# Calculator (addition)
#
# ask user to enter a number
puts "First number?"
# store first number
first_number = gets.chomp
# check first number class
first_number = checker_to_f(first_number)
# ask user for operation
def calculator(number_one, number_two, operation)
# check which operator
case operation
when '+'
# compute the right operation
result = number_one + number_two
when '-'
result = number_one - number_two
when '*'
result = number_one * number_two
# compute computer choice
random_price = (1..100).to_a.sample
guess_price = 0 # initialization
until guess_price == random_price
# ask user input and put into an integer
puts " What price is the object?"
guess_price = gets.chomp.to_i
# compare the 2 entries
if guess_price == random_price
require 'date'
def compute_diff(date_today, year)
date_christmas = Date.new(year, 12, 25)
return (date_christmas - date_today).to_i
end
# puts compute_diff(Date.today, 2019)
def days_to_xmas