Skip to content

Instantly share code, notes, and snippets.

View FioFiyo's full-sized avatar

Fiorella FioFiyo

View GitHub Profile
@FioFiyo
FioFiyo / System Design.md
Created April 23, 2021 17:21 — forked from vasanthk/System Design.md
System Design Cheatsheet

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
@FioFiyo
FioFiyo / SQL exercise 10 - 11
Created July 6, 2016 03:45
Using SQL for a Bookstore DB
SELECT authors.id AS "ID",(authors.first_name)|| ' '||(authors.last_name) AS "Full name",COUNT(books.title) AS "Number of Books"
FROM books
JOIN authors ON (authors.id = books.author_id)
GROUP BY authors.id
ORDER BY COUNT(books.title) DESC
@FioFiyo
FioFiyo / barracks.rb
Created June 29, 2016 23:44
Warcraft3: Create classes and methods for the specs to pass.
class Barracks
attr_reader :gold, :food
def initialize
@gold = 1000
@food = 80
end
def train_footman
if can_train_footman?
@FioFiyo
FioFiyo / Shakil the dog pt 2
Last active June 22, 2016 00:18
Using loop and case within a method. Edit: removed variable from calling method, edited break so its within the loop and not outside(break if word == "go away"). Will edit to include clearer values in the loop to avoid 'woof' repetition.
require "pry-byebug"
#implement clear values within the loop
def barks_really_loud
puts "WOOF WOOF WOOF"
end
# create method to evaluate word
def behaviour
# # binding.pry
@FioFiyo
FioFiyo / FizzBuzz Refactored 2
Created June 21, 2016 20:46
Using each method & range(up to) with case and not if statements.
# 1.upto(100) do |i|
# if i % 5 == 0 && i % 3 == 0
# puts "FizzBuzz"
# elsif i % 5 == 0
# puts "Buzz"
# elsif i % 3 == 0
# puts "Fizz"
# else
# puts i
# end
@FioFiyo
FioFiyo / Maximum new
Created June 21, 2016 20:01
Using inject to replace max method as opposed to using loops to replace that method.
# Find the maximum
def maximum(arr)
arr.inject {|max,num| max = num > max ? num : max}
end
# expect it to return 42 below
result = maximum([2, 42, 22, 02])
puts "max of 2, 42, 22, 02 is: #{result}"
# expect it to return nil when empty array is passed in
vagrant [vagrant]> pry
[1] pry(main)> "hello"
=> "hello"
[2] pry(main)> puts "h"
h
=> nil
[3] pry(main)> quit
vagrant [vagrant]> ls
git-mania scavenger_hunt-master temp_test_file.txt Vagrantfile
vagrant [vagrant]> touch example.rb
@FioFiyo
FioFiyo / Animals
Last active April 5, 2016 18:58
Inheritance of animals and using modules to add features on subclasses
require 'pry'
require_relative 'methods.rb'
class Animal
attr_accessor :num_legs, :body
def initialize (num_legs, body = true)
@num_legs = num_legs
@body = body
end
@FioFiyo
FioFiyo / Candidates list
Created April 2, 2016 16:59
Sort candidates according to conditions.
require 'active_support/all'
@candidates = [
{
id: 5,
years_of_experience: 4,
github_points: 293,
languages: ['C', 'Ruby', 'Python', 'Clojure'],
date_applied: 5.days.ago.to_date,
age: 26
@FioFiyo
FioFiyo / Benchmark_with_block
Last active June 23, 2016 18:42
Cleaner code to run the block perhaps faster?
# require 'pry'
def benchmark
start_time = Time.now
# binding.pry
yield
end_time = Time.now
end_time - start_time
end