Skip to content

Instantly share code, notes, and snippets.

View FioFiyo's full-sized avatar

Fiorella FioFiyo

View GitHub Profile
@FioFiyo
FioFiyo / IRB work
Created March 29, 2016 18:19
IRB testing: arrays, include, modules, looping, def methods, calling destructive methods
Fiorellas-MacBook-Pro:lighthouse LHL$ irb
irb(main):001:0> def say_hi(name)
irb(main):002:1> "Hello, #{name}"
irb(main):003:1> end
=> nil
irb(main):004:0> say_hi("Meow")
=> "Hello, Meow"
irb(main):005:0> say_hi()
ArgumentError: wrong number of arguments (0 for 1)
from (irb):1:in `say_hi'
@FioFiyo
FioFiyo / Maximum
Created March 29, 2016 21:04
using anything other than sort type of methods to run through an array and scan the highest number.
# Find the maximum
#Scan the array to compare integers and find the maximum
#within that array if there are objects inside the array
#otherwise set it to nil.
def maximum(arr)
#arr.max
#create the sort option
#comparing the actual number not the index using arr[i]
itswaps = true
@FioFiyo
FioFiyo / FizzBuzz
Created March 29, 2016 23:19
Refactoring original FizzBuzz by making my own numbers as opposed to 1-100
def fizzbuzz1
#
puts "Please put your range:"
#number1 = gets.chomp.to_i
first_num = gets.chomp.to_i
last_num = gets.chomp.to_i
n = (first_num..last_num)
array = n.sort
array.each do |fixnum|
@FioFiyo
FioFiyo / Renter
Created March 29, 2016 23:54
Adjusted the "bug"
# must be baller and either furnished or rent cheaper than 2100
def rent?(furnished, rent, baller)
if baller && (furnished && (rent < 2100))
puts "YES"
return true
else
puts " NAH"
return false
end
end
@FioFiyo
FioFiyo / Shakil the Dog
Last active March 30, 2016 02:17
Created a method to run a command sent by user for the dog to output certain things depending on the input.
# Save this file to your computer so you can run it
# via the command line (Terminal) like so:
# $ ruby shakil_the_dog.rb
#
# Your method should wait for user input, which corresponds
# to you saying something to your dog (named Shakil).
# You'll probably want to write other methods, but this
# encapsulates the core dog logic
def shakil_the_dog
@FioFiyo
FioFiyo / debug01
Created March 31, 2016 01:05
Debugging
list = {
yvr: 'Vancouver',
yba: 'Banff',
yyz: 'Toronto',
yxx: 'Abbotsford',
ybw: 'Calgary',
}
#COUNT LETTERS
def count_letters(sentence)
letters = {}
sentence = [sentence]
sentence.each do |words|
word = words.split('')
word.each do |letter|
@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
@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 / 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