Skip to content

Instantly share code, notes, and snippets.

Ryan Kulp ryanckulp

Block or report user

Report or block ryanckulp

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ryanckulp
ryanckulp / jp_morgan.rb
Created Feb 27, 2018
sanitizes JP morgan string variants to singular intention
View jp_morgan.rb
str_a = 'j.p. morgan'
str_b = 'jp morgan chase'
str_a == str_b # => false
str = 'j.p. morgan'
str.downcase.gsub("j.p.", "jp").gsub("j.p", "jp").gsub("jp.", "jp").gsub("jp morgan", "jp morgan chase") # => "jp morgan chase"
def jp_morgan_chase?(str)
@ryanckulp
ryanckulp / unless_good.rb
Last active Jan 2, 2018
intuitive use case for unless...end statement in Ruby
View unless_good.rb
require 'date'
def date_night?
Date.today.wday == 5 # friday
end
unless date_night?
puts "study hard!"
end
@ryanckulp
ryanckulp / unless.rb
Created Jan 2, 2018
example unless statement in Ruby
View unless.rb
unless 2 + 2 == 4
puts "Incorrect!"
end
@ryanckulp
ryanckulp / if_guard.rb
Created Jan 2, 2018
example if/guard clause in Ruby
View if_guard.rb
# verbose
if 2 + 2 == 4
puts "Correct!"
end
# short-hand
puts "Correct" if 2 + 2 == 4
# more realistic short-hand
def addition_problem(user_answer, correct_answer)
@ryanckulp
ryanckulp / flash_cards.rb
Last active Jan 1, 2018
a sample flash card application in Ruby
View flash_cards.rb
questions = {
'one' => {text: "What is 2 + 2?", answer: 4},
'two' => {text: "What is 4 + 7?", answer: 11},
'three' => {text: "What is 7 + 3?", answer: 10},
}
user_answers = {
'one' => 4,
'two' => 9,
'three' => 10
@ryanckulp
ryanckulp / grocery_array.rb
Last active Jan 2, 2018
looping through an array of groceries in Ruby
View grocery_array.rb
groceries = ["apple", "pear", "banana"]
groceries.each do |grocery|
puts grocery
end
# =>
# apple
# pear
# banana
@ryanckulp
ryanckulp / student_age_array.rb
Created Jan 1, 2018
array of floats for looping in Array
View student_age_array.rb
ages = [16, 15.6, 16.25, 17.1, 16.4, 15.8]
total_years = 0.0
ages.each do |age|
total_years += age
end
total_years / ages.size # => 16.191666666666666
@ryanckulp
ryanckulp / eccentric_array.rb
Created Jan 1, 2018
array with different element types in Ruby
View eccentric_array.rb
arr = [3, "four", {five: 'six'}]
@ryanckulp
ryanckulp / hash_actions.rb
Created Jan 1, 2018
adding key/values to a Hash in Ruby
View hash_actions.rb
questions = {} # => create an empty Hash/object
questions['one'] = "What's your name?"
questions['two'] = "How old are you?"
@ryanckulp
ryanckulp / hash_bracket.rb
Created Jan 1, 2018
accessing a Hash key/value in Ruby
View hash_bracket.rb
questions = {
'one' => "What's your name?",
'two' => "How old are you?"
}
questions['one'] # => returns "What's your name?"
questions['two'] # => returns "How old are you?"
You can’t perform that action at this time.