Skip to content

Instantly share code, notes, and snippets.

View dedemenezes's full-sized avatar

André Menezes dedemenezes

View GitHub Profile
@dedemenezes
dedemenezes / SETUP_DAY.md
Created April 14, 2021 22:21
Starting my coding journey...
@dedemenezes
dedemenezes / index.html
Created April 5, 2022 22:57
Dom & Events Lecture
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css">
<title>Playground - JavaScript 101</title>
</head>
<body>
@dedemenezes
dedemenezes / array.rb
Created April 21, 2022 14:08
Code from the lecture iterators and blocks
students = ["Harry Potter", "Ronald Weasley", "Hermione Granger"]
# INDEXES 0 1 2
# CRUD
# CREATE -> add new element
students << "Draco Malfoy"
students.push("Draco Malfoy")
p students
@dedemenezes
dedemenezes / acronymize.rb
Created April 21, 2022 22:55
Livecode done
def acronymize(sentence)
if sentence == ""
return ""
else
# 1. split sentence into words
words = sentence.split(" ")
# 2. create new array with first letters only
letters = words.map do |word|
word[0].capitalize
@dedemenezes
dedemenezes / array_to_hash.rb
Created April 22, 2022 13:56
Hash & Symbols lecture code
students = [ "Peter", "Mary", "George", "Emma" ]
student_ages = [ 24 , 25 , 22 , 20 ]
# INDEXES 0 1 2 3
# Index is the only thing connecting both arrays
# We need to use it to print our list
students.each_with_index do |name, index|
age = student_ages[index]
puts "#{name} is #{age} years old"
@dedemenezes
dedemenezes / french_departments.yml
Created April 25, 2022 21:31
Regex Livecode naming groups
'01': Ain
'02': Aisne
'03': Allier
'04': Alpes-de-Haute-Provence
'05': Hautes-Alpes
'06': Alpes-Maritimes
'07': Ardèche
'08': Ardennes
'09': Ariège
'10': Aube
require 'date'
require 'yaml'
SSN_PATTERN = /^(?<gender>[1-2])\s?(?<birth_year>\d{2})\s?(?<birth_month>0[1-9]|1[0-2])\s?(?<department>0[1-9]|[1-9]\d)\s?(?<random_numbers>(\d{3}\s?){2})(?<key>\d{2})$/
def french_ssn_info(ssn_number)
return 'The number is invalid' if ssn_number.empty?
match_data = ssn_number.match(SSN_PATTERN)
@dedemenezes
dedemenezes / christmas_list.rb
Created April 26, 2022 19:58
Reboot step, 1, 2 and 3 done. Missing Scrape and save to csv
def list(items)
items.each_with_index do |gift_hash, index|
# 2.1. Display each gift information
# TERNARY IF
# CONDITION ? code_executed_if_true : code_executed_if_false
status = gift_hash[:bought] ? "[X]" : '[ ]'
#=> TRUE/FALSE
puts "#{index + 1} - #{status} #{gift_hash[:name]} - $#{gift_hash[:price]}"
end
end
@dedemenezes
dedemenezes / scraper.rb
Created April 27, 2022 18:48
Scraping top 5 movies from IMDB - livecode
require 'open-uri'
require 'nokogiri'
# 1. Capture the href/path/url for the top 5 movies
def fetch_movie_urls
url = 'https://www.imdb.com/chart/top'
# 1. 'visit' the page, and retriving all the content
html_file = URI.open(url, "Accept-Language" => "en-US").read
# 2. parse the html using nokogiri
html_doc = Nokogiri::HTML(html_file)
require "csv"
# TODO - let's read/write data from beatles.csv
filepath = "data/beatles.csv"
# PARSING CSV
# CSV.foreach(filepath, headers: :first_row) do |row|
# # puts "first name: #{row[0]}, last name: #{row[1]}, instrument: #{row[2]}" // BEFORE ADDING headers: :first_row
# puts "first name: #{row['First Name']}, last name: #{row['Last Name']}, instrument: #{row['Instrument']}"