Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cameron Averill 1A and 1B #12

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions CameronAverill-cameronaverill/d1/hello.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>Hello, World!</h1>
<p>My name is Cameron Averill</p>
9 changes: 9 additions & 0 deletions CameronAverill-cameronaverill/d1/profile.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!doctype html>
<html>
<head>
<title>My second webpage</title>
</head>
<body<
<p>hello world!</p>
</body<>
</html>
9 changes: 9 additions & 0 deletions CameronAverill-cameronaverill/d2/99_bottles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
index = 99
while index >= 1
if index > 1
puts "#{index} bottles of beer on the wall. #{index} bottles of beer. You take one down, pass it around, #{index} bottles of beer on the wall"
else
puts "#{index} bottle of beer on the wall. #{index} bottle of beer. You take one down, pass it around, #{index} bottle of beer on the wall"
end
index = index - 1
end
3 changes: 3 additions & 0 deletions CameronAverill-cameronaverill/d2/angry_boss.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
puts "What the fuck do you want?"
answer = gets.chomp.upcase
puts "WHADDAYA MEAN \"#{answer}\"?!? YOU'RE FIRED!!"
10 changes: 10 additions & 0 deletions CameronAverill-cameronaverill/d2/answers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1. x = 5
2. String
3. No, it's an integer
4. YOLO
5. Coolio
6. It's an error because 42 is an integer, which you can't add to a string
7. Batwoman
8. Miley
9. rapper[0]
10. rapper[0, 3] or rapper[0..2]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
puts "Tell me your favorite number"
favNum = gets.chomp.to_i
favNum += 1
puts "I think #{favNum} is a better favorite number"
14 changes: 14 additions & 0 deletions CameronAverill-cameronaverill/d2/deaf_grandma.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
puts "How are you, dear?"
answer = gets.chomp

while answer!='BYE'
while answer != answer.upcase
puts "HUH?! SPEAK UP, SONNY!"
answer = gets.chomp
end

currentYear = rand(21)
currentYear = currentYear + 1930
puts "NO, NOT SINCE #{currentYear}!"
answer = gets.chomp
end
21 changes: 21 additions & 0 deletions CameronAverill-cameronaverill/d2/deaf_grandma_extended.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
puts "How are you, dear?"
answer = gets.chomp

byecount = 0

while byecount < 2
if(answer == 'BYE')
byecount = byecount + 1
puts byecount
end

if answer != answer.upcase
puts "HUH?! SPEAK UP, SONNY!"
answer = gets.chomp
else
currentYear = rand(21)
currentYear = currentYear + 1930
puts "NO, NOT SINCE #{currentYear}!"
answer = gets.chomp
end
end
10 changes: 10 additions & 0 deletions CameronAverill-cameronaverill/d2/full_name_greeting.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
puts "Please enter your first name"
firstname = gets.chomp

puts "Please enter your middle name"
middlename = gets.chomp

puts "Please enter your last name"
lastname = gets.chomp

puts "Hello, #{firstname} #{middlename} #{lastname}"
35 changes: 35 additions & 0 deletions CameronAverill-cameronaverill/d2/leap_years.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
puts "Enter a starting year"
startingYear = gets.chomp.to_i

puts "Enter an ending year"
endingYear = gets.chomp.to_i

currentYear = startingYear
startLeapYear = nil

while startLeapYear == nil && currentYear <= endingYear
if (currentYear % 4 == 0)
if(currentYear % 100 == 0)
if (currentYear % 400 == 0)
startLeapYear = currentYear
else
currentYear += 1
end
else
startLeapYear = currentYear
end
else
currentYear += 1
end
end

if(startLeapYear == nil)
puts "There are no leap years between these two years"
else
while startLeapYear <= endingYear
puts startLeapYear
startLeapYear+=4
end
end


36 changes: 36 additions & 0 deletions CameronAverill-cameronaverill/d3/better_bouncer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
def lenient_bouncer
true
end

puts lenient_bouncer

def bouncer(age, country)
if((country.downcase == 'south africa' && age >= 18) || (country.downcase == 'usa' && age>=21))
"You in."
else
"You out."
end
end

puts bouncer(21, 'UsA')
puts bouncer(18, 'UsA')
puts bouncer(7, 'south Africa')
puts bouncer(18, 'SOUTH AFRICA')

def strict_bouncer(people, letter)
allowed_names = []
people.each do |person|
person_name = person[0]
person_age = person[1]
if !(person_name[0].downcase == letter || person_age < 21)
allowed_names.push(person_name)
end
end
allowed_names
end

p strict_bouncer([['erica', 22], ['ian', 24], ['brian', 34], ['seth', 18]], 'i')
p strict_bouncer([['aaron', 28], ['rafi', 21]], 'i')



67 changes: 67 additions & 0 deletions CameronAverill-cameronaverill/d3/finding_things.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
def index_of(string, letter)
index = 0
string.each_char do |character|
if character.downcase == letter.downcase
return index
else
index += 1
end
end
return -1
end

puts index_of('turtle', 't')
puts index_of('', 'h')
puts index_of('zoomba', 'c')

def find_by_name(array_of_hashes, string)
index = 0
array_of_hashes.each do |hash|
if hash.has_value?(string)
return hash
else
index += 1
end
end
return nil
end

people = [
{
:id => 1,
:name => "bru"
},
{
:id => 2,
:name => "ski"
},
{
:id => 3,
:name => "brunette"
},
{
:id => 4,
:name => "ski"
}
]

p find_by_name(people, "ski")
# => {:id=>2,:name=>"ski"}
p find_by_name(people, "kitten!")

def filter_by_name(array_of_hashes, string)
array = []
array_of_hashes.each do |hash|
if hash.has_value?(string)
array << hash
end
end
array
end

p filter_by_name(people, "ski")
# => [{:id=>2,:name=>"ski"}, {:id=>4,:name=>"ski"}]
p filter_by_name(people, "bru")
# => [{:id=>1,:name=>"bru"}] (Note this is still an array)
p filter_by_name(people, "puppy!!!")
# => []
18 changes: 18 additions & 0 deletions CameronAverill-cameronaverill/d3/fizzbuzz.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def fizzbuzz(max_val)
index = 1
while index <=max_val
if index%15 == 0
p "fizzbuzz"
elsif index%5 == 0
p "buzz"
elsif index%3 == 0
p "fizz"
else
p index
end
index += 1
end
end

fizzbuzz(0)
fizzbuzz(20)
15 changes: 15 additions & 0 deletions CameronAverill-cameronaverill/d3/map.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def map_array(array)
array.map do |element|
if element == "Google"
element = "OK"
elsif element == "Bing"
element = "Bad!"
else
element = ("What is that?")
end
end
end

p map_array(["Google", "Bing", "Ask Jeeves"])


14 changes: 14 additions & 0 deletions CameronAverill-cameronaverill/d3/mumble_jumble.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def jumble(str_to_jumble)
str_to_jumble.split('').shuffle.join('')
end

puts jumble('the dog')
puts jumble('turtle')
puts jumble('')
puts jumble("Nice, Bru! Try to talk properly")

def mumble(str_to_mumble)
str_to_mumble.downcase
end

puts mumble('TURTLE')
17 changes: 17 additions & 0 deletions CameronAverill-cameronaverill/d3/recipes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
dishes = {"Hash browns" => ["Potatoes", "Butter"], "Sushi" => ["fish", "rice"], "Salsa" => ["tomatoes", "onions", "cilantro"]}

puts dishes

recipes = {"Hash browns" => {
"description" => "warm deliciousess",
"ingredients" => ["Potatoes", "Butter"],
"steps" => ["cut potatoes", "sizzle in pan"]},
"Sushi" => {
"description" => "crisp and tasty fish on rice",
"ingredients" => ["fish", "rice"],
"steps" => ["filet fish", "pack rice onto bamboo", "roll"]},
"Salsa" => {
"description" => "spicy and fun with chips",
"ingredients" => ["tomatoes", "onions", "cilantro"],
"steps" => ["cube tomatoes", "chop onions", "mix"]}}
p recipes
9 changes: 9 additions & 0 deletions CameronAverill-cameronaverill/d3/reverse.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def reverse(array)
answer = []
array.each do |element|
answer.unshift(element)
end
answer
end

p reverse(['turtle', 'sushi', 'latvia'])
5 changes: 5 additions & 0 deletions CameronAverill-cameronaverill/d3/scope_it_out.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1. it prints "IT'S SO LOUD" and returns 20
2. a. Sets the variable loudness to the value 20
b. prints out "IT'S SO LOUD"
c. returns loudness
3. 10. The scope of the variables inside a method are local to that method.
31 changes: 31 additions & 0 deletions CameronAverill-cameronaverill/d4/calculator_app/calculator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require "sinatra"

get "/" do
erb :home_page
end

get "/add/:number1/:number2" do |number1, number2|
sum_of_nums = number1.to_i + number2.to_i
"The sum of #{number1} and #{number2} is #{sum_of_nums}"
end

get "/multiply/:number1/:number2" do |number1, number2|
product_of_nums = number1.to_i * number2.to_i
"The product of #{number1} and #{number2} is #{product_of_nums}"
end

get "/divide/:number1/:number2" do |number1, number2|
quotient_of_nums = number1.to_f / number2.to_f
"The quotient of #{number1} and #{number2} is #{quotient_of_nums}"
end

get "/subtract/:number1/:number2" do |number1, number2|
difference_of_nums = number1.to_i - number2.to_i
"The difference of #{number1} and #{number2} is #{difference_of_nums}"
end

get "/exponentiate/:number1/:number2" do |number1, number2|
exponent_of_nums = number1.to_i ** number2.to_i
"#{number1} to the power of #{number2} is #{exponent_of_nums}"
end

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>

<head>
<Title> Cameron's Calculator </Title>
</head>

<body style="text-align: center; margin: 0 auto; max-width: 400px">
<h1> Cameron's Calculator </h1>
<p> Welcome to Cameron's Calculator, where the secret lies in the web address.
Just type our domain name followed by a site path, where the first path feature
is the operation you wish to complete, followed by two paths that are the numbers you wish to calculate. </p>
<p> <strong> Example: </strong> http://localhost:4567/add/4/7 takes you to a page that shows the sum of 4 and 7. </p>

<p> The possible operations are add, subtract, multiply, divide, and exponentiate </p>
</body>
13 changes: 13 additions & 0 deletions CameronAverill-cameronaverill/d4/personal_page/app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require "sinatra"

get "/" do
erb :home
end

get "/contact" do
erb :contact
end

get "/about" do
erb :about
end
Loading