On Github jnappy / coding_for_beginners_workshop-
How the Internet works Manipulate data with Ruby Version control and why it's important Hosting applications with GitHub pages
Today
How the web works Command line Data types, methods in Ruby LUNCH Data collections Iterating over a collection Getting data from the internet (without a Browser) and doing something with it :)Tomorrow
HTTP requests Sinatra Hosting?FILL THIS IN
In your terminal:
xcode-select -pYou should see something like:
/Applications/Xcode.app/Contents/Developer
Command+
Spacebar
Type in "Terminal"
and hit enterIn your terminal:
brew -vYou should see something like:
Homebrew 0.9.5
In your terminal:
rvm -vYou should see something like:
rvm 1.26.10
In your terminal:
atom -vYou should see something like:
0.158.0
Describe how clients work with servers to deliver information.
It all comes down to requests and responses
You send information out to the web, and based on the info you send, you get information back
Stands for "Hyper Text Transfer Protocol"
Allows for communication between a variety of hosts and clients, and supports a mixture of network configurations.
Read: "Makes it easy for computers to talk to each other"
Host - Client - Request - Response
Predict, with a partner, how these vocabulary words relate to one another. When you're finished, we'll draw a diagram on the board that we will refer back to.
Host - a computer or other device connected to a computer network. A host may offer information resources, services, and applications (via computer code!) to users or other computers on the network
Examples: Servers and Web Services
Let's login to the AWS Console, Heroku
Client - the requesting program in the client/host relationship
The client initiates an HTTP request message, which is serviced through a HTTP response message in return.
Come up with one example of a client that can send requests.
Terminals
Web Browsers
SQL Programs like Workbench and PGAdmin
Open your terminal, and type in the following request:
curl http://www.krossoverkredit.com/users/sign_in
cURL stands for 'Client URL Request Library'
Now, try this request:
curl google.com
What do you notice?
But before we do, let's answer the following questions:
Predict: How is a request format different in a browser? What do you think makes a browser client so special in the way it handles responses?The request is a URL!!!
What do you think makes a browser client so special in the way it handles responses?The browser can take the response and make it pretty
Open up Chrome and type in 'http://www.krossoverkredit.com/users/sign_in'
Keep in mind, this is the same request and same response, so remember what makes response handling different!
What do you notice about the URL after you searched?
Let's draw it in our diagram
Server-side languages control what pages, information is served to the client.
Client-side languages are responsible for displaying information and aesthetics to the user.
Each side's programming, refers to code which runs at the specific machine, the server's or the client's.
Client: "I'm going to ask for information by explicitly saying where to go and what I need in a URL"
Server: "Based on the request/URL, I'm going to run a particular set of code (Ruby), to send you the information + data you request via HTML/CSS/JS."
Client: "Thank you for this data - I'm going to make it pretty with the HTML/CSS/JS you gave me."
Describe how clients work with servers to deliver information.
Navigate files and folders using the terminal
Run ruby code using the command line
It all comes down to requests and responses
Let's look to the diagram...
Heart of your OS
You can do anything you could do in finder in the command line...but faster
GUI vs. Command Line Demo
"Directory" = "Folder"
Want to run a .docx file? Use Microsoft Office
What about an mp3? Open with iTunes
If we want to run a ruby file (.rb) we have to run it using the terminal program
Watch, real quick...
~/Sites/secret_number/jay_nappy
What happens if we do f(3)?
Mac:
Applications > Utilitites > Terminal
PC: Right click desktop and choose
Git bash
Remember: Directory = Folder
Find out the present working directorypwdList the contents of the directory
lsChange directories
cdCreate a new folder
mkdir
rmdir- Remove an empty folder
touch- Create an empty file
rm- Remove a file
cp- Copy a file
atom- Open the directory you're in with a text editor
cd ..
Move to the parent (root) directory
cd ~
From your desktop:
Work with a partner!
Bonus:Open each file in atom and add the day of the week in quotes.
cdinto your days directory
git initThis adds git to your "days" directory
git addAdds your files as "ready to be saved" (committed)
git commit -m 'INSERT A MESSAGE'Commits (saves) files to the git timeline or version history
git logShows your commit history
With Git, nothing is lost (if you do it right!)
Let's check it out:
git clone YOUR_URL@github.com
An object is a software bundle of related state and behavior. Software objects are often used to model the real-world objects that you find in everyday life.
Practice the next few slides with me!
Let's jump into Krossover's objects...
Integers
Floats
Variables are simply a place to store data. The data can take on almost any form. All variables we store as lower case, and separate words are separated by underscores:
How could data work with variables in req/resp?
There are two ways to join variables together:
By simply appending on thing after the other String interpolationDiscuss: Could you think of any use cases for this?
Puts is a method that Ruby "gives you for free". It stands for "PUT" "String", out to the terminal:
Puts always returns 'nil'
Gets is also a method that Ruby "give you for free". It stands for "GET" "String", requesting it from user input.
What's that \n? It's newline (the user hitting enter)
Code along! Strings & Integers
f(x) = x + 2
Does this function produce anything if you repeat the "instructions"?
Think of functions as variables, but instead of data, they hold code!
In Ruby, you would write f(x) = x + 2 like:
All methods, in Ruby, start with 'def'
You call a function exactly the same (as you would in math!)
And remember, they can accept parameters
Methods code along
To run a ruby file, move into the directory your ruby file is in and type:
ruby FILE_NAME.rb
Watch, as I move my code along code into a ruby file and run it from the terminal to get the same output.
Let's explain how this relates to req/resp - to the board!.
Refactor the code along code (I'll chat it out in a gist in tlk.io) to ask the user for the story name and the number of likes for the story - store that data two variables.
First, but first HTTPS
Let's get our brains going!
(Jay, reveal/day_2_opening.part1.rb)
Check tlk.io for the kickoff assignment.
Together: create a new directory in exercises titled: "day_2", create a file called kick_off.rb, copy and paste the code from the gist, and initialize a git repository
Part 1: Together - day_2_opening.part1.rb
Part 2: In Pairs - https://gist.github.com/jnappy/17d0d99b7ded311a0eff
Bonus: Push your code to GitHub!
use Booleans and conditionals to control the flow of your application
Either true or false; these give us the ability to use logic => to choose where and what we want to happen in our application.
true || false
read: "user operators; compare"
The syntax reads
The 'elseif'
I'm going to build a function that asks a user where they live and then tells them whether or not they are cool.
Fork it; clone it to your computer; solve it!
https://github.com/jnappy/beer_exercise
This allows you to create an if statement that could be satisfied by multiple conditions
Let's see an easier way to do this...
or
Predict: an easier way to do this...
Fork it, clone it, solve it!
https://github.com/jnappy/admin_exercise
While
Until
Watch mi!!
Let's make a SPAM message until I enter "unsubscribe"
(Jay, Lesson 2 slide 25)
Let's make an Identification method that doesn't let you drink until you're twenty one
Fork it, clone it, solve it: https://github.com/jnappy/secret_numbah
Let's think back to KrossoverKredit Objects...
Data about an object is a collection of attributes, some of which have other attributes!
names = ['jay', 'erin', 'lindsay', 'david', 'delauno']
numbers = [1, 2, 5, 9, 13]
misc = ["one", 4, '9', "Two"]
What do names, numbers, and misc represent?
That means: it has a bunch of attributes and functions we can use!!
Let's access a particular element of an array
names = ['jay', 'erin', 'lindsay', 'david', 'delauno']
names[0]
=> 'jay'
NOTE: Indexes start at 0!
Imagine we get a request to get articles from our database...
Code along with me:
We can "iterate" over them!
read: "we can do something to each element in a collections of data"
sign_ins = [["jpnappy@gmail.com", "3:02pm"], ["tylernappy@gmail.com", "3:03pm"], ["rob@gmail.com", "3:05pm"], ["lorit@gmail.com", "3:06pm"], ["laura@gmail.com", "3:07pm"], ["jpnappy@gmail.com", "3:02pm"], ["jpnappy@gmail.com", "3:02pm"], ["jpnappy@gmail.com", "3:02pm"], ["jpnappy@gmail.com", "3:02pm"], ["jpnappy@gmail.com", "3:02pm"], ["dan@gmail.com", "3:05pm"]
Let's look at this in a text editor
Now, let's get a list of all the user's email addresses
person = {'name' => 'Jay', 'age' => 28}
This is great for objects!
Let's build on this object
person = {name: 'Jay', age: 28}
These are called 'symbols' (just like strings, don't focus on them!!)
Symbols are just like strings, the only difference is they're more efficient - they only get stored once
They're always denoted by a : and have lowercase letters with underscores.
Let's show some symbols vs. strings on the projector (lessons/3/slides/17)
We got sweet methods on hashes too!
person.keys
person.values
person.size
Let's practice adding new values and retrieving values from a hash
person['name']
person['age']
person[:name]
person[:age]
Let's try with a larger collection: hash + array (object)
blog_post = { title: 'What Makes A Star Starry? Is It Me?', body: "Notice what Tyler Nordgren does in these posters. He's an artist, an astronomer (from Cornell, Carl Sagan's department);", author: { first_name: 'Robert', last_name: 'Krulwich', twitter_handle: '@rkrulwich' }, tags: ['art', 'education', 'science'] }
blog_posts = [ { title: 'What Makes A Star Starry? Is It Me?', body: "Notice what Tyler Nordgren does in these posters. He's an artist, an astronomer (from Cornell, Carl Sagan's department);", author: { first_name: 'Robert', last_name: 'Krulwich', twitter_handle: '@rkrulwich' }, tags: ['art', 'education', 'science'] }, { title: 'The Meter: The Measure of a Man', body: "About six and a half billion people use the metric system every single day. That's more than the citizens of any single nation, the followers of any single religion or the speakers of any single language.", author: { first_name: 'Latif', last_name: 'Nasser', twitter_handle: '@latifnasser' }, tags: ['discovery', 'dialogues', 'history', 'meter', 'science', 'storytelling'] }, { title: 'Shattering Silence and An Eye of God', body: "In our Morality show, we tell the story of Eastern State Penitentiary -- a radical new kind of prison engineered to crack into the hearts and minds of 19th-Century criminals", author: { first_name: 'Brenna', last_name: 'Farrell', twitter_handle: '@brennacfarrell' }, tags: ['history', 'morality', 'prison'] } ]
Let's store each blog post into a variable to make this feel a bit easier...
Let's do the following:
The center of communication via the web are request messages that are sent via Uniform Resource Locators
Let's look at an example on the board...
The center of communication via the web are request messages that are sent via Uniform Resource Locators
Write content using inline or external Markdown. Instructions and more info available in the readme.
<section data-markdown> ## Markdown support Write content using inline or external Markdown. Instructions and more info available in the [readme](https://github.com/hakimel/reveal.js#markdown). </section>
Hit the next arrow...
... to step through ...
... a fragmented slide.
This slide has fragments which are also stepped through in the notes window.There's different types of fragments, like:
grow
shrink
fade-out
current-visible
highlight-red
highlight-blue
You can select from different transitions, like: None - Fade - Slide - Convex - Concave - Zoom
reveal.js comes with a few themes built in: Black (default) - White - League - Sky - Beige - Simple Serif - Blood - Night - Moon - Solarized
Set data-background="#dddddd" on a slide to change the background color. All CSS color formats are supported.
<section data-background="image.png">
<section data-background="image.png" data-background-repeat="repeat" data-background-size="100px">
<section data-background-video="video.mp4,video.webm">
Different background transitions are available via the backgroundTransition option. This one's called "zoom".
Reveal.configure({ backgroundTransition: 'zoom' })
You can override background transitions per-slide.
<section data-background-transition="zoom">
function linkify( selector ) { if( supports3DTransforms ) { var nodes = document.querySelectorAll( selector ); for( var i = 0, len = nodes.length; i < len; i++ ) { var node = nodes[i]; if( !node.className ) { node.className += ' roll'; } } } }
Code syntax highlighting courtesy of highlight.js.
These guys come in two forms, inline: “The nice thing about standards is that there are so many to choose from” and block:
“For years there has been a theory that millions of monkeys typing at random on millions of typewriters would reproduce the entire works of Shakespeare. The Internet has proven this theory to be untrue.”You can link between slides internally, like this.
There's a speaker view. It includes a timer, preview of the upcoming slide as well as your speaker notes.
Press the S key to try it out.
Oh hey, these are some notes. They'll be hidden in your presentation, but you can see them if you open the speaker notes window (hit 's' on your keyboard).Presentations can be exported to PDF, here's an example:
Set data-state="something" on a slide and "something" will be added as a class to the document element when the slide is open. This lets you apply broader style changes, like switching the page background.
Additionally custom events can be triggered on a per slide basis by binding to the data-state name.
Reveal.addEventListener( 'customevent', function() { console.log( '"customevent" has fired' ); } );
Press B or . on your keyboard to pause the presentation. This is helpful when you're on stage and want to take distracting slides off the screen.