Solutions 4A

Exercise 4A

1) Calculator:

Folder: calculator_app
File: CalculatorApp/calculator.rb

require "sinatra"

#each route performs simple math and returns a string. 
#The maths done varies based on the route. 
#The numbers are supplied as route parameters
get "/add/:number_1/:number_2" do |number_1, number_2|

    "The solution to #{number_1} plus #{number_2} is #{number_1.to_i+number_2.to_i}"

end

get "/multiply/:number_1/:number_2" do |number_1, number_2|

    "The solution to #{number_1} multiplied by #{number_2} is #{number_1.to_i*number_2.to_i}"

end

get "/minus/:number_1/:number_2" do |number_1, number_2|

    "The solution to #{number_1} minus #{number_2} is #{number_1.to_i-number_2.to_i}"

end

get "/divide/:number_1/:number_2" do |number_1, number_2|

    "The solution to #{number_1} divided by #{number_2} is #{number_1.to_i/number_2.to_i}"

end

get "/exp/:number_1/:number_2" do |number_1, number_2|

    "The solution to #{number_1} to the power of #{number_2} is #{number_1.to_i**number_2.to_i}"

end

Note, this is app works with ERB files to control views. That's perfectly ok in very simple apps like this. Talk to Josh or Erica about other potential ERB based strcutures.

To use the above app, copy the code above into a new ruby file and run it using ruby <filename>.rb:

Type: localhost:4567/add/num1/num2 into the browser to add num1 and num2
Type: localhost:4567/minus/num1/num2 into the browser to subtract num2 from num1
Type: localhost:4567/multiply/num1/num2 into the browser to times num1 by num2
Type: localhost:4567/divide/num1/num2 into the browser to divide num1 by num2
Type: localhost:4567/exp/num1/num2 into the browser to raise num1 to the power of num2

2) Personal site:

The code below is for a very very basic personal site with no styling. To see an example of a more styled site leave your session0203 folder, run git clone https://github.com/JoshBroomberg/PersonalSiteExample.git, cd into the new folder and run shotgun personalApp.rb. This app is written to be inline with your current knowledge, it uses no external style sheets, all CSS is inline etc. It isn't a very good app, but it is an example of what you could do with your current knoweldge. If you aren't curious, here is the basic code:

file: personal_site.rb

This file defines the routes for the app

require "sinatra"

#These are the site routes, they define what pages sinatra will serve when different URL's
#are entered into the browser

get "/" do #root of site is set to show home page
    erb :home
end

get "/contact" do 
    erb :contact
end

get "/about" do 
    erb :about
end

folder: views

This folder holds the file for each page/view

file: home.erb
<!DOCTYPE html>
<head>
    <title>Josh Broomberg</title>
</head>

<nav class="fixed-nav-bar">
    <ul>
        <li>
            <a href="/"> HOME</a>
        </li>
        <li>
            <a href="/about"> ABOUT</a>
        </li>
        <li>
            <a href="/contact"> CONTACT</a>
        </li>
    </ul>
</nav>



<body>
    <br>
    <h1><b>JMB</b></h1>
    <img src="http://i.imgur.com/MsLw0CY.png?3">

</br>

<h2>
</br>My name is Josh Broomberg. I am a student, an aspiring entrepreneur, and an avid coder.</br></br>

While I will always be a 'joburger' at heart,
I live in Cape Town and study at <a href="http://www.uct.ac.za/"> UCT</a>. 
<a id="about_link" href="/about"> More about my studies..?</a>

&nbsp;As far as interests go; I really love to code, in fact, I love all things tech. 
<a id="about_link" href="/about"> 
    More about my coding..?</a>&nbsp;
    My other passion is debating, which I particpated in at a national level.
    <a id="about_link" href="/about"> More about my debating..?</a></br></br>

    Feel free to explore using the navigation bar, or the links in the paragraph above.
    Alternately, <a id="about_link" href="/contact"> 
    click to get in touch with me now.</a> </br>
</h2>
</body>
</html>
file: contact.erb
<!DOCTYPE html>
<head>
    <title>Josh Broomberg</title>
</head>

<nav class="fixed-nav-bar">
    <ul>
        <li>
            <a href="/"> HOME</a>
        </li>
        <li>
            <a href="/about"> ABOUT</a>
        </li>
        <li>
            <a href="/contact"> CONTACT</a>
        </li>
    </ul>
</nav>

<h2>
</br>
If you know me, you should add me on  <a href="https://www.facebook.com/joshbroomberg">Facebook</a>,
follow me on <a href="https://twitter.com/joshbroomberg">Twitter</a>
or connect with me on <a href="https://www.linkedin.com/profile/view?id=426466441">LinkedIn</a>. 
If you need to reach me privately -  
feel free to send me an <a href="mailto:joshbroomberg@gmail.com">email</a>
or just use the box below and I'll contact you.</br></br>
<form>
    <input type="email" placeholder= "youremail@mail.com">
    <input type="submit">
</form>
</br></br>
Finally, take a second to tell me if you found this site helpful. Thanks in advance.
<form>
</h2></p> 
Not helplful
<input type="radio" name="rating" value="1">
<input type="radio" name="rating" value="2">
<input type="radio" name="rating" value="3" checked> 
<input type="radio" name="rating" value="4">
<input type="radio" name="rating" value="5">
Very Helpful
</br></br>
<input type="submit">
</form>
</br>
<h2>
</h2>
</body>
</html>
file: about.erb
<!DOCTYPE html>
<head>
    <title>Josh Broomberg</title>
</head>

<nav class="fixed-nav-bar">
    <ul>
        <li>
            <a href="/"> HOME</a>
        </li>
        <li>
            <a href="/about"> ABOUT</a>
        </li>
        <li>
            <a href="/contact"> CONTACT</a>
        </li>
    </ul>
</nav>

<h2>
    Studies:</br> I'm currently in first year at UCT, doing a BSc majoring in CompSci, Economics 
    and Math. While my real focus is CompSci, I really enjoy learning about the intricacies
    of the way the world works in Ecos and find the logic of Maths... 
    tbh I hate maths, the pure kind at least.</br></br>

    Coding:</br>I fell in love with coding from the very first "hello world!" in grade 10
    and have been working to improve my skills. I am 'fluent' in Java, python, and SQL;
    proficient in PHP, HTML and CSS and learning Swift and Ruby. 
    I code because I love problem solving and the feeling of creating functional products.
    If you're interested in my projects, have a look at my 
    <a href="https://github.com/JoshBroomberg"><span style="color:#ffa500">GitHub<span></a>.</br></br>

    Debating:</br>In highschool, I spent most of my time debating - one of the cool kids, you know.
    I was on the SA national team from Grade 10 to Grade 12.
    I currently speak as UCT A. If you're interested, you can watch me and the rest
    of the team represent SA in the finals of world championships
    <a href="https://vimeo.com/103587325">here</a>.</br> <a name="studies"></a>
    <h2>
    </h2>
</body>
</html>