Skip to content

Instantly share code, notes, and snippets.

require 'json'
require 'open-uri'
puts "Username please"
username = gets.chomp
# TODO - Let's fetch name and bio from a given GitHub username
url = "https://api.github.com/users/#{username}"
user_serialized = open(url).read
@marcoranieri
marcoranieri / array_recap.rb
Created July 11, 2019 10:19
ITERATORS & BLOCKS
musicians = ['David Gilmour', 'Roger Waters', 'Richard Wright', 'Nick Mason']
puts musicians.length
# CRUD
# create
musicians << "Eminem"
puts musicians.length
@marcoranieri
marcoranieri / acronymize_with_map.rb
Created July 11, 2019 17:26
Livecode - Acronymize with map & Encrypt
def acronymize(sentence)
return "" if sentence.empty?
sentence.split.map { |word| word[0].upcase}.join
end
puts acronymize("be right back")
<!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="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
@marcoranieri
marcoranieri / API_demo.rb
Created July 16, 2019 10:48
Parsing&Storing
require 'json'
require 'open-uri'
# Documentation - GitHub API
# https://developer.github.com/v3/
url = 'https://api.github.com/users/ssaunier' # endpoint of Github API
# We open & read what is returning the API call
user_serialized = open(url).read # is a STRING
require "yaml"
require_relative "scraper"
# fetch array of urls
puts "Fetching URLs"
urls = fetch_movie_urls
# return an array of hashes of movie details
movies = urls.map do |url|
puts "Scraping #{url}"
class AddRatingToRestaurants < ActiveRecord::Migration[5.1]
def change
add_column :restaurants, :rating, :integer
end
end
class CreateRestaurants < ActiveRecord::Migration[5.1]
def change
create_table :restaurants do |t|
t.string :name
t.string :city
t.timestamps null: false
end
end
end
@marcoranieri
marcoranieri / array.rb
Created October 9, 2019 10:32
Flow & Array
beatles = ["john", "ringo", "seb"]
#index 0 1 2 (length - 1)
#index -3 -2 -1
p beatles # puts beatles.inspect
# C R U D
# Create
@marcoranieri
marcoranieri / acronymize.rb
Created October 9, 2019 17:57
LIVECODE_Flow_conditional_array
def acronymize(sentence) # sentence => "be right back"
return "" if sentence == ""
# split sentence into array
splitted = sentence.split #=> ["be", "right", "back"]
# iterate .each and store first letters
first_letter = [] # before iteration
splitted.each do |word|