Skip to content

Instantly share code, notes, and snippets.

View rodloboz's full-sized avatar

Rui Freitas rodloboz

View GitHub Profile
@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 / 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 / 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
# 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'
# 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
# USER STORIES
# - see a list of horses
# - place a bet
# - see the winning horse
# pseudo-code
# - initialize user waller with 100€
def calculate(first_number, second_number, operator)
case operator
when "+"
first_number + second_number
when "-"
first_number - second_number
when "*"
first_number * second_number
when "/"
first_number / second_number
# #frequencies method
# should return and empty hash when passed an empty string
# should count words
# should count multiple words
# should be case insensitive
# should ignore short words and punctuation (. ! ? ,)
# #read_file method
# should read the dummy file
lisbon = {
# key => value
"country" => "Portugal", # string
"population" => 2821876 # integer
}
# puts Lisbon.class
# uninitialized constant Lisbon (NameError)
# the program does not know a variable/constant named Paris
# (because we have not defined one)
@rodloboz
rodloboz / restaurants_controller.rb
Last active April 11, 2018 07:19
Rails Slug Filtering
# Set up a /slug/ route to your #index in routes.rb
# get '/search/:slug', to: 'restaurants#index'
class RestaurantsController < ApplicationController
def index
if params[:slug]
lookup = SlugLookupService.new(params[:slug])
lookup.perform
category = lookup.category
redirect_to restaurants_path unless category