Skip to content
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
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
border-radius: 12px;
opacity: .85;
}
li{

li{
display: inline;
list-style-type: none;
padding-right: 20px;
Expand Down
73 changes: 73 additions & 0 deletions ChrisCahill-christophercahill/d4/finding_things.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
def index_of(string, letter)
i = 0
length = string.length
string = string.chars.to_a
string.each do |character|
if character.downcase == letter.downcase
break
else
i = i + 1
end
end
if i > length
i = -1
end
i
end

puts index_of("hello", "o")
puts index_of("tomorrow", "o")
puts index_of("lekker", "k")

def find_by_name(array, name)
result = nil
array.each do |individual_hash|
if individual_hash[:name] == name
result = individual_hash
break
end
end
result
end

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

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

puts find_by_name(people, "kitten!")
# => nil

def filter_by_name(array, name)
result = []
array.each do |individual_hash|
if individual_hash[:name] == name
result << individual_hash
end
end
result
end

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

fizzbuzz 100

17 changes: 17 additions & 0 deletions ChrisCahill-christophercahill/d4/map.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# map.rb
engines = ["Google", "Bing", "Ask Jeeves"]

result = engines.map do |e|
if e == "Google"
new_e = "OK"
elsif e == "Bing"
new_e = "Bad!"
else
new_e = "What is that?"
end
new_e
end

puts result

# => ["OK", "Bad!", "What is that?"]
18 changes: 18 additions & 0 deletions ChrisCahill-christophercahill/d4/phonebook_app/app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'sinatra'

get '/' do
erb :index
end

get '/contacts' do
@contacts = ["Melissa", "Sarah", "Robert"]
erb :contacts
end

get '/contacts/:contact' do
@contacts = { "Melissa" => "071-871-1840", "Sarah" => "071-160-5132",
"Robert" => "071-221-8652"}
@contact_name = params["contact"]
@contact_number = @contacts[@contact_name].to_s
erb :contact
end
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p><%= @contact_name %>'s number is <%= @contact_number %>.</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<h1> Contacts </h1>
<p> Here are all of the contacts I have #needfriends </p>
<ul>
<% @contacts.each do |contact| %>
<li><%= contact %></li>
<% end %>
</ul>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<p>Welcome to this sketch online phonebook.</p>
<a href="/contacts">To see all my contacts, click here</a>
<p>To make this have any use, you can find a phone number for a contact by utilizing the URL. For example, if you were to type /contacts/Sarah it would return to you Sarah's number.</p>
21 changes: 21 additions & 0 deletions ChrisCahill-christophercahill/d4/recipes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
dishes = { :Butter_Chicken => ["chicken", "curry", "rice"],
:BLT => ["bacon", "lettuce", "tomato"], :Crepes => ["water", "flour", "butter"]}


recipes = {
:Butter_Chicken => {
:description => "This is a classic Indian-inspired dish.",
:ingredients => ["chicken", "curry", "rice"],
:steps => ["Prep the chicken", "Marinate with spices", "Cook with curry"]
},
:BLT => {
:description => "'Merica.",
:ingredients => ["bacon", "lettuce", "tomato"],
:steps => ["Put bacon in between", "Add lettuce", "Add tomato"]
},
:Crepes => {
:description => "Viva la France",
:ingredients => ["flour", "water", "butter"],
:steps => ["Prep the liquid mixture", "Pour on crepe stone"]
}
}
15 changes: 15 additions & 0 deletions ChrisCahill-christophercahill/d4/reverse.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def reverse(array)
length = array.length - 1
new_array = []
while length >= 0
new_array << array[length]
puts array[length]
length-= 1
end
new_array
end

random_objects = ["apples", 4, "bananas", "kiwis", "pears"]

reverse random_objects

74 changes: 74 additions & 0 deletions ChrisCahill-christophercahill/d5/capetown_guide/app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
require "sinatra"

get "/" do
erb :index
end

get "/places" do
@places = ["Lion's Head", "Camps Bay", "Old Biscuit Mill"]
@places_url = { "Lion's Head" => "lion" ,
"Camps Bay" => "camp" , "Old Biscuit Mill" => "old" }
erb :places
end

get "/places/:destination" do |destination|
places = {"lion" =>
{"title" => "Lion's Head",
"picture" => "http://www.capetownmagazine.com//media_lib/r2/fa98c334aa8f8907bd2a8595e46c5526.img.jpg",
"map" => "https://www.google.co.za/maps/place/Lion's+Head,+Table+Mountain+National+Park,+Signal+Hill,+Cape+Town,+8001/@-33.935037,18.3889709,15z/data=!4m2!3m1!1s0x1dcc6705adf437ed:0x482833296b600211",
"description" => "Description: <br>

Lion's head is a mountain in Cape Town, South Africa, located between Table Mountain and Signal Hill. Lion's Head peaks at 669 metres (2,195 ft) above sea level. The mountain is a part of the Table Mountain National Park.

The suburbs of the city surround the peak on almost all sides of the Mountain, but strict management by city authorities has kept development of housing off the higher ground. The Lion's Head area is significant to the Cape Malay community, who historically lived in the Bo-Kaap quarter.

<br> <br>

Activities: <br>

Lion's head is know for it's beautiful views over both the city and the Atlantic Seaboard. The hour-long walk to the top is extremely popular, especially during the full moon and during sunrise. Its slopes are also a popular launching point for paragliders.



"
},
"camp" =>
{"title" => "Camps Bay",
"picture" => "http://www.savingwater.co.za/wp-content/uploads/2010/02/camps-bay.jpg",
"map" => "https://www.google.co.za/maps/place/Camps+Bay,+Cape+Town/@-33.9520409,18.382408,15z/data=!3m1!4b1!4m2!3m1!1s0x1dcc67ad0e328c89:0xc7a0b241c4464b97",
"description" => "Description/History: <br>

Camps Bay is an affluent suburb of Cape Town, South Africa. In summer it attracts a large number of foreign visitors as well as South Africans. The first residents of Camps Bay were the San (Hunter Gatherers) and the Goringqhaique, Khoi pastorates. By 1713 the number of Gringqhaique population had been reduced by measles and smallpox. All that was left of their settlement was an old kraal (Oudekraal). For most of the 1800s Camps Bay was undeveloped. Lord Charles Somerset used the area for hunting and used the Roundhouse as his lodge. Kloof Road was built in 1848 and in 1884 Thomas Bain was commissioned to build a road from Sea Point to Camps Bay using convict labour. In 1913 Camps Bay was incorporated into Cape Town although it was still seen as a recreational area rather than a residential area.

<br><br>

Activities: <br>

If you head south from the beaches of Clifton (or north from the buzz of Sea Point), you’ll discover the chic suburb of Camps Bay. The main attraction, Victoria Road, is jam-packed with funky restaurants, trendy pubs, and bucket-and-spade shops on one side, and a palm-fringed beach on the other.

If you’re staying over, there’s a wide range of accommodation on offer, from self-catering apartments to stylish villas and the old and gracious The Bay Hotel with its perfect views of Camps Bay beach.

"
},
"old" =>
{"title" => "Old Biscuit Mill",
"picture" => "http://www.thewrendesign.com/wp-content/uploads/design-goods-market/biscuit-mill-1.jpg",
"map" => "https://www.google.co.za/maps/place/The+Old+Biscuit+Mill/@-33.9275533,18.4574846,17z/data=!3m1!4b1!4m2!3m1!1s0x1dcc5da6b46abd99:0x39cc47e5b0eb6340",
"description" => "Description: <br> There are many markets in Cape Town, but one stands out head and shoulders above all others - The Old Biscuit Mill market in Woodstock. A wide range of food stalls, an excellent vibe, good music and did we mention the excellent wide range of foods?

Tucked away in Woodstock, one of Cape Towns poorer suburbs, The Old Biscuit Mill market has managed to attract the young and trendy Cape Town crowd in their droves with an atmosphere similar to Borough Market in London.

The food stalls represent a wide range of tastes from your standard sandwiches (nothing standard about them though), to Ostrich burgers, Greek kebabs, organic local foods, French food and a wide range of breads, cheeses and wines all locally produced in the Western Cape.

Directly outside of the market you will find a treasure-trove of homeware shops that sell those obscure and never thought of knick-knacks that you never knew you needed untill you saw them!

The market runs every Saturday what ever the weather from 9am till 2pm, be advised it can get extremely busy and at times finding a parking spot can be a problem so arrive early (before 10:30am) in order to get a decent parking spot."
}}

@destination = places[destination]
@name = @destination["title"]
@image_url = @destination["picture"]
@description = @destination["description"]
@map_url = @destination["map"]
erb :place
end
75 changes: 75 additions & 0 deletions ChrisCahill-christophercahill/d5/capetown_guide/views/index.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<head>
<link href='http://fonts.googleapis.com/css?family=Lato&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
</head>
<style>
body {
background-image: url("http://www.travelstart.co.za/blog/wp-content/uploads/2013/11/Greg-Lumley.jpg") ;
background-size: cover;
text-align: center;
}
h1 {
font-size: 55px;
font-family: 'Lato', sans-serif;
font-weight: 100;
color: white;
}
h2 {
font-family: 'Lato', sans-serif;
font-weight: 400;
font-size: 35px;
color: white;
}
h3 {
font-family: cursive;
font-size: 35px;
font-style: normal;
font-variant: normal;
font-weight: 500;
}
a {
font-family: 'Lato', sans-serif;
font-weight: 400;
font-size: 35px;
color: white;
text-decoration: none;

}
li {
display: inline;
list-style-type: none;
padding-right: 20px;
font-size: 40px;
font-family: 'Lato', sans-serif;
font-weight: 100;
color: white;
}
div {
height: auto;
background: #B0C4DE;
background-size: cover;
margin: 40px 0 0 0;
border-radius: 20px;
opacity: .75;
font-size: 30px;
}
</style>

<body>
<h1> Welcome to Cape Town<h1>
<h2> A Brief Guide </h2>
<br>
<br>
<br>
<br>
<div>
<h3>"This cape is the most stately thing and the fairest cape we saw in the whole circumference of the earth" -Sir Francis Drake, 1580</h3>
</div>
<br>

<br>
<br>
<br>
<br>
<br>
<a href="/places">Attractions</a>
</body>
Loading