Skip to content

Instantly share code, notes, and snippets.

@jonny-gates
jonny-gates / beatles.rb
Created July 10, 2019 09:35
Exercises from Flow & Arrays lecture
# Define an array
beatles = ["john", "ringo", "seb"]
# 0 1 2
# Read an element
beatles[1]
# Modify an element
beatles[2] = "george"
@jonny-gates
jonny-gates / acronomyze.rb
Created July 10, 2019 17:11
Flow, Conditionals & Arrays - Live Code Solutions
def acronomyze(string)
# split our sentence on space
string_split = string.split(" ")
string_split.map do |word|
word[0] # first letter of each string
end
# same as:
# letters = []
-- Give me all patients aged 30
SELECT * FROM patients WHERE age = 30
-- Give me doctors' name and specialty whose specialty ends in magic and name contains strange
SELECT name, specialty
FROM doctors
WHERE specialty LIKE '%Magic'
AND name LIKE '%Strange%'
-- Give me the number of inhabitants in my table
This file has been truncated, but you can view the full file.
5351 4c69 7465 2066 6f72 6d61 7420 3300
0400 0101 0040 2020 0000 3d36 0000 0501
0000 020a 0000 013d 0000 009e 0000 0004
0000 0000 0000 0000 0000 0001 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 3d36
002d f988 0500 0000 0503 e700 0000 0025
03ec 03f1 03fb 03f6 03e7 03e2 03dd 03d3
03d3 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
require "sqlite3"
db = SQLite3::Database.new("chinook.sqlite")
# List all customers (name + email), ordered alphabetically (no extra information)
def query_1(db)
query = <<-SQL
SELECT first_name, last_name, email
FROM customers
ORDER BY first_name asc
SQL
@jonny-gates
jonny-gates / repository.rb
Created October 18, 2019 09:40
to-do-manager
class Repository
def initialize
@tasks = []
end
def add(task)
@tasks << task
end
def all
@jonny-gates
jonny-gates / app.rb
Created October 20, 2019 16:49
cookbook-day-1-recap
require_relative 'cookbook' # You need to create this file!
require_relative 'controller' # You need to create this file!
require_relative 'router'
csv_file = File.join(__dir__, 'recipes.csv')
cookbook = Cookbook.new(csv_file)
controller = Controller.new(cookbook)
router = Router.new(controller)
require_relative 'patient'
class Room
attr_accessor :id
class RoomCapacityError < Exception; end
# STATE
# capacity - integer
# clean - boolean
# patients - array
require_relative 'app/repositories/meal_repository'
require_relative 'app/controllers/meals_controller'
require_relative 'router'
csv_file = 'data/meals.csv'
meal_repository = MealRepository.new(csv_file)
meals_controller = MealsController.new(meal_repository)
router = Router.new(meals_controller)
@jonny-gates
jonny-gates / app.rb
Created January 24, 2020 10:45
ToDo Manager
require_relative 'view'
require_relative 'repo'
require_relative 'controller'
require_relative 'router'
view = View.new
repo = Repo.new
controller = Controller.new(view, repo)
router = Router.new(controller)