Write a Deaf Grandma program.
Whatever you say to grandma (whatever you type in), she should respond with
HUH?! SPEAK UP, SONNY!
unless you shout it (type in all capitals).
| TERNARY OPERATOR | |
| n.abs == 1 ? 'bottle' : 'bottles' | |
| #This is saying if the number of bottles is 1 return bottle, if not return bottles; | |
| # In Ruby we have open classes; | |
| #You can take any class at any point and add extra data into it; | |
| #MONKEY MATCHING adding something later to something that exists already; |
| Inside irb: | |
| require 'json' | |
| require 'httparty' | |
| title = 'aliens' #comes from params[:movie_title] | |
| url = "http://www.omdbapi.com/?t=#{title}" | |
| #Data in HTTParty response format |
| #http - tells you to use port 80; | |
| #ftp | |
| #irc | |
| #http = hypertext transfer protocol; | |
| #http://www.cnn.com/latest?q=idiots | |
| # http://www.cnn.com (webserver that it lives on(domain, ip address)) / latest? (this is the path) ?q=idiots (this is the query string) | |
| # This is an example of a path -> get 'hello' (which part of the server we are accessing, which bit of code to execute) | |
| ##HTTP VERBS |
| class Sandwich | |
| @slices_of_bread = 2 | |
| def how_much_bread() | |
| @slices_of_bread | |
| end | |
| end | |
| #Instance variable you can access anywhere inside the class; |
| ##Loading data from a CSV File | |
| #Slow | |
| #Memory expensive | |
| #Buggy | |
| ##DATABASE | |
| #A different program; | |
| #Create a string that describes what you want and send it to the database; | |
| #You could have the database on a different machine/different country, all you need to send to it is a query string; |
| - Username and password; | |
| - \h => help; | |
| -\c butterflies_app; | |
| -\d (desribe the table) | |
| - cp -r butterflies_app butterflies_pg_app | |
| -psql --help | |
| - psql -f butterflies.sql butterflies_app (run where the butterflies.sql is) | |
| -\d butterflies |
| ##ENVIRONEMNTS | |
| #Development (uses sqlite) | |
| #Production (uses postgresql) | |
| #Test environemnt | |
| psql to get into the database | |
| \l shows all of the databases; | |
| \c students (connects to the students database); | |
| \d shows relations; |
| ##DEPLOYING TO HEROKU | |
| #Create an account on Heroku | |
| https://www.heroku.com | |
| #Download Heroku Toolbelt (a client for generating and creating heroku apps); | |
| https://toolbelt.heroku.com/ | |
| heroku login #in the command line #It should generate SSH keys (we may have to do this manually); | |
| #Gem list and check that you have the gem bundler; (You can do gem list | grep bundler); | |
| #If you do not have it then install it: | |
| gem install bundler #We have already done this; |