Skip to content

Instantly share code, notes, and snippets.

View rodloboz's full-sized avatar

Rui Freitas rodloboz

View GitHub Profile
# USER STORIES
# - see a list of horses
# - place a bet
# - see the winning horse
# pseudo-code
# - initialize user waller with 100€
# Create List of items (STORE)
# => Hash key: name of item, value: price of item (integer)
# Welcome user
# Show user list of of items
# LOOP (more choices)
#--- LOOP
# Ask user to pick item
# Get user choice
# validate that choice exists
#--- END LOOP
# SETUP:
# touch french_ssn.rb
# mkdir spec
# touch spec/french_ssn_spec.rb
# mkdir data
# touch data/french_departments.yml
# curl -L https://gist.githubusercontent.com/Eschults/279682088e2f87564161e4dbf8390d68/raw/bdbc97ed036a5b21978defd9987e800c7fa67dce > 'data/french_departments.yml'
require 'date'
require 'yaml'
@rodloboz
rodloboz / interface.rb
Created April 24, 2018 16:29
Reboot Day 2
# USER STORIES
# - List the items
# - Add an item
# - Import item (from Etsy)
# - Mark an item as bought/done
# - Unmark an item
# - Delete an item
# show menu
# - Initialize a list of items
@rodloboz
rodloboz / interface.rb
Created April 24, 2018 18:20
LIVECOOOOODE...
# SETUP
# touch scraper.rb
# touch interface.rb
# mkdir spec
# touch spec/scraper_spec.rb
# stt
require "yaml"
require_relative "scraper"
@rodloboz
rodloboz / scraper.rb
Created April 25, 2018 10:02
livecode scraping
require 'open-uri'
require 'nokogiri'
require 'pry-byebug'
BASE_URL = "https://www.imdb.com"
def fetch_urls
url = "https://www.imdb.com/chart/top"
html_file = open(url).read # string
html_doc = Nokogiri::HTML(html_file) #Nokogiri::HTML::Document
@rodloboz
rodloboz / patient.eb
Created May 1, 2018 10:09
Modeling Data
class Patient
attr_reader :name, :cured
attr_accessor :id, :room # attr_red + attr_writer
# STATE:
# - name (String)
# - cured (Boolean)
# STRATEGY 1
# def initialize(name, cured)
# "Hello" # string
# true # boolean
# false # boolean
# 3 # integer
# 3.14 # float
# ["Hello", 3, 3.14, true] # array
# (1..10) # range
# # String interpolation
require 'date'
def days_until_xmas(date = Date.today)
# TODO: calculate the number of days
# until Christmas
current_year = Time.now.year
if (Date.new(current_year, 12, 25) - date).to_i < 0
(Date.new(current_year + 1, 12, 25) - date).to_i
else
(Date.new(current_year, 12, 25) - date).to_i
puts "How old are you?"
age = gets.chomp.to_i
# Conditional Statements
# if / else structure
if age >= 18
puts "You can vote!"
else