Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Weather</title>
<link rel="shortcut icon" href="data:image/x-icon;" type="image/x-icon">
// declare our event listener and wait for KEYUP
document.addEventListener("keyup", event => {
// Someone press a key => Event
console.log(event.keyCode)
// check if the keycode is correct
// if player1 keycode
if (event.keyCode === 81) {
const active = document.querySelector("#player1-race > .active")
@marcoranieri
marcoranieri / dom.js
Created June 26, 2020 21:59
dom&event
/* eslint-disable no-multiple-empty-lines */
/* eslint-disable prefer-const */
// INSTRUCTIONS - PLEASE READ!!
// Here are some challenges. Solve them from top to bottom
// **Each time** you complete a challenge, please commit and push!
// This is a good practise. Each time you make some progress in software
// development, you want to save a snapshot.
@marcoranieri
marcoranieri / api.rb
Created June 6, 2020 16:59
Active Record
require "json"
require "rest-client"
def get_request_to(url)
response = RestClient.get(url)
JSON.parse(response)
end
def build_post(story_id)
@marcoranieri
marcoranieri / hash.rb
Created February 21, 2020 10:36
Hash & Symbols
students = [ "Peter", "Mary", "George", "Emma" ]
student_ages = [ 24 , 25 , 22 , 20 ]
# "Peter is 24 yo!"
# "Mary is 25 yo!"
# ...
students.each_with_index do |student, index|
puts "#{student} is #{student_ages[index]}"
end
@marcoranieri
marcoranieri / acron.rb
Last active February 19, 2020 19:10
Flow & Array
def acronomize(sentence)
return "" if sentence == ""
#retrieve each word from sentence (from string to array)
sentence_array = sentence.split(" ")
#take just first letter from each word and capitalize
acronym = []
sentence_array.each do |word|
#store in new array
@marcoranieri
marcoranieri / crud_array.rb
Created February 19, 2020 09:58
Flow & Array
cities = %w(rome paris perugia)
# ["rome", "paris", "perugia"]
# index 0 1 2
# -3 -2 -1
# READ
cities[1]
# CREATE
# cities.push("New York")
@marcoranieri
marcoranieri / price.rb
Created February 18, 2020 23:05
Programming Basics
# TODO Guess the price!
# Generate a random number (computer choice)
computer = rand(1..5)
loop do
# prompt the user to guess a number
puts "Guess a number!"
# from String (gets.chomp) to Integer (.to_i)
user = gets.chomp.to_i
@marcoranieri
marcoranieri / api_demo.rb
Created January 21, 2020 15:37
Parsing&Storing
require 'json'
require 'open-uri'
puts "Username?"
input = gets.chomp
# TODO - Let's fetch name and bio from a given GitHub username
url = "https://api.github.com/users/#{input}"
user_serialized = open(url).read # String
@marcoranieri
marcoranieri / acron.rb
Created January 15, 2020 18:30
flow and array LIVECODE
def acronymize(sentence)
return "" if sentence == ""
# split sentence into array of words
words = sentence.split
result = []
# for each word
words.each do |word|