4 |
--------------------------------------------------------------------------------
/10-node/10-exercises/template/printer.js:
--------------------------------------------------------------------------------
1 |
2 | // add file read and print code
3 | // wrap it up in a function
4 | // export that function as `print`
--------------------------------------------------------------------------------
/10-node/10-exercises/template/server.js:
--------------------------------------------------------------------------------
1 |
2 | // build a server that can server files from the public directory
3 |
4 | var http = require('http');
--------------------------------------------------------------------------------
/16-express-creating-data/16-template/views/error.ejs:
--------------------------------------------------------------------------------
1 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/10-node/10-examples/about.txt:
--------------------------------------------------------------------------------
1 | Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.
--------------------------------------------------------------------------------
/08-javascript-functions-adv/08-examples/foreach.js:
--------------------------------------------------------------------------------
1 |
2 | function forEach(array, callback) {
3 | for (var i = 0; i < array.length; i++) {
4 | callback(array[i]);
5 | }
6 | }
7 |
8 | var array = [0,1,2,3,4,5,6,7,8,9];
9 |
10 | forEach(array, function(item) {
11 | console.log("Just got access to item", item);
12 | });
--------------------------------------------------------------------------------
/16-express-creating-data/16-template/models/comment.js:
--------------------------------------------------------------------------------
1 |
2 | var mongoose = require('mongoose');
3 |
4 | var schema = mongoose.Schema({
5 | body: String,
6 | author: Number,
7 | postId: mongoose.Schema.Types.ObjectId
8 | });
9 |
10 | var Comment = mongoose.model('comments', schema);
11 | module.exports = Comment;
--------------------------------------------------------------------------------
/16-express-creating-data/16-template/views/index.ejs:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | <%= title %>
5 |
6 |
7 |
8 |
<%= title %>
9 |
Welcome to <%= title %>
10 |
11 |
12 |
--------------------------------------------------------------------------------
/A-exercise-solutions/04-bootstrap-class-example/readme.md:
--------------------------------------------------------------------------------
1 | Example Bootstrap Site
2 | ====================================
3 |
4 | Look in the `public` directory for the `.html` files that use bootstrap. The bootstrap styles and javascript are kept in the `stylesheets` and `javascipts` folder in the `public` directory, respectively.
--------------------------------------------------------------------------------
/15-mongoose/15-template/bin/www:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | var debug = require('debug')('template');
3 | var app = require('../app');
4 |
5 | app.set('port', process.env.PORT || 3000);
6 |
7 | var server = app.listen(app.get('port'), function() {
8 | debug('Express server listening on port ' + server.address().port);
9 | });
10 |
--------------------------------------------------------------------------------
/15-mongoose/15-template/public/stylesheets/style.css:
--------------------------------------------------------------------------------
1 |
2 | .post .author {
3 | display: inline-block;
4 | margin: 8px 0;
5 | }
6 |
7 | .post-links ul {
8 | margin: 0;
9 | padding: 0;
10 | }
11 |
12 | .post-links ul li {
13 | display: inline-block;
14 | list-style-type: none;
15 | padding: 0;
16 | margin: 0 20px 0 0;
17 | }
--------------------------------------------------------------------------------
/10-node/10-exercises/template/printer-test.js:
--------------------------------------------------------------------------------
1 |
2 | var printer = require('./printer');
3 |
4 | // ensure the print function exists on the printer module before calling it
5 |
6 | if ( printer.print ) {
7 | printer.print('test.txt');
8 | } else {
9 | console.log("ERROR: you haven't exported the print function from the printer.js file");
10 | }
--------------------------------------------------------------------------------
/16-express-creating-data/16-template/bin/www:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | var debug = require('debug')('template');
3 | var app = require('../app');
4 |
5 | app.set('port', process.env.PORT || 3000);
6 |
7 | var server = app.listen(app.get('port'), function() {
8 | debug('Express server listening on port ' + server.address().port);
9 | });
10 |
--------------------------------------------------------------------------------
/08-javascript-functions-adv/08-examples/timeout.js:
--------------------------------------------------------------------------------
1 |
2 | // Use setTimeout with a function assigned to a variable
3 |
4 | var callback1 = function() {
5 | console.log('3. Callback 1 called');
6 | }
7 |
8 | console.log("1. About to call setTimeout");
9 | setTimeout(callback1, 2000);
10 | console.log("2. Just called setTimeout");
11 | console.log("");
--------------------------------------------------------------------------------
/16-express-creating-data/16-template/public/stylesheets/style.css:
--------------------------------------------------------------------------------
1 |
2 | .post .author {
3 | display: inline-block;
4 | margin: 8px 0;
5 | }
6 |
7 | .post-links ul {
8 | margin: 0;
9 | padding: 0;
10 | }
11 |
12 | .post-links ul li {
13 | display: inline-block;
14 | list-style-type: none;
15 | padding: 0;
16 | margin: 0 20px 0 0;
17 | }
--------------------------------------------------------------------------------
/A-exercise-solutions/04-bootstrap-class-example/bin/www:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | var debug = require('debug')('intro-bootstrap');
3 | var app = require('../app');
4 |
5 | app.set('port', process.env.PORT || 3000);
6 |
7 | var server = app.listen(app.get('port'), function() {
8 | debug('Express server listening on port ' + server.address().port);
9 | });
10 |
--------------------------------------------------------------------------------
/A-exercise-solutions/10-node-intro/reader.js:
--------------------------------------------------------------------------------
1 |
2 | var fs = require('fs');
3 |
4 | var filename = process.argv[2];
5 |
6 | fs.readFile(filename, function(err, data) {
7 | if (err) {
8 | console.log("Unable to read file test.txt");
9 | } else {
10 | console.log("File Contents:");
11 | console.log(data.toString());
12 | }
13 | });
14 |
--------------------------------------------------------------------------------
/A-exercise-solutions/10-node-intro/printer.js:
--------------------------------------------------------------------------------
1 | var fs = require('fs');
2 |
3 | exports.print = function (filename)
4 | {
5 | fs.readFile(filename, function(err, data) {
6 | if (err) {
7 | console.log("Unable to read file test.txt");
8 | } else {
9 | console.log("File Contents:");
10 | console.log(data.toString());
11 | }
12 | });
13 | };
--------------------------------------------------------------------------------
/15-mongoose/15-template/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "template",
3 | "version": "0.0.1",
4 | "private": true,
5 | "scripts": {
6 | "start": "node ./bin/www"
7 | },
8 | "dependencies": {
9 | "express": "~4.2.0",
10 | "static-favicon": "~1.0.0",
11 | "morgan": "~1.0.0",
12 | "cookie-parser": "~1.0.1",
13 | "body-parser": "~1.0.0",
14 | "debug": "~0.7.4",
15 | "ejs": "~0.8.5"
16 | }
17 | }
--------------------------------------------------------------------------------
/A-exercise-solutions/04-bootstrap-class-example/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "intro-bootstrap",
3 | "version": "0.0.1",
4 | "private": true,
5 | "scripts": {
6 | "start": "node ./bin/www"
7 | },
8 | "dependencies": {
9 | "express": "~4.2.0",
10 | "static-favicon": "~1.0.0",
11 | "morgan": "~1.0.0",
12 | "cookie-parser": "~1.0.1",
13 | "body-parser": "~1.0.0",
14 | "debug": "~0.7.4",
15 | "jade": "~1.3.0"
16 | }
17 | }
--------------------------------------------------------------------------------
/16-express-creating-data/16-template/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "template",
3 | "version": "0.0.1",
4 | "private": true,
5 | "scripts": {
6 | "start": "node ./bin/www"
7 | },
8 | "dependencies": {
9 | "body-parser": "~1.0.0",
10 | "cookie-parser": "~1.0.1",
11 | "debug": "~0.7.4",
12 | "ejs": "~0.8.5",
13 | "express": "~4.2.0",
14 | "mongoose": "^3.8.13",
15 | "morgan": "~1.0.0",
16 | "static-favicon": "~1.0.0"
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/00-preparation/00-01-preclass.md:
--------------------------------------------------------------------------------
1 | Preclass Preparation
2 | ====
3 |
4 | You will need to install a few applications on your computer for this course, set up what's called your *development environment*, and create SSH keys, or *Secure Shell* keys for access to GitHub.
5 |
6 | Instructions are provided for Macintosh and Windows computers, the two operating systems supported by this course material. If you are not familiar with the command line, expect to spend a couple hours on this.
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/A-exercise-solutions/10-node-intro/mycopy.js:
--------------------------------------------------------------------------------
1 |
2 | var fs = require('fs');
3 |
4 | var src = process.argv[2];
5 | var dest = process.argv[3];
6 |
7 | fs.readFile(src, function(err, data) {
8 | if (err) {
9 | console.log("Unable to read file " + src);
10 | } else {
11 | fs.writeFile(dest, data, function (err) {
12 | if (err) {
13 | console.log("Error writing file to " + dest);
14 | } else {
15 | console.log("Copied from " + src + " to " + dest);
16 | }
17 | });
18 | }
19 | });
20 |
--------------------------------------------------------------------------------
/06-javascript-functions/06-exercises/javascript/is_number.js:
--------------------------------------------------------------------------------
1 | var input = process.argv[2];
2 |
3 | /* run your program from the command line: $ node number.js input
4 | * for example: $ node is_number.js 12
5 | * for example: $ node is_number.js "philip"
6 | *
7 | * whatever input you provide will be available in the variable input
8 | * your program should check if input is a number
9 | *
10 | * if it is a number, print out " is a valid number" where is the number
11 | * for example: "12 is a valid number"
12 | *
13 | * if it is not a number, print out "" is not a number" where is the number
14 | * for example: "philip is not a number"
15 |
16 | * use the following built-in functions:
17 | * console.log()
18 | * isNaN()
19 | */
20 |
21 |
--------------------------------------------------------------------------------
/08-javascript-functions-adv/08-examples/map.js:
--------------------------------------------------------------------------------
1 |
2 | function map(array, callback) {
3 | var newarray = [];
4 | for (var i = 0; i < array.length; i++) {
5 | newarray[i] = callback(array[i]);
6 | }
7 | return newarray;
8 | }
9 |
10 | var people = [
11 | {
12 | firstName: "OK",
13 | lastName: "Coders",
14 | age: 1,
15 | city: "OKC"
16 | },
17 | {
18 | firstName: "Philip",
19 | lastName: "Dow",
20 | age: 32,
21 | city: "Norman"
22 | },
23 | {
24 | firstName: "Marky",
25 | lastName: "Mark",
26 | age: 39,
27 | city: "Los Angeles"
28 | },
29 | {
30 | firstName: "Ellen",
31 | lastName: "Ripley",
32 | age: 28,
33 | city: "Nostromo"
34 | }
35 | ];
36 |
37 | var firstNames = map(people, function(item) {
38 | return item.firstName;
39 | });
40 |
41 | console.log(firstNames);
--------------------------------------------------------------------------------
/10-node/10-01-readme.md:
--------------------------------------------------------------------------------
1 | OK Coders: Lesson 9, Introduction to Node
2 | ===========================
3 |
4 | Lesson material contained in intro-node.md.
5 |
6 | The examples directory contains example code used during the lesson. `cd` into the eamples directory to run each program with node.
7 |
8 | ## Reading Files
9 |
10 | `readfile.js` reads the content in `about.txt` and prints it to the console.
11 |
12 | **Usage**
13 |
14 | $ node readfile.js
15 |
16 | ## Using Modules
17 |
18 | `calculator.js` imports `circle.js` as a module and uses it to compute the area of a circle.
19 |
20 | **Usage**
21 |
22 | $ node calculator.js
23 |
24 | ## A Simple HTTP Server
25 |
26 | `server.js` creates a web server and can either send a hello world response or a file.
27 |
28 | **Simple Usage**
29 |
30 | Sends "hello world" to every request.
31 |
32 | $ node server.js
33 |
34 | **Advanced Usage**
35 |
36 | Sends the "index.html" file to every request.
37 |
38 | $ node server.js advanced
--------------------------------------------------------------------------------
/A-exercise-solutions/10-node-intro/server.js:
--------------------------------------------------------------------------------
1 |
2 | // build a server that can server files from the public directory
3 |
4 | var http = require('http');
5 | var fs = require('fs');
6 | var path = require('path');
7 |
8 | var server = http.createServer(function (req, res) {
9 | console.log(req.url);
10 |
11 | var filename = path.join(__dirname, "public", req.url);
12 | console.log(filename);
13 |
14 | fs.exists(filename, function(exist) {
15 | if (!exists) {
16 | res.writeHead(200, {'Content-Type': 'text/plain'});
17 | res.end("File does not exist " + req.url);
18 | } else {
19 | fs.readFile(filename, function(err, data) {
20 | if (err) {
21 | res.writeHead(200, {'Content-Type': 'text/plain'});
22 | res.end("Unable to read file " + req.url);
23 | } else {
24 | res.writeHead(200, {'Content-Type': 'text/html'});
25 | res.end(data.toString());
26 | }
27 | });
28 | }
29 | });
30 | });
31 |
32 |
33 | server.listen(3000, '127.0.0.1');
34 |
--------------------------------------------------------------------------------
/15-mongoose/15-template/routes/posts.js:
--------------------------------------------------------------------------------
1 | var express = require('express');
2 | var router = express.Router();
3 |
4 | var Post = require('./../models/post');
5 |
6 | // posts
7 |
8 | router.get('/', function(req, res) {
9 | var posts = Post.all();
10 | res.render('posts/index', {posts: posts});
11 | });
12 |
13 | router.get('/new', function(req, res) {
14 | res.render('posts/new');
15 | });
16 |
17 | router.post('/', function(req, res) {
18 | res.status(404).send('create post')
19 | });
20 |
21 | router.get('/:id', function(req, res) {
22 | var post = Post.find( req.params.id );
23 | res.render('posts/show', {post: post});
24 | });
25 |
26 | router.get('/:id/edit', function(req, res) {
27 | var post = Post.find( req.params.id );
28 | res.render('posts/edit', {post: post});
29 | });
30 |
31 | router.put('/:id', function(req, res) {
32 | res.status(404).send('update post: ' + req.params.id);
33 | });
34 |
35 | router.delete('/:id', function(req, res) {
36 | res.status(404).send('delete post ' + req.params.id)
37 | });
38 |
39 | module.exports = router;
--------------------------------------------------------------------------------
/15-mongoose/15-template/routes/comments.js:
--------------------------------------------------------------------------------
1 | var express = require('express');
2 | var router = express.Router();
3 |
4 | router.get('/:pid/comments', function(req, res) {
5 | res.status(404).send('all comments, post: ' + req.params.pid );
6 | });
7 |
8 | router.get('/:pid/comments/new', function(req, res) {
9 | res.status(404).send('new comment form, post: ' + req.params.pid);
10 | });
11 |
12 | router.post('/:pid/comments', function(req, res) {
13 | res.status(404).send('create comment, post: ' + req.params.pid)
14 | });
15 |
16 | router.get('/:pid/comments/:id', function(req, res) {
17 | res.status(404).send('show a comment, post: ' + req.params.id +
18 | ' comment: ' + req.params.pid);
19 | });
20 |
21 | router.get('/:pid/comments/:id/edit', function(req, res) {
22 | res.status(404).send('edit comment, post: ' + req.params.pid +
23 | ' comment: ' + req.params.id);
24 | });
25 |
26 | router.put('/:pid/comments/:id', function(req, res) {
27 | res.status(404).send('update commen, post: ' + req.params.pid +
28 | ' comment: ' + req.params.id);
29 | });
30 |
31 | router.delete('/:pid/comments/:id', function(req, res) {
32 | res.status(404).send('delete comment, post: ' + req.params.pid +
33 | ' comment: ' + req.params.id);
34 | });
35 |
36 | module.exports = router;
--------------------------------------------------------------------------------
/02-html/02-exercises/public/suggestions.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
21 |
22 |
23 |
24 | Contact Us
25 |
26 |
29 |
30 | Name
31 |
32 | Email
33 |
34 | Query
35 |
36 | Question
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/10-node/10-exercises/template/test.txt:
--------------------------------------------------------------------------------
1 | The standard Lorem Ipsum passage, used since the 1500s
2 |
3 | "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
4 |
5 | Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC
6 |
7 | "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"
--------------------------------------------------------------------------------
/A-exercise-solutions/10-node-intro/test.txt:
--------------------------------------------------------------------------------
1 | The standard Lorem Ipsum passage, used since the 1500s
2 |
3 | "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
4 |
5 | Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC
6 |
7 | "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"
--------------------------------------------------------------------------------
/A-exercise-solutions/10-node-intro/test2.txt:
--------------------------------------------------------------------------------
1 | The standard Lorem Ipsum passage, used since the 1500s
2 |
3 | "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
4 |
5 | Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC
6 |
7 | "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"
--------------------------------------------------------------------------------
/A-exercise-solutions/10-node-intro/public/about.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Bootstrap 101 Template
8 |
9 |
10 |
11 |
12 |
13 |
14 |
18 |
19 |
20 |
21 |
22 |
23 |
Example Server: About
24 |
25 |
26 | Here's my nice server code and the about page
27 | with a public directory.
28 |
26 | Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.
27 |
26 | Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.
27 |
26 | Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.
27 |
35 | var ages = [16,21,30,45,60,75];
36 | var young = select(ages, function(item) {
37 | return (item <= 25);
38 | });
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/06-javascript-functions/06-exercises/06-exercises.md:
--------------------------------------------------------------------------------
1 | Lesson 6 Exercises: JavaScript Functions
2 | ====
3 |
4 | The homework assignments are contained in the *javascript* folder included in this directory. Download this repository as a zip file to your computer usign the **Download Zip** button on the bottom right of the home page for this repository, or fork and clone this repository using git. For more information about forking and cloning git respositories, see:
5 |
6 | [Forking a repo](https://help.github.com/articles/fork-a-repo/)
7 |
8 | GitHub instructions for forking and cloning a repo.
9 |
10 | [Syncing a fork](https://help.github.com/articles/syncing-a-fork/)
11 |
12 | This will come in handy for future lessons.
13 |
14 | [Generating SSH Keys](https://help.github.com/articles/generating-ssh-keys)
15 |
16 | GitHub instructions for setting up SSH keys to work with GitHub.
17 |
18 | Read through each javascript file and complete the assignments it contains. Further instructions are provided in each file. In general you will edit each file and run it from the command line using node until the output matches the instructions or all the tests are passing.
19 |
20 | ## Code Academy
21 |
22 | Continue working through the [Code Academy JavaScript](http://www.codecademy.com/tracks/javascript) lessons. There is almost certainly not enough practice in this homework, and you want to get as much practice as possible with the basics.
23 |
24 | ## Eloquent JavaScript
25 |
26 | Continue reading [Eloquent JavaScript](http://eloquentjavascript.net/contents.html). Review the first three chapters, which you should have already read, and move on to the chapters on Data Strutures, Functional programming and Object-oriented Programming.
--------------------------------------------------------------------------------
/01-command-line/01-exercises/01-exercises.md:
--------------------------------------------------------------------------------
1 | OK Coders Lesson 1 Exercises
2 | ====
3 |
4 | Complete all homework assignments before coming to the next class or as otherwise instructed.
5 |
6 | ### 1. Create an express app and upload it to heroku
7 |
8 | This evening's homework assignment is straightforward: create a new Express web application just like we did in class and upload it to Heroku. Refer to the [lesson material from today's class](https://github.com/okcoders/bash-heroku-class) if you run into trouble.
9 |
10 | This homework assignment is designed to reinforce your understanding of the command line and of git and heroku.
11 |
12 | ### 2. Review material on the command line and git
13 |
14 | Two free books on the command line and on git were mentioned in class. Consider these books textbooks and study them.
15 |
16 | - [The Linux Command Line, by William Shots](http://linuxcommand.org/tlcl.php) : Read the first four chapters by the end of the week. Practice the material at the command line.
17 | - [Pro Git](http://git-scm.com/book) : Read the first two chapters by the end of the week on Getting Started and Git Basics.
18 |
19 | ### 3. Begin learning JavaScript
20 |
21 | We will not start JavaScript programming until the 3rd week, but you should begin learning JavaScript before then. We will use the excellent and free [Eloquent JavaScript](http://eloquentjavascript.net/) for this class. Consider it a textbook.
22 |
23 | Read and practice with the first four chapters by the beginning of the third week. Don't put this off! Work in small batches rather than waiting to cram at the end.
24 |
25 | If you would like additional JavaScript practice, sign up for a free account at [Code Academy](http://www.codecademy.com/) and begin working through their JavaScript lessons.
--------------------------------------------------------------------------------
/10-node/10-examples/readfile.js:
--------------------------------------------------------------------------------
1 |
2 | // Import the fs module. The fs module includes APIs for dealing with the file system.
3 | // The functions are attached to the fs module so that it behaves like an object.
4 | // Call them with fs.functionName()
5 |
6 | var fs = require('fs');
7 |
8 | // Get the sync/async argument from the command line
9 |
10 | var async = (process.argv[2] != 'sync');
11 |
12 | if (async) {
13 |
14 | // Demonstrate asynchronous file reading. Note that "Called the Read File Method"
15 | // is printed to the console before the file's contents are.
16 |
17 | // fs.readFile() is an asynchronous operation. Your program continues executing
18 | // while it does work in the background. You provide a callback function that is
19 | // executed once its operation is complete.
20 |
21 | console.log("About to Read File");
22 |
23 | fs.readFile('about.txt', function(err, data) {
24 | if (err) {
25 | console.log("Unable to read file about.txt");
26 | } else {
27 | console.log("File Contents:");
28 | console.log(data.toString());
29 | }
30 | });
31 |
32 | console.log("Called fs.readFile()\n");
33 |
34 | } else {
35 |
36 | // Demonstrate synchronous file reading. Note that this time "Called the Read File Method"
37 | // is printed to the console before the file's contents are.
38 |
39 | // Because fs.readFileSync() is synchronous, it completes its operation before
40 | // returning control to your code and returns the result
41 |
42 | console.log("About to Read File\n");
43 |
44 | var data = fs.readFileSync('about.txt');
45 | if (!data) {
46 | console.log("Unable to read file about.txt");
47 | } else {
48 | console.log("File Contents:");
49 | console.log(data.toString());
50 | }
51 |
52 |
53 | console.log("\nCalled fs.readFileSync()")
54 | }
--------------------------------------------------------------------------------
/07-javascript-data-structures/07-exercises/07-exercises.md:
--------------------------------------------------------------------------------
1 | Lesson 7 Exercises: JavaScript Structures
2 | =====
3 |
4 | The homework assignments are contained in the .js files included in this subdirectory. Download this repository as a zip file to your computer usign the **Download Zip** button on the bottom right of the home page for this repository, or fork and clone this repository using git. For more information about forking and cloning git respositories, see:
5 |
6 | [Forking a repo](https://help.github.com/articles/fork-a-repo/)
7 |
8 | GitHub instructions for forking and cloning a repo.
9 |
10 | [Syncing a fork](https://help.github.com/articles/syncing-a-fork/)
11 |
12 | This will come in handy for future lessons.
13 |
14 | [Generating SSH Keys](https://help.github.com/articles/generating-ssh-keys)
15 |
16 | GitHub instructions for setting up SSH keys to work with GitHub.
17 |
18 | Read through each javascript file and complete the assignments it contains. Further instructions are provided in each file. In general you will edit each file and run it from the command line using node until the output matches the instructions or all the tests are passing, e.g.
19 |
20 | $ node arrays.js
21 | test 1 passed
22 | test 2 failed *
23 | test 3 failed *
24 | test 4 failed *
25 | test 5 failed *
26 | test 6 failed *
27 | test 7 failed *
28 | test 8 failed *
29 | test 9 failed *
30 |
31 | ## Code Academy
32 |
33 | Continue working through the [Code Academy JavaScript](http://www.codecademy.com/tracks/javascript) lessons. There is almost certainly not enough practice in this homework, and you want to get as much practice as possible with the basics.
34 |
35 | ## Eloquent JavaScript
36 |
37 | Continue reading [Eloquent JavaScript](http://eloquentjavascript.net/contents.html). Review the first four chapters, which you should have already read, and move on to the chapters on Data Strutures, Functional programming and Object-oriented Programming.
--------------------------------------------------------------------------------
/15-mongoose/15-template/app.js:
--------------------------------------------------------------------------------
1 | var express = require('express');
2 | var path = require('path');
3 | var favicon = require('static-favicon');
4 | var logger = require('morgan');
5 | var cookieParser = require('cookie-parser');
6 | var bodyParser = require('body-parser');
7 |
8 | var routes = require('./routes/index');
9 | var users = require('./routes/users');
10 |
11 | // posts and comments
12 | var posts = require('./routes/posts');
13 | var comments = require('./routes/comments');
14 |
15 | var app = express();
16 |
17 | // view engine setup
18 | app.set('views', path.join(__dirname, 'views'));
19 | app.set('view engine', 'ejs');
20 |
21 | app.use(favicon());
22 | app.use(logger('dev'));
23 | app.use(bodyParser.json());
24 | app.use(bodyParser.urlencoded());
25 | app.use(cookieParser());
26 | app.use(express.static(path.join(__dirname, 'public')));
27 |
28 | app.use('/', routes);
29 | app.use('/users', users);
30 |
31 | // posts and comments
32 | app.use('/posts', posts);
33 | app.use('/posts', comments);
34 |
35 | app.param(':pid', function(req, res, next) {
36 | console.log('pid request');
37 | next();
38 | });
39 |
40 | /// catch 404 and forward to error handler
41 | app.use(function(req, res, next) {
42 | var err = new Error('Not Found');
43 | err.status = 404;
44 | next(err);
45 | });
46 |
47 | /// error handlers
48 |
49 | // development error handler
50 | // will print stacktrace
51 | if (app.get('env') === 'development') {
52 | app.use(function(err, req, res, next) {
53 | res.status(err.status || 500);
54 | res.render('error', {
55 | message: err.message,
56 | error: err
57 | });
58 | });
59 | }
60 |
61 | // production error handler
62 | // no stacktraces leaked to user
63 | app.use(function(err, req, res, next) {
64 | res.status(err.status || 500);
65 | res.render('error', {
66 | message: err.message,
67 | error: {}
68 | });
69 | });
70 |
71 |
72 | module.exports = app;
73 |
--------------------------------------------------------------------------------
/02-html/02-exercises/public/resources.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
21 |
22 |
23 |
24 | Resources
25 |
26 |
27 |
28 |
29 | Version Control
30 | GitHub: https://github.com/
31 | Git Book: http://git-scm.com/book
32 | Git Tutorials: http://sixrevisions.com/resources/git-tutorials-beginners/
33 |
34 |
35 | HTML
36 | Mozilla Developer Network: https://developer.mozilla.org/en-US/
37 | W3 Schools: http://www.w3schools.com/
38 | Validator: http://validator.w3.org/
39 |
40 |
41 | CSS
42 | W3 Schools: http://www.w3schools.com/css/
43 | CSS Box Model: http://www.w3schools.com/css/css_boxmodel.asp
44 | Twitter Bootstrap: http://getbootstrap.com/
45 | CSS Animations: http://daneden.me/animate/
46 |
47 |
48 | JavaScript
49 | jQuery: http://jquery.com/
50 | Underscore.js: http://underscorejs.org/
51 | JSHint: http://www.jshint.com/
52 | D3.js (visualization): http://d3js.org/
53 |
54 | More
55 | HTML5 Rocks: http://www.html5rocks.com/en/
56 | Can I Use It (browser support): http://caniuse.com/
57 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/10-node/10-examples/server.js:
--------------------------------------------------------------------------------
1 |
2 | // Import the http and fs module. The fs module includes APIs for dealing with the file system,
3 | // while the http module is used for handling HTTP web requests.
4 | // The functions are attached to the fs module so that it behaves like an object.
5 | // Call them with fs.functionName()
6 |
7 | var http = require('http'),
8 | fs = require('fs');
9 |
10 | // Get the simple/advanced argument from the command line
11 |
12 | var simple = (process.argv[2] != 'advanced');
13 |
14 | if (simple) {
15 |
16 | // Create the server. The function takes a callback that is called every time
17 | // the server receives a request and returns the server object.
18 |
19 | // The callback function includes two parameters, a request object that describes
20 | // the http request and a response object to which the response is written
21 |
22 | var server = http.createServer(function (req, res) {
23 | console.log(req.url);
24 | res.writeHead(200, {'Content-Type': 'text/plain'});
25 | res.end('Hello World\n');
26 | });
27 |
28 | // Begin listening for requests at the localhost address on port 3000
29 |
30 | server.listen(3000, '127.0.0.1');
31 | console.log('Simple server running at http://127.0.0.1:3000/');
32 |
33 | } else {
34 |
35 | // Create the server. The function takes a callback that is called every time
36 | // the server receives a request and returns the server object.
37 |
38 | // But this time our callback function will read in the index.html file and
39 | // send that as the response.
40 |
41 | var server = http.createServer(function (req, res) {
42 | console.log(req.url);
43 | fs.readFile('index.html', {encoding: 'utf8'}, function(err, data) {
44 | if (err) {
45 | res.writeHead(200, {'Content-Type': 'text/plain'});
46 | res.end("Unable to read file index.html\n");
47 | } else {
48 | res.writeHead(200, {'Content-Type': 'text/html'});
49 | res.end(data);
50 | }
51 | });
52 | });
53 |
54 | // Begin listening for requests at the localhost address on port 3000
55 |
56 | server.listen(3000, '127.0.0.1');
57 | console.log('Advanced server running at http://127.0.0.1:3000/');
58 |
59 | }
--------------------------------------------------------------------------------
/02-html/02-exercises/public/syllabus.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
22 |
23 |
24 |
25 | Syllabus
26 |
27 |
28 |
29 | Week 1: Web Pages: HTML, CSS, Twitter Bootstrap [colspan=2]
30 |
31 | Lesson 1: HTML5, CSS https://developer.mozilla.org/en-US/docs/Web/HTML
32 | Lesson 2: Advanced CSS, Twitter Bootstrap http://twitter.github.com/bootstrap/
33 |
34 | Week 2: JavaScript and JavaScript Libraries [colspan=2]
35 |
36 | Lesson 3: The DOM, JavaScript http://eloquentjavascript.net
37 | Lesson 4: jQuery, Underscore.js http://jquery.com/ , http://underscorejs.org
38 |
39 | Week 3: Full Stack JavaScript [colspan=2]
40 |
41 | Lesson 5: Node, Express.js http://nodejs.org/ , http://expressjs.com/
42 | Lesson 6: Introduction to Backbone.js http://www.backbonejs.org
43 |
44 | Week 4: Databases and APIs [colspan=2]
45 |
46 | Lesson 7: MongoDB in Node, APIs http://www.mongodb.org/ , http://mongoosejs.com/
47 | Lesson 8: Advanced Backbone
48 |
49 | Week 5: Web Applications [colspan=2]
50 |
51 | Lesson 9: Putting it All Together Single page, API backed, full stack JavaScript web applications
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/16-express-creating-data/16-template/app.js:
--------------------------------------------------------------------------------
1 | var express = require('express');
2 | var path = require('path');
3 | var favicon = require('static-favicon');
4 | var logger = require('morgan');
5 | var cookieParser = require('cookie-parser');
6 | var bodyParser = require('body-parser');
7 | var mongoose = require('mongoose');
8 |
9 | var routes = require('./routes/index');
10 | var users = require('./routes/users');
11 |
12 | // posts and comments
13 | var posts = require('./routes/posts');
14 | var comments = require('./routes/comments');
15 |
16 | var app = express();
17 |
18 | // database connection
19 | mongoose.connect('mongodb://localhost/blog');
20 | var db = mongoose.connection;
21 |
22 | db.on('error', function(msg) {
23 | console.log('Mongoose connection error %s', msg);
24 | });
25 |
26 | db.once('open', function() {
27 | console.log('Mongoose connection established');
28 | });
29 |
30 | // view engine setup
31 | app.set('views', path.join(__dirname, 'views'));
32 | app.set('view engine', 'ejs');
33 |
34 | app.use(favicon());
35 | app.use(logger('dev'));
36 | app.use(bodyParser.json());
37 | app.use(bodyParser.urlencoded());
38 | app.use(cookieParser());
39 | app.use(express.static(path.join(__dirname, 'public')));
40 |
41 | app.use('/', routes);
42 | app.use('/users', users);
43 |
44 | // posts and comments
45 | app.use('/posts', posts);
46 | app.use('/posts', comments);
47 |
48 | /// catch 404 and forward to error handler
49 | app.use(function(req, res, next) {
50 | var err = new Error('Not Found');
51 | err.status = 404;
52 | next(err);
53 | });
54 |
55 | /// error handlers
56 |
57 | // development error handler
58 | // will print stacktrace
59 | if (app.get('env') === 'development') {
60 | app.use(function(err, req, res, next) {
61 | res.status(err.status || 500);
62 | res.render('error', {
63 | message: err.message,
64 | error: err
65 | });
66 | });
67 | }
68 |
69 | // production error handler
70 | // no stacktraces leaked to user
71 | app.use(function(err, req, res, next) {
72 | res.status(err.status || 500);
73 | res.render('error', {
74 | message: err.message,
75 | error: {}
76 | });
77 | });
78 |
79 |
80 | module.exports = app;
81 |
--------------------------------------------------------------------------------
/09-javascript-oop/09-exercises/09-exercises.md:
--------------------------------------------------------------------------------
1 | OK Coders: Lesson 9 Exercises
2 | =================================
3 |
4 | The homework assignments are contained in the .js files included in this subdirectory. Download this repository as a zip file to your computer usign the **Download Zip** button on the bottom right of the home page for this repository, or fork and clone this repository using git. For more information about forking and cloning git respositories, see:
5 |
6 | [Forking a repo](https://help.github.com/articles/fork-a-repo/)
7 |
8 | GitHub instructions for forking and cloning a repo.
9 |
10 | [Syncing a fork](https://help.github.com/articles/syncing-a-fork/)
11 |
12 | This will come in handy for future lessons.
13 |
14 | [Generating SSH Keys](https://help.github.com/articles/generating-ssh-keys)
15 |
16 | GitHub instructions for setting up SSH keys to work with GitHub.
17 |
18 | Read through each javascript file and complete the assignments it contains. Further instructions are provided in each file. In general you will edit each file and run it from the command line using node until the output matches the instructions or all the tests are passing.
19 |
20 | ## Create a Heroku Homework Site
21 |
22 | It's been a few weeks since we used node, express and heroku to create a website, but it's time to review!
23 |
24 | Create a new express application. Create two html files in the public folder, `functions.html` and `objects.html`, one for your functions homework assignment and one for the objects homework assignment in this repository. Add twitter bootstrap styling to the pages, and link to each page from the other.
25 |
26 | Embed your solutions for today's homework assignment into their respective pages. For example, you will have an implementation for the `select` function in the `higher-order.js` file. Embedd your javascript code into the `functions.html` file so that you can view it in a web browser. See the **Code** section in the **CSS** document on the twitter bootstrap homepage for information on which tag to use to get your formatting right, and refer to the `example.html` file in this repository for help.
27 |
28 | Create a git repository for your express application and then create a heroku application for it and upload it to heroku.
29 |
30 | You may need to review some of the old lesson material on Git, Bash & Heroku (Lesson 01) or Using Bootstrap (Lesson 04).
31 |
--------------------------------------------------------------------------------
/A-exercise-solutions/04-bootstrap-class-example/public/forms.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Bootstrap 101 Template
8 |
9 |
10 |
11 |
12 |
13 |
14 |
18 |
19 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
Hello, world!
36 |
37 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/09-javascript-oop/09-exercises/javascript/object-oriented.js:
--------------------------------------------------------------------------------
1 |
2 | // Instructions
3 | // cd into the correct directory and run this file with `node objects.js`
4 | // You will see a number of failing tests.
5 | // Complete each of the problems by filling in the provided variables and functions
6 | // with the correct values to get the tests to pass.
7 |
8 |
9 | // 1.
10 | // Create an object with a name property and a getName method. The getName
11 | // method should return the value in the name property.
12 |
13 | var obj1 = {
14 | name: "OK Coders"
15 | };
16 |
17 |
18 | // 2.
19 | // Create an object with four properties: address, city, state, zip
20 | // Add a function mailingAddress that returns a string composed of the four
21 | // properties with the following format:
22 | // address
23 | // city, state zip
24 | // For example:
25 | // 419 Foobar St.
26 | // Oklahoma City, OK 73069
27 | // When composing strings, use the "\n" sequence to represent a newline.
28 | // Pay special attention to the string formatting!
29 | // Use console.log if you need help debugging
30 |
31 | var obj2 = {
32 | address: "419 Foobar St.",
33 | city: "Oklahoma City",
34 | state: "OK",
35 | zip: "73003"
36 | }
37 |
38 |
39 | // 3.
40 | // Create an object with one property, age, and one method, canDrink.
41 | // The canDrink method should return true if and only if the age is greater than
42 | // or equal to 21.
43 |
44 | var obj3 = {
45 | age: 19
46 | };
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 | // ==================================================
56 | // TESTS
57 |
58 | obj1.name = "Philip Dow";
59 | if ( obj1.getName && typeof obj1.getName == 'function' && obj1.getName() == obj1.name ) {
60 | console.log("test 1 passed");
61 | } else {
62 | console.log("test 1 failed *");
63 | }
64 |
65 |
66 | obj2.address = "420 Qux Street";
67 | if ( obj2.mailingAddress && typeof obj2.mailingAddress == 'function' ) {
68 | var mailing = obj2.mailingAddress();
69 | if (mailing == "420 Qux Street\nOklahoma City, OK 73003") {
70 | console.log("test 2 passed");
71 | } else {
72 | console.log("test 2 failed *");
73 | }
74 | } else {
75 | console.log("test 2 failed *");
76 | }
77 |
78 |
79 | if ( obj3.canDrink && typeof obj3.canDrink == 'function' &&
80 | (obj3.age = 18) && obj3.canDrink() == false &&
81 | (obj3.age = 45) && obj3.canDrink() == true ) {
82 | console.log("test 3 passed");
83 | } else {
84 | console.log("test 3 failed *");
85 | }
86 |
--------------------------------------------------------------------------------
/06-javascript-functions/06-exercises/javascript/booleans.js:
--------------------------------------------------------------------------------
1 |
2 | /* declare and test all of the functions described in this file
3 | * run the file with $ node booleans.js
4 | */
5 |
6 |
7 | /* 1. write a function called not that reverses the value of
8 | * its boolean parameter and returns it
9 | *
10 | * you might use the ! boolean operation
11 | * refer to the javascript intro variables and values
12 | *
13 | * print the result of calling the function not to the console, eg:
14 | * console.log( not(true) ); -> "false"
15 | * console.log( not(false) ); -> "true"
16 | */
17 |
18 |
19 | /*
20 | * 2. create a function called andTable that checks all possible combinations
21 | * of performing the 'and' operation on two boolean parameters
22 | * and prints out the result of the operation
23 |
24 | * the template should help you get started
25 | */
26 |
27 | function andTable(boolean1, boolean2) {
28 | if (boolean1 == true && boolean2 == true) {
29 | console.log("true && true : true");
30 | }
31 | // fill in the rest with additional else if statements
32 | }
33 |
34 | andTable(true, true);
35 | andTable(true, false);
36 | andTable(false, true);
37 | andTable(false, false);
38 |
39 | console.log(); // just print a blank line
40 |
41 | /*
42 | * 3. create a functionc called orTable that checks all possible combinations
43 | * of performing the 'or' operation on two boolean parameters
44 | * and prints out the result of the operation
45 |
46 | * the template should help you get started
47 | */
48 |
49 | function orTable(boolean1, boolean2) {
50 | if (boolean1 == true && boolean2 == true) {
51 | console.log("true || true : true");
52 | }
53 | // fill in the rest with additional else if statements
54 | // be careful, still using an && for the test!
55 | }
56 |
57 | orTable(true, true);
58 | orTable(true, false);
59 | orTable(false, true);
60 | orTable(false, false);
61 |
62 | /* 4. define the following variables correctly so that
63 | * "Reached inside condition" is printed
64 | *
65 | * that is, you need to assign the right values to the variables
66 | * so that all the conditions are met for the
67 | * control flow to reach the console.log() call.
68 | *
69 | * consider what kind of value you need in each case, including
70 | * strings, numbers and booleans
71 | */
72 |
73 | var x;
74 | var y;
75 | var z;
76 | var q;
77 |
78 |
79 | if (!x) {
80 | if (y && z < 100) {
81 | if (q == "OK Coders".toLowerCase()) {
82 | console.log("Reached inside condition");
83 | }
84 | }
85 | }
86 |
87 |
--------------------------------------------------------------------------------
/02-html/02-exercises/02-exercises.md:
--------------------------------------------------------------------------------
1 | OK Coders: Lesson 2 Exercises
2 | ====
3 |
4 | Complete all homework assignments before coming to the next class or as otherwise instructed.
5 |
6 | ## Create an express app, add static content, upload it to heroku
7 |
8 | Create a new Express web application. Do not reuse previous express applications. The intent is to practice using the command line and creating applications from scratch quickly.
9 |
10 | Copy all the html files from the *public* directory in this repository into the public directory of your express application. Place them directly in the public directory.
11 |
12 | Each html file includes plain text that you should mark up with html. Refer to each html file for further instructions.
13 |
14 | Test your application locally as you go, and upload the express application to heroku using git. You'll need to create a git repository, continually add content to it, create a heroku application, and upload to it.
15 |
16 | ## Review the html elements
17 |
18 | Mozilla has excellent html documention. Review the elements list, paying special attention to the new html5 elements. View the documentation for a few of the elements.
19 |
20 | The intent is to familiarize you with Mozilla's html documentation. You may need to use elements in the future that we do not cover in class.
21 |
22 | [Mozilla's HTML5 Elements List](https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5/HTML5_element_list)
23 |
24 | ## Continue reviewing material on the command line and git
25 |
26 | Two free books on the command line and on git were mentioned in class. Consider these books textbooks and study them.
27 |
28 | - [The Linux Command Line, by William Shots](http://linuxcommand.org/tlcl.php) : Read the first four chapters by the end of the week one. Practice the material at the command line.
29 | - [Pro Git](http://git-scm.com/book) : Read the first two chapters by the end of the week 1oneon Getting Started and Git Basics.
30 |
31 | ## Continue learning JavaScript
32 |
33 | We will not start JavaScript programming until the 3rd week, but you should continue learning JavaScript before then. We will use the excellent and free [Eloquent JavaScript](http://eloquentjavascript.net/) for this class. Consider it a textbook.
34 |
35 | Read and practice with the first four chapters by the beginning of the third week. Don't put this off! Work in small batches rather than waiting to cram at the end.
36 |
37 | If you would like additional JavaScript practice, sign up for a free account at [Code Academy](http://www.codecademy.com/) and begin working through their JavaScript lessons.
--------------------------------------------------------------------------------
/06-javascript-functions/06-exercises/javascript/functions.js:
--------------------------------------------------------------------------------
1 |
2 | /* declare and test all of the functions described in this file
3 | * run the file with $ node functions.js
4 | */
5 |
6 |
7 |
8 |
9 | /* 1. declare a function called hugeNumber that takes no parameters
10 | * return the number 2 to the 64th power
11 | *
12 | * you should use the following built-in function:
13 | * Math.pow()
14 |
15 | * print out the result of calling the function, for example:
16 | * console.log( hugeNumber() ) -> 18446744073709552000
17 | */
18 |
19 |
20 |
21 |
22 | /* 2. declare a function called testIt that takes one parameter,
23 | * the number 'x'
24 | *
25 | * if x is less than 0, print out " is negative"
26 | * if x is equal to 0, print out " is zero"
27 | * if x is greater than 0, print out " is positive"
28 | * in each case, replace with the actual number
29 | *
30 | * use a switch statement for your tests (refer to eloquent javascript)
31 | * use console.log() to print out the text from within the function
32 | *
33 | * for example:
34 | * testIt(-100); -> "-100 is negative"
35 | * testIt(0); -> "0 is zero"
36 | * testIt(100); -> "100 is postive"
37 | */
38 |
39 |
40 |
41 |
42 | /* 3. declare a function called addSuffix that takes two parameters,
43 | * the string 'name' and the boolean 'male'
44 | *
45 | * if 'male' is true, return a string with 'Mr. ' prepended to it.
46 | * if 'male' is false, return a string with 'Mrs. ' prepended to it.
47 |
48 | * you only need string concatenation and an if statement
49 |
50 | * print out the result of calling the function, for example:
51 | * console.log( addSuffix("Philip Dow", true) ); -> "Mr. Philip Dow"
52 | * console.log( addSuffix("Mary Beth Havard", false) ); -> "Mrs. Mary Beth Havard"
53 | */
54 |
55 |
56 |
57 |
58 | /* 4. consider the following two functions foo and bar
59 | * try to understand what they are doing
60 | *
61 | * uncomment the calls to foo below them one at a time
62 | * (delete the // at the front of the line, which is a single line comment)
63 | *
64 | * what happens? why? follow the control flow of the program
65 | * and calculate the value that each function gets as you go
66 |
67 | * why does the program crash on the last example?
68 | */
69 |
70 | function foo(x) {
71 | console.log("foo has", x);
72 | if (x==0) {
73 | return x;
74 | } else {
75 | return bar(x-2);
76 | }
77 | }
78 |
79 | function bar(x) {
80 | console.log("bar has", x);
81 | if (x==1) {
82 | return x;
83 | } else {
84 | return foo(x-2);
85 | }
86 | }
87 |
88 | /* uncomment the next three lines one at a time and run the program */
89 |
90 | // foo(12);
91 | // foo(15);
92 | // bar(12);
93 |
94 |
95 |
--------------------------------------------------------------------------------
/00-preparation/00-03-win-setup.md:
--------------------------------------------------------------------------------
1 | Windows Instructions
2 | ====
3 |
4 | You must be running a recent version of Windows, at least Windows Vista or higher. Windows 7 or higher is strongly recommended. Ensure that you have installed the latest Windows updates for you version of windows.
5 |
6 | ## Install software
7 |
8 | Install the following software by downloading it at these urls:
9 |
10 | [Sublime Text](http://www.sublimetext.com/).
11 |
12 | This is the free text editor we will be using in class.
13 |
14 | [Google Chrome](https://www.google.com/intl/en-US/chrome/browser/).
15 |
16 | We will be doing all web development in Google Chrome because of its excellent developer tools.
17 |
18 | [Git Bash](http://msysgit.github.io/)
19 |
20 | Windows does come with a built-in command prompt, but we will be using another Terminal emulator with built-in support for git, the version control software that works with GitHub. *Do not use the built-in command prompt*. Use Git Bash.
21 |
22 | ## Configure Git
23 |
24 | Set your global git username and password. At the terminal, type the following two commands. Press enter after each one:
25 |
26 | git config --global user.name "Your Name"
27 | git config --global user.email your@email.address
28 |
29 | ## Install Node and Friends
30 |
31 | Install Node.js: [http://nodejs.org/](http://nodejs.org/).
32 |
33 | Install Express: Launch Git Bash from your Start menu and at the terminal, type the following two commands and press return after each one to execute it:
34 |
35 | npm install -g express-generator
36 |
37 | ## Set Up Heroku
38 |
39 | (You may skip this step for now)
40 |
41 | Sign up for a free account at Heroku: [https://www.heroku.com/](https://www.heroku.com/)
42 |
43 | Install the Heroku Command Line Interface: Follow the instructions at [https://devcenter.heroku.com/articles/heroku-command](https://devcenter.heroku.com/articles/heroku-command). Note you will need to install the Heroku Toolbelt.
44 |
45 | ## Set up your SSH keys
46 |
47 | SSH Keys are used to establish a secure connection to GitHub and Heroku.
48 |
49 | Follow the instructions at GitHub to create and register new SSH keys: [Generating SSH Keys for GitHub](https://help.github.com/articles/generating-ssh-keys).
50 |
51 | If you get an error when trying to add your keys to the ssh-agent, type the following command at the terminal prompt and press return:
52 |
53 | eval `ssh-agent -s`
54 |
55 | Follow the instructions at Heroku to register your SSH keys. **You do not need to create a new public/private keypair.** [Register SSH Keys with Heroku](https://devcenter.heroku.com/articles/keys)
56 |
57 | Nice work! You just set up your development environment and are already using the command line! This is serious stuff!
--------------------------------------------------------------------------------
/A-exercise-solutions/08-javascript-oop/object-oriented.js:
--------------------------------------------------------------------------------
1 |
2 | // Instructions
3 | // cd into the correct directory and run this file with `node objects.js`
4 | // You will see a number of failing tests.
5 | // Complete each of the problems by filling in the provided variables and functions
6 | // with the correct values to get the tests to pass.
7 |
8 |
9 | // 1.
10 | // Create an object with a name property and a getName method. The getName
11 | // method should return the value in the name property.
12 |
13 | var obj1 = {
14 | name: "OK Coders",
15 | getName: function() {
16 | return this.name;
17 | }
18 | };
19 |
20 |
21 | // 2.
22 | // Create an object with four properties: address, city, state, zip
23 | // Add a function mailingAddress that returns a string composed of the four
24 | // properties with the following format:
25 | // address
26 | // city, state zip
27 | // For example:
28 | // 419 Foobar St.
29 | // Oklahoma City, OK 73069
30 | // When composing strings, use the "\n" sequence to represent a newline.
31 | // Pay special attention to the string formatting!
32 | // Use console.log if you need help debugging
33 |
34 | var obj2 = {
35 | address: "419 Foobar St.",
36 | city: "Oklahoma City",
37 | state: "OK",
38 | zip: "73003",
39 |
40 | mailingAddress: function() {
41 | return this.address + "\n" + this.city + ", " +
42 | this.state + " " + this.zip;
43 | }
44 | }
45 |
46 |
47 | // 3.
48 | // Create an object with one property, age, and one method, canDrink.
49 | // The canDrink method should return true if and only if the age is greater than
50 | // or equal to 21.
51 |
52 | var obj3 = {
53 | age: 19,
54 | canDrink: function() {
55 | return (this.age >= 21);
56 | }
57 | };
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 | // ==================================================
67 | // TESTS
68 |
69 | obj1.name = "Philip Dow";
70 | if ( obj1.getName && typeof obj1.getName == 'function' && obj1.getName() == obj1.name ) {
71 | console.log("test 1 passed");
72 | } else {
73 | console.log("test 1 failed *");
74 | }
75 |
76 |
77 | obj2.address = "420 Qux Street";
78 | if ( obj2.mailingAddress && typeof obj2.mailingAddress == 'function' ) {
79 | var mailing = obj2.mailingAddress();
80 | if (mailing == "420 Qux Street\nOklahoma City, OK 73003") {
81 | console.log("test 2 passed");
82 | } else {
83 | console.log("test 2 failed *");
84 | }
85 | } else {
86 | console.log("test 2 failed *");
87 | }
88 |
89 |
90 | if ( obj3.canDrink && typeof obj3.canDrink == 'function' &&
91 | (obj3.age = 18) && obj3.canDrink() == false &&
92 | (obj3.age = 45) && obj3.canDrink() == true ) {
93 | console.log("test 3 passed");
94 | } else {
95 | console.log("test 3 failed *");
96 | }
97 |
--------------------------------------------------------------------------------
/03-css/03-exercises/public/columns.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Columns
6 |
7 |
8 |
9 |
27 |
28 |
29 |
30 |
74 |
75 |
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
34 | tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
35 | quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
36 | consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
37 | cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
38 | proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
39 |
40 |
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
41 | tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
42 | quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
43 | consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
44 | cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
45 | proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
81 |
82 |
83 |
84 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/03-css/03-exercises/03-exercises.md:
--------------------------------------------------------------------------------
1 | OK Coders: Lesson 3 Exercises
2 | ====
3 |
4 | Complete all homework assignments before coming to the next class or as otherwise instructed.
5 |
6 | ## Create an express app for css practice
7 |
8 | **Create a new express app**
9 |
10 | Similar to the previous homework assignment, create a new Express web application. Do not reuse previous express applications. The intent is to practice using the command line and creating applications from scratch quickly.
11 |
12 | **Grab the html and css from this repository**
13 |
14 | Copy all the html files from the public directory in this repository into the public directory of your express application. Don't forget to copy the files from the public/stylesheets directory into the public/stylesheets directory in your Express application.
15 |
16 | **Fill in the css**
17 |
18 | Each file includes html and content that is already marked up with id and class attributes. But the style definitions are missing! Add style definitions so that each documents appears as it should. Refer to the comments in each html file for further instructions.
19 |
20 | **Test your application and upload it to heroku**
21 |
22 | Test your application locally as you go, and upload the express application to heroku using git. You'll need to create a git repository, continually add content to it, create a heroku application, and upload to it.
23 |
24 | If you run out of Heroku application space because you are only allowed five before having to add a credit card, simply log into the Heroku dashboard and delete some of your applications:
25 |
26 | - [Log into Heroku Dashboard](https://dashboard.heroku.com/apps)
27 | - Click the settings gear icon on the right side of the page for an application
28 | - Scroll down to **Delete app** and click it
29 | - Follow instructions
30 |
31 | ## Review css selectors and properties
32 |
33 | Mozilla has excellent css documention. Review the properties list and make sure you understand selectors. We'll be using them with JavaScript as well.
34 |
35 | [Mozilla's CSS Documentation](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference)
36 |
37 | ## Continue reviewing material on the command line and git
38 |
39 | Two free books on the command line and on git were mentioned in class. Consider these books textbooks and study them.
40 |
41 | [The Linux Command Line, by William Shots](http://linuxcommand.org/tlcl.php) : Read past the first four chapters. Start to get into the advanced material likes pipes and redirection.
42 |
43 | [Pro Git](http://git-scm.com/book) : Make sure you have read the first two chapters, Getting Started and Git Basics, and begin working on branching in chapter three.
44 |
45 | ## Continue learning JavaScript
46 |
47 | We start JavaScript programming next week! Make sure you come to class prepared. We will use the excellent and free [Eloquent JavaScript](http://eloquentjavascript.net/) for this class.
48 |
49 | Read and practice with the first four chapters by the beginning of next week. Don't put this off!
50 |
51 | If you would like additional JavaScript practice, sign up for a free account at [Code Academy](http://www.codecademy.com/) and begin working through their JavaScript lessons.
--------------------------------------------------------------------------------
/15-mongoose/15-template/views/posts/index.ejs:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Blog Application
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
21 |
22 |
23 |
24 |
25 |
49 |
50 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/02-html/02-exercises/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
21 |
22 |
23 |
24 | Web Homework
25 |
26 |
27 |
28 | OK Coders: Lesson 2 Homework
29 |
30 | Complete all homework assignments before coming to the next class or as otherwise instructed.
31 |
32 | Create an express app, add static content, upload it to heroku
33 |
34 | Create a new Express web application. Do not reuse previous express applications. The intent is to practice using the command line and creating applications from scratch quickly.
35 |
36 | Copy all the html files from the html directory in this repository into the public directory of your express application. Don't put them in an 'html' folder. Place them directly in the public directory.
37 |
38 | Each html file includes plain text that you should mark up with html. Refer to each html file for further instructions.
39 |
40 | Test your application locally as you go, and upload the express application to heroku using git. You'll need to create a git repository, continually add content to it, create a heroku application, and upload to it.
41 |
42 |
43 | Review the html elements
44 |
45 | Mozilla has excellent html documention. Review the elements list, paying special attention to the new html5 elements. View the documentation for a few of the elements.
46 |
47 | The intent is to familiarize you with Mozilla's html documentation. You may need to use elements in the future that we do not cover in class.
48 |
49 | Mozilla's HTML5 Elements List
50 |
51 |
52 | Continue reviewing material on the command line and git
53 |
54 | Two free books on the command line and on git were mentioned in class. Consider these books textbooks and study them.
55 |
56 | The Linux Command Line, by William Shots : Read the first four chapters by the end of the week one. Practice the material at the command line.
57 |
58 | Pro Git : Read the first two chapters by the end of the week 1oneon Getting Started and Git Basics.
59 |
60 |
61 | Continue learning JavaScript
62 |
63 | We will not start JavaScript programming until the 3rd week, but you should continue learning JavaScript before then. We will use the excellent and free Eloquent JavaScript for this class. Consider it a textbook.
64 |
65 | Read and practice with the first four chapters by the beginning of the third week. Don't put this off! Work in small batches rather than waiting to cram at the end.
66 |
67 | If you would like additional JavaScript practice, sign up for a free account at Code Academy and begin working through their JavaScript lessons.
68 |
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/16-express-creating-data/16-template/views/posts/show.ejs:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Blog Application
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
21 |
22 |
23 |
24 |
25 |
49 |
50 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/07-javascript-data-structures/07-exercises/javascript/arrays.js:
--------------------------------------------------------------------------------
1 |
2 | // Instructions
3 | // cd into the correct directory and run the file with `node arrays.js`
4 | // You will see a number of failing tests.
5 | // Complete each of the 7 problems by filling in the provided variables
6 | // with the correct values to get the tests to pass.
7 |
8 | // 1.
9 | // Create an array with the following values in it in this order:
10 | // 1, 1, 2, 3, 5, 8, 13, 21
11 |
12 | var array1 = [ ];
13 |
14 |
15 | // 2.
16 | // Create an array with the following names in it in this order:
17 | // "Philip"
18 | // "Mary"
19 | // "Shafi"
20 | // "Marissa"
21 |
22 | var array2 = [ ];
23 |
24 |
25 | // 3.
26 | // Update the following array so that the third item has a value of 100
27 |
28 | var array3 = [1, 2, 3, 4, 5, 6, 7];
29 |
30 |
31 | // 4.
32 | // Create two dimenional array with three nested arrays each with three items
33 | // Fill the arrays with the numbers 1 through 9, so 3 numbers in each nested array
34 |
35 | var array4 = [ ];
36 |
37 |
38 | // 5.
39 | // Create an array with a single object in it. The object should represent a person
40 | // with a `name` property set to "Luke", an `age` property set to 56, and a `sex`
41 | // property set to 'M'
42 |
43 | var array5 = [ ];
44 |
45 |
46 | // 6.
47 | // Write a for loop that adds up all the values in the following array and
48 | // assigns the result to the `total` variable.
49 |
50 | var array6 = [1, 2, 3, 4, 5, 6, 7, 8, 9];
51 | var total = 0;
52 |
53 |
54 | // 7.
55 | // Turn the following `csv` string into an array, separating the text where commas occur.
56 | // Store the result in array7
57 |
58 | var csv = 'Philip,Dow,32,Male,Oklahoma City,OK,Developer'
59 | var array7 = [ ];
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 | // ==================================================
78 | // tests
79 |
80 | if ( array1[0] === 1 && array1[1] === 1 && array1[2] === 2 && array1[3] === 3 &&
81 | array1[4] === 5 && array1[5] === 8 && array1[6] === 13 && array1[7] === 21 ) {
82 | console.log("test 1 passed");
83 | } else {
84 | console.log("test 1 failed *");
85 | }
86 |
87 | if ( array2[0] === "Philip" && array2[1] === "Mary" && array2[2] === "Shafi" && array2[3] === "Marissa" ) {
88 | console.log("test 2 passed");
89 | } else {
90 | console.log("test 2 failed *");
91 | }
92 |
93 | if ( array3[2] === 100 ) {
94 | console.log("test 3 passed");
95 | } else {
96 | console.log("test 3 failed *");
97 | }
98 |
99 | if ( array4[0] && array4[0][0] === 1 && array4[0][1] === 2 && array4[0][2] === 3 &&
100 | array4[1] && array4[1][0] === 4 && array4[1][1] === 5 && array4[1][2] === 6 &&
101 | array4[2] && array4[2][0] === 7 && array4[2][1] === 8 && array4[2][2] === 9 ) {
102 | console.log("test 4 passed");
103 | } else {
104 | console.log("test 4 failed *");
105 | }
106 |
107 | if ( typeof array5[0] == 'object' && array5[0].name === 'Luke' && array5[0].age === 56 && array5[0].sex === 'M') {
108 | console.log("test 5 passed");
109 | } else {
110 | console.log("test 5 failed *");
111 | }
112 |
113 | if ( total === 45 ) {
114 | console.log("test 6 passed");
115 | } else {
116 | console.log("test 6 failed *");
117 | }
118 |
119 | if ( array7[0] === "Philip" && array7[1] === "Dow" && array7[2] === "32" && array7[3] === "Male" &&
120 | array7[4] === "Oklahoma City" && array7[5] === "OK" && array7[6] === "Developer" ) {
121 | console.log("test 7 passed");
122 | } else {
123 | console.log("test 7 failed *");
124 | }
--------------------------------------------------------------------------------
/15-mongoose/15-template/models/post.js:
--------------------------------------------------------------------------------
1 | var posts = [
2 | {
3 | id: 1,
4 | title: "The email line that's client repellent",
5 | body: "I’d gone through a few droughts as a freelancer, but this one was bad. Each day, the stress mounted. The magnitude of every new client meeting ballooned greater than ever before. Before each meeting, I went in knowing one thing; 'I need this job.' It’s the nature of being a freelancer. By definition, the work ends.",
6 | author: "http://letsworkshop.com/blog/the-email-line/"
7 | },
8 | {
9 | id: 2,
10 | title: "The Moderately Enthusiastic Programmer",
11 | body: "I feel like I’m practically the poster child for the “passionate programmer”. I code for fun, always have. I’m like the stereotype of the guy who’d be programming even if it didn’t pay. I play with new programming languages for the sheer hell of it. I write and speak about the joy of coding, and try my best to pass that joy along to others as best I can.",
12 | author: "http://devblog.avdi.org/2014/01/31/the-moderately-enthusiastic-programmer/"
13 | },
14 | {
15 | id: 3,
16 | title: "The Magic of Strace",
17 | body: "Early in my career, a co-worker and I were flown from Memphis to Orlando to try to help end a multi-day outage of our company’s corporate Lotus Domino server. The team in Orlando had been fire-fighting for days and had gotten nowhere. I’m not sure why they thought my co-worker and I could help. We didn’t know anything at all about Lotus Domino. But it ran on UNIX and we were pretty good with UNIX. I guess they were desperate.",
18 | author: "http://chadfowler.com/blog/2014/01/26/the-magic-of-strace/"
19 | },
20 | {
21 | id: 4,
22 | title: "http://nightwatchjs.org/",
23 | body: "Simple but powerful syntax which enables you to write tests very quickly, using only Javascript and CSS selectors. No need to initialize other objects and classes, you only need to write the test specs. Built-in command-line test runner which enables you to run the tests either altogether, by group or single.",
24 | author: "http://nightwatchjs.org/"
25 | },
26 | {
27 | id: 5,
28 | title: "The upside to being let go by Nokia",
29 | body: "During the years of Nokia's decline, culminating in the sale of its mobile phone division to Microsoft in September, thousands of workers were made redundant. But the ex-Nokians have now created hundreds of new companies - thanks partly to a very Finnish level of support from the employer to its departing staff.",
30 | author: "http://www.bbc.co.uk/news/magazine-25965140"
31 | },
32 | {
33 | id: 6,
34 | title: "PayPal Mafia",
35 | body: "PayPal Mafia is a term used to indicate a group of former PayPal employees and founders who have since founded and developed additional technology companies such as Tesla Motors, LinkedIn, Palantir Technologies, SpaceX, YouTube, Yelp Inc., and Yammer.",
36 | author: "http://en.wikipedia.org/wiki/PayPal_Mafia"
37 | },
38 | {
39 | id: 7,
40 | title: "You might not need jQuery",
41 | body: "jQuery and its cousins are great, and by all means use them if it makes it easier to develop your application. If you're developing a library on the other hand, please take a moment to consider if you actually need jQuery as a dependency. Maybe you can include a few lines of utility code, and forgo the requirement. If you're only targeting more modern browsers, you might not need anything more than what the browser ships with.",
42 | author: "http://youmightnotneedjquery.com/?hn"
43 | }
44 | ];
45 |
46 | // You can implement your module.exports here
47 |
48 | module.exports = {
49 | all: function() {
50 | return posts;
51 | },
52 | find: function(id) {
53 | return posts[id - 1];
54 | }
55 | };
--------------------------------------------------------------------------------
/12-rendering-html/12-exercises/posts.js:
--------------------------------------------------------------------------------
1 |
2 | // Sample data
3 | // Source: https://news.ycombinator.com
4 |
5 | var posts = [
6 | {
7 | id: 1,
8 | title: "The email line that's client repellent",
9 | body: "I’d gone through a few droughts as a freelancer, but this one was bad. Each day, the stress mounted. The magnitude of every new client meeting ballooned greater than ever before. Before each meeting, I went in knowing one thing; 'I need this job.' It’s the nature of being a freelancer. By definition, the work ends.",
10 | author: "http://letsworkshop.com/blog/the-email-line/"
11 | },
12 | {
13 | id: 2,
14 | title: "The Moderately Enthusiastic Programmer",
15 | body: "I feel like I’m practically the poster child for the “passionate programmer”. I code for fun, always have. I’m like the stereotype of the guy who’d be programming even if it didn’t pay. I play with new programming languages for the sheer hell of it. I write and speak about the joy of coding, and try my best to pass that joy along to others as best I can.",
16 | author: "http://devblog.avdi.org/2014/01/31/the-moderately-enthusiastic-programmer/"
17 | },
18 | {
19 | id: 3,
20 | title: "The Magic of Strace",
21 | body: "Early in my career, a co-worker and I were flown from Memphis to Orlando to try to help end a multi-day outage of our company’s corporate Lotus Domino server. The team in Orlando had been fire-fighting for days and had gotten nowhere. I’m not sure why they thought my co-worker and I could help. We didn’t know anything at all about Lotus Domino. But it ran on UNIX and we were pretty good with UNIX. I guess they were desperate.",
22 | author: "http://chadfowler.com/blog/2014/01/26/the-magic-of-strace/"
23 | },
24 | {
25 | id: 4,
26 | title: "http://nightwatchjs.org/",
27 | body: "Simple but powerful syntax which enables you to write tests very quickly, using only Javascript and CSS selectors. No need to initialize other objects and classes, you only need to write the test specs. Built-in command-line test runner which enables you to run the tests either altogether, by group or single.",
28 | author: "http://nightwatchjs.org/"
29 | },
30 | {
31 | id: 5,
32 | title: "The upside to being let go by Nokia",
33 | body: "During the years of Nokia's decline, culminating in the sale of its mobile phone division to Microsoft in September, thousands of workers were made redundant. But the ex-Nokians have now created hundreds of new companies - thanks partly to a very Finnish level of support from the employer to its departing staff.",
34 | author: "http://www.bbc.co.uk/news/magazine-25965140"
35 | },
36 | {
37 | id: 6,
38 | title: "PayPal Mafia",
39 | body: "PayPal Mafia is a term used to indicate a group of former PayPal employees and founders who have since founded and developed additional technology companies such as Tesla Motors, LinkedIn, Palantir Technologies, SpaceX, YouTube, Yelp Inc., and Yammer.",
40 | author: "http://en.wikipedia.org/wiki/PayPal_Mafia"
41 | },
42 | {
43 | id: 7,
44 | title: "You might not need jQuery",
45 | body: "jQuery and its cousins are great, and by all means use them if it makes it easier to develop your application. If you're developing a library on the other hand, please take a moment to consider if you actually need jQuery as a dependency. Maybe you can include a few lines of utility code, and forgo the requirement. If you're only targeting more modern browsers, you might not need anything more than what the browser ships with.",
46 | author: "http://youmightnotneedjquery.com/?hn"
47 | }
48 | ];
49 |
50 | // You can implement your module.exports here
51 |
52 | module.exports = {
53 | all: function() {
54 | return posts;
55 | },
56 | find: function(id) {
57 | return posts[id - 1];
58 | }
59 | };
--------------------------------------------------------------------------------
/00-preparation/00-02-mac-setup.md:
--------------------------------------------------------------------------------
1 | Macintosh Instructions
2 | ====
3 |
4 | You must be running Mac OS 10.8 Mountain Lion or Mac OS 10.9 Mavericks. Check what version of the Mac OS you have installed by clicking on the Apple menu item at the top left of your screen and selecting *About this Mac*.
5 |
6 | If you must upgrade your computer, follow the instructions at [apple.com/osx/how-to-upgrade](http://www.apple.com/osx/how-to-upgrade/).
7 |
8 | Also ensure that you have installed the latest updates. Again click on the *Apple* menu item at select *Software Update*.
9 |
10 | ## Install Software
11 |
12 | Install the following software by downloading it at these urls:
13 |
14 | [Sublime Text](http://www.sublimetext.com/)
15 |
16 | This is the free text editor we will be using in class.
17 |
18 | [Google Chrome](https://www.google.com/intl/en-US/chrome/browser/)
19 |
20 | We will be doing all web development in Google Chrome because of its excellent developer tools.
21 |
22 | [iTerm2](http://www.iterm2.com/)
23 |
24 | An enhanced Terminal we'll learn to use.
25 |
26 | ## Install the Command Line Utilities
27 |
28 | The Macintosh comes with a built-in command line interface called the *Terminal*. Launch it from your */Applications/Utilities* folder.
29 |
30 | Install Apple's Command Line Tools: Instructions vary depending on which version of the Mac OS you are using. First try typing `gcc` at the command line. If a dialog box appears for installing the command line tools, *Install* them. You do not need to Install Xcode.
31 |
32 | If the dialog box does not appear or you get an '*command not found*' error, download one of the following installers depending on your version of Mac OS. Double-click the completed download to install the files:
33 |
34 | - Mac OS 10.9: [Command Line Utilities for Mac OS 10.9 Mavericks](https://s3.amazonaws.com/okcoders/command_line_tools_for_osx_mavericks_april_2014.dmg)
35 | - Mac OS 10.8: [Command Line Utilities for Mac OS 10.8 Mountain Lion](https://s3.amazonaws.com/okcoders/command_line_tools_for_osx_mountain_lion_april_2014.dmg)
36 |
37 | ## Configure Git
38 |
39 | Set your global git username and password. At the terminal, type the following two commands. Press enter after each one:
40 |
41 | git config --global user.name "Your Name"
42 | git config --global user.email your@email.address
43 |
44 | ## Install Homebrew
45 |
46 | Install Homebrew: Follow the instructions at [http://brew.sh/](http://brew.sh/). Scroll to the bottom of the page and paste the text that appears in your Terminal. Press return to execute the command. Text activity should indicate that Homebrew is being downloaded and installed. Follow any instructions that appear.
47 |
48 | Update Hombrew: At the terminal, type the following command and press return:
49 |
50 | brew update
51 |
52 | ## Install Node and Friends
53 |
54 | Install Node.js: At the Terminal, type the following command and press return:
55 |
56 | brew install node
57 |
58 | Install Express: At the Terminal, type the following two commands and press return after each one:
59 |
60 | npm install -g express-generator
61 |
62 | ## Set Up Heroku
63 |
64 | Sign up for a free account at Heroku: [https://www.heroku.com/](https://www.heroku.com/)
65 |
66 | Install the Heroku Command Line Interface: Follow the instructions at [https://devcenter.heroku.com/articles/heroku-command](https://devcenter.heroku.com/articles/heroku-command). Note you will need to install the Heroku Toolbelt.
67 |
68 | ## Set up your SSH keys
69 |
70 | SSH Keys are used to establish a secure connection to GitHub and Heroku.
71 |
72 | Follow the instructions at GitHub to create and register new SSH keys: [Generating SSH Keys for GitHub](https://help.github.com/articles/generating-ssh-keys).
73 |
74 | Follow the instructions at Heroku to register your SSH keys. **You do not need to create a new public/private keypair.** [Register SSH Keys with Heroku](https://devcenter.heroku.com/articles/keys)
75 |
76 | Nice work! You just set up your development environment and are already using the command line! This is serious stuff!
--------------------------------------------------------------------------------
/02-html/02-exercises/public/people.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
21 |
22 |
23 |
24 | People
25 |
26 |
27 |
28 | Image: http://31.media.tumblr.com/tumblr_m7vknnrE181rn3fpto1_500.jpg
29 | Name: Tim Berners-Lee
30 |
31 | Bio: A graduate of Oxford University, Tim Berners-Lee invented the World Wide Web, an internet-based hypermedia initiative for global information sharing while at CERN, the European Particle Physics Laboratory, in 1989. He wrote the first web client and server in 1990. His specifications of URIs, HTTP and HTML were refined as Web technology spread.
32 |
33 | Link: http://en.wikipedia.org/wiki/Tim_Berners-Lee
34 |
35 |
36 | Image: http://portal.educ.ar/debates/sociedad/img/stallman.jpg
37 | Name: Richard Stallman
38 |
39 | Bio: Richard Matthew Stallman (born March 16, 1953), often known by his initials, RMS, is an American software freedom activist and computer programmer. He campaigns for the freedom to use, study, distribute and modify software; software that ensures these freedoms is termed free software. He is best known for launching the GNU Project, founding the Free Software Foundation, developing the GNU Compiler Collection and GNU Emacs, and writing the GNU General Public License.
40 |
41 | Link: http://en.wikipedia.org/wiki/Richard_Stallman
42 |
43 |
44 | Image: http://www.pophistorydig.com/wp-content/uploads/2010/05/woz-w-computer-1-320.jpg
45 | Name: Steve Wozniak
46 |
47 | Bio: Stephen Gary "Steve" Wozniak (born August 11, 1950), known as "Woz", is an American inventor, computer engineer and programmer who co-founded Apple Computer (now Apple Inc.) with Steve Jobs and Ronald Wayne. Wozniak single-handedly invented both the Apple I and Apple II computers in the 1970s. These computers contributed significantly to the microcomputer revolution.
48 |
49 | Link: http://en.wikipedia.org/wiki/Steve_Wozniak
50 |
51 |
52 | Image: http://phandroid.s3.amazonaws.com/wp-content/uploads/2011/01/larry_page.jpg
53 | Name: Larry Page
54 |
55 | Bio: Lawrence "Larry" Page (born March 26, 1973) is an American computer scientist and Internet entrepreneur who is the co-founder of Google, alongside Sergey Brin. On April 4, 2011, Page became the chief executive officer of Google and Eric Schmidt is his predecessor. As of 2013, Page's personal wealth is estimated to be US$23 billion, ranking him #20 on the Forbes 400 list of the 400 richest Americans. Page is the inventor of PageRank, the foundation of Google's search ranking algorithm, and he and Brin own approximately 16 percent of Google's stock.
56 |
57 | Link: http://en.wikipedia.org/wiki/Larry_Page
58 |
59 |
60 | Image: https://www.student.cs.uwaterloo.ca/~cs462/Hall/knuth.gif
61 | Name: Donald Knuth
62 |
63 | Bio: Donald Knuth is the author of the seminal multi-volume work The Art of Computer Programming. Knuth has been called the "father" of the analysis of algorithms. He contributed to the development of the rigorous analysis of the computational complexity of algorithms and systematized formal mathematical techniques for it. In the process he also popularized the asymptotic notation.
64 |
65 | Link: http://en.wikipedia.org/wiki/Donald_Knuth
66 |
67 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/09-javascript-oop/09-exercises/javascript/higher-order-functions.js:
--------------------------------------------------------------------------------
1 |
2 | // Instructions
3 | // cd into the correct directory and run this file with `node higher-order.js`
4 | // You will see a number of failing tests.
5 | // Complete each of the problems by filling in the provided variables and functions
6 | // with the correct values to get the tests to pass.
7 |
8 |
9 |
10 | // 1.
11 | // Create a select function that works as a higher order function.
12 | // It takes two parameters: a data parameter that is an array, and
13 | // a callback parameter that is a function.
14 | //
15 | // Select loops through the items in the data parameter, calling the
16 | // callback for each one. In this respects it is like the map function
17 | //
18 | // The callback function takes a single paramter, the item currently being
19 | // looped through, and it returns either true or false. If the callback
20 | // returns true, then select adds the current item to a local array. If it
21 | // returns false, it does not.
22 |
23 | // When select is finished looping through each item in data, it returns
24 | // the local array, which now contains some of the items from data, namely,
25 | // those for which the callback function returns true.
26 |
27 | // 1, 1, 2, 3, 5, 8, 13, 21
28 |
29 | function select() {
30 |
31 | }
32 |
33 | // Example usage
34 | // young ends up as an array which contains two items: [16, 21]
35 |
36 | var ages = [16,21,30,45,60,75];
37 | var young = select(ages, function(item) {
38 | return (item <= 25);
39 | });
40 |
41 |
42 | // 2.
43 | // Create a reject function that works as a higher order function.
44 | // It is the opposite of select. Like select it takes data and callback
45 | // arguments, but now only return those items that the callback function
46 | // returns false for.
47 |
48 | function reject() {
49 |
50 | }
51 |
52 | // Example usage
53 | // old ends up as an array which contains four items: [30, 45, 60, 75]
54 |
55 | var ages = [16,21,30,45,60,75];
56 | var old = reject(ages, function(item) {
57 | return (item <= 25);
58 | });
59 |
60 |
61 | // 3.
62 | // Create a find function that works as a higher order function.
63 | // Find takes two parameters: a data parameter that is an array,
64 | // and a callback parameter that is a function.
65 | //
66 | // Find should return the first item it encouters for which calling
67 | // the callback with it returns true.
68 | //
69 | // If the callback never returns true for any of the items in the data
70 | // array, it should return undefined.
71 |
72 | function find() {
73 |
74 | }
75 |
76 | // Example usage
77 | // firstEven ends up as the first even number in the array: 26
78 | // the % operator (or 'mod operator') returns the remainder after
79 | // dividing the left hand side by the right hand
80 |
81 | var nums = [1,89,45,26,57,34];
82 | var firstEven = find(nums, function(item) {
83 | return (item % 2 == 0);
84 | });
85 |
86 |
87 |
88 |
89 |
90 |
91 | // ==================================================
92 | // TESTS
93 |
94 | var tofilter = [0,1,2,3,4,5,6,7,8,9,10];
95 | var filtered = select(tofilter, function(item) {
96 | return (item % 2 == 0);
97 | });
98 |
99 | if (typeof filtered == 'object' && filtered[0] == 0 && filtered[1] == 2 && filtered[2] == 4 &&
100 | filtered[3] == 6 && filtered[4] == 8 && filtered[5] == 10) {
101 | console.log("test 1 passed");
102 | } else {
103 | console.log("test 1 failed *");
104 | }
105 |
106 |
107 | var toreject = [0,1,2,3,4,5,6,7,8,9,10];
108 | var rejected = reject(toreject, function(item) {
109 | return (item % 2 == 0);
110 | });
111 |
112 | if (typeof rejected == 'object' && rejected[0] == 1 && rejected[1] == 3 && rejected[2] == 5 &&
113 | rejected[3] == 7 && rejected[4] == 9) {
114 | console.log("test 2 passed");
115 | } else {
116 | console.log("test 2 failed *");
117 | }
118 |
119 |
120 | var testnums = [6,34,56,77,68,91,23];
121 | var firstOdd = find(testnums, function(item) {
122 | return (item % 2 == 1);
123 | });
124 |
125 | if (firstOdd == 77) {
126 | console.log("test 3 passed");
127 | } else {
128 | console.log("test 3 failed *");
129 | }
130 |
131 |
--------------------------------------------------------------------------------
/03-css/03-exercises/public/navbar.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Navigation Bar
6 |
7 |
8 |
9 |
62 |
63 |
64 |
65 |
66 |
67 |
81 |
82 |
91 |
92 |
93 |
94 |
Lorem Ipsum
95 |
96 |
97 | "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
98 |
99 |
100 | "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"
101 |
108 |
109 |
110 |
--------------------------------------------------------------------------------
/04-twitter-bootstrap/04-exercises/04-exercises.md:
--------------------------------------------------------------------------------
1 | OK Coders: Lesson 4 Exercises
2 | ====
3 |
4 | Complete all homework assignments before coming to the next class or as otherwise instructed.
5 |
6 | ## Create an express app for bootstrap practice
7 |
8 | **Create a new express app**
9 |
10 | Similar to the previous homework assignment, create a new Express web application. Do not reuse previous express applications. The intent is to practice using the command line and creating applications from scratch quickly.
11 |
12 | **Grab the html from this repository**
13 |
14 | Copy all the html files from the public directory in this repository into the public directory of your express application. Actually, for this lesson you could create the html files from scratch, because the html files in this repository are empty placeholders.
15 |
16 | **Install bootstrap**
17 |
18 | Download the bootstrap files and place them into the correct directories. Remember to use the *javascripts* instead of *js* and *stylesheets* instead of *css* directories in your express application.
19 |
20 | **Create a web site**
21 |
22 | For this assignment you will create the files from scratch. I've added an empty file for each page. You will generate all the html. Base your html on the Bootstrap Basic Template we used in class, but don't forget to correct the `link` and `script` tags.
23 |
24 | The site should have the following characteristics:
25 |
26 | **Navigation and container**
27 |
28 | Each page should have a working bootstrap-based *navigation bar* with links to all the other pages that also indicates the current page. Each page should also have a *container* div that contains the rest of the page.
29 |
30 | **Index.html**
31 |
32 | The index is the front landing page for the site. Use the *jumbotron* component and *panels* to highlight features of the site. Make up marketing copy (text) for a data analysis firm and add images.
33 |
34 | **About.html**
35 |
36 | Create an about page that describes the business and the team. Add images for team members. The images should be circles, but don't edit square images. Use bootstrap's support for making a rectangular image appear circular. Again, make up the copy (text contents).
37 |
38 | **Signup.html**
39 |
40 | Create a sign up page for the firm's product. Create a form using bootstrap's form classes. Your sign up form should require an email address and password. No username and no password confirmation field. Include a signup button. Center the form on the page so that it doesn't take up the entire width.
41 |
42 | **Reports.html**
43 |
44 | The reports page uses bootstrap's *grid system* for layout. This is where your customers go to view the data reports available to them. Use bootstrap's grid system to create a two column layout. The left column is the sidebar (width:4) that contains a *list group* component. The right column is the main content area (width:8) and should include a sample report or chart. If you're feeling brave, try incorporating one of the examples from [D3.js](http://d3js.org/), even if you don't understand javascript yet.
45 |
46 | ## Review css selectors and properties
47 |
48 | Mozilla has excellent css documention. Review the properties list and make sure you understand selectors. We'll be using them with JavaScript as well.
49 |
50 | [Mozilla's CSS Documentation](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference): The goto reference for css questions.
51 |
52 | [Code Academy CSS Practice](http://www.codecademy.com/tracks/web): Practice html and css at Code Academy.
53 |
54 | ## Review the command line and git
55 |
56 | Two free books on the command line and on git were mentioned in class. Consider these books textbooks and study them.
57 |
58 | [The Linux Command Line, by William Shots](http://linuxcommand.org/tlcl.php) : Read past the first four chapters. Start to get into the advanced material likes pipes and redirection.
59 |
60 | [Pro Git](http://git-scm.com/book) : Make sure you have read the first two chapters, Getting Started and Git Basics, and begin working on branching in chapter three.
61 |
62 | ## Keep learning JavaScript
63 |
64 | We start JavaScript programming next week! Make sure you come to class prepared. We will use the excellent and free [Eloquent JavaScript](http://eloquentjavascript.net/) for this class.
65 |
66 | Read and practice with the first four chapters by the beginning of next week. Don't put this off!
67 |
68 | If you would like additional JavaScript practice, sign up for a free account at [Code Academy](http://www.codecademy.com/) and begin working through their JavaScript lessons.
--------------------------------------------------------------------------------
/11-express/11-01-npm.md:
--------------------------------------------------------------------------------
1 | NPM: Node Package Manager
2 | ====================================
3 |
4 | As soon as we start building more complex applications that involve more than one javascript file and may rely on 3rd party modules, we should order our application as a *package*.
5 |
6 | For node, a package is a self-contained collection of javascript files and other resources with accompanying metadata that describes what it does and what other code it depends on. Node includes a special utility, *npm* or the *node package manager* that makes it easy to mangage packages.
7 |
8 | Node treats packages like modules. Although a package may contain may files, it also indicates a *main* file or public facing file that represents the package to its consumers as a module.
9 |
10 | ## Resources
11 |
12 | [Node Modules](http://nodejs.org/api/modules.html)
13 |
14 | Modules reference documentation. Packages are modules.
15 |
16 | [NPM](https://www.npmjs.org/)
17 |
18 | The Node Package Manager homepage.
19 |
20 | [NPM API Docs](https://www.npmjs.org/doc/)
21 |
22 | Everything you can do with the `npm` command in the terminal. It's a lot.
23 |
24 | ## Creating a package
25 |
26 | Creating a new package is straightforward. Use the `npm` command line utility and give it a subcommand, such as `init` to create a new package.
27 |
28 | So to create a new package, make a new directory and `cd` into it, then initialize the new package in that directory with:
29 |
30 | $ npm init
31 |
32 | Npm will ask you for some information about your project. All this command does is create a *package.json* file in the current working directory that contains the information you provided.
33 |
34 | We've already seen the *package.json* file when we used `express` to generate our application. Examine it and you'll see information about the application. Examine one generated by the express template and you'll see more information like required dependencies.
35 |
36 | Notice our package says there should be an "index.js" file. Go ahead and create it:
37 |
38 | $ touch index.js
39 |
40 | ## Managing dependencies
41 |
42 | The node package manager also handles application dependencies for us. Depdencies are the 3rd party code our application relies on. They often come in the form of *libraries* and *frameworks*, which are collections of re-usable code that other people have written and which we can take advantage of in our projects.
43 |
44 | **Installing a new dependency**
45 |
46 | Installing dependencies is simple. You just need its name. Install a new package and mark it as a dependency in the package.json file with the following format:
47 |
48 | npm install package-name --save
49 |
50 | So for example to install the `underscore` package, type at the console:
51 |
52 | $ npm install underscore --save
53 |
54 | NPM adds the package to the `node_modules` folder in the current directory, creating it if necessary, and with the `--save` argument modifies the package.json file to list underscore as a dependency:
55 |
56 | $ ls
57 | node_modules package.json index.js
58 | $ ls node_modules
59 | underscore
60 | $ cat package.json
61 | {
62 | "name": "npm-test",
63 | ...
64 | "dependencies": {
65 | "underscore": "^1.6.0"
66 | }
67 | }
68 |
69 | We could then use the `underscore` package from our "index.js" file by requiring it, as we've already seen with modules:
70 |
71 | var _ = require('underscore');
72 |
73 | All packages behave like modules in node.
74 |
75 | And yes, we're actually assigning the result of `require` to an underscore `_` which is a legal variable name in javascript.
76 |
77 | **Installing the listed dependencies**
78 |
79 | Saving the dependencies in the package.json file makes it easy to move the our package around later. We don't need to move the dependencies with it, just this *manifest* file which tells npm what dependencies are required. Then we can run `npm install` by itself and it will automatically download and install all the dependencies listed there:
80 |
81 | $ npm install
82 |
83 | This is exactly what we do after templating a new application with `express`. The `express` command generates an application template that includes a package.json file. The package.json file lists all the application dependencies:
84 |
85 | "dependencies": {
86 | "express": "~4.2.0",
87 | "static-favicon": "~1.0.0",
88 | "morgan": "~1.0.0",
89 | "cookie-parser": "~1.0.1",
90 | "body-parser": "~1.0.0",
91 | "debug": "~0.7.4",
92 | "jade": "~1.3.0"
93 | }
94 |
95 | The dependencies include express itself! Express is not just a command line utility we use to template our applications, it is also a node library that an express application needs in order to work.
96 |
97 | But the `express` *command* doesn't install the *library*, it just lists it as a dependency. Consequently we run `npm install` to have npm download and install all the required depdencies.
--------------------------------------------------------------------------------
/A-exercise-solutions/04-bootstrap-class-example/public/grid.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Bootstrap 101 Template
8 |
9 |
10 |
11 |
12 |
13 |
14 |
18 |
19 |
20 |
21 |
56 | Panel content
57 |
58 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
59 | tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
60 | quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
61 | consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
62 | cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
63 | proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
64 |
65 |
66 |
67 |
68 |
69 |
Panel title
70 |
71 |
72 | Panel content
73 |
74 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
75 | tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
76 | quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
77 | consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
78 | cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
79 | proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
Right Sidebar
88 |
89 |
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
90 | tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
91 | quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
92 | consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
93 | cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
94 | proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
--------------------------------------------------------------------------------
/12-rendering-html/12-exercises/12-exercises.md:
--------------------------------------------------------------------------------
1 | OK Coders: Lesson 13 Exercises
2 | ===================================
3 |
4 | For this assignment you will extend the blog application you began building in [lesson 11's assignment](https://github.com/okcoders/intro-express-homework) by adding view's for the various routes.
5 |
6 | You may either start from scratch and copy in the routing code from the previous assignment, or you make work from the existing assignment.
7 |
8 | **From Scratch**
9 |
10 | If you start a new application from scratch, be sure to initialize the express application with the `--ejs` argument to use the ejs templating system:
11 |
12 | $ mkdir express-app && cd express-app
13 | $ express --ejs
14 |
15 | **Upgrade Existing**
16 |
17 | If you are extending an existing homework assignment you will need to switch from the jade templating system which is used by default to the ejs templating system:
18 |
19 | First, `cd` into your project directory in the terminal and install ejs:
20 |
21 | $ npm install ejs --save
22 |
23 | That will install ejs and also modify the *package.json* file to mark it as a dependency.
24 |
25 | Second, modify the *app.js* file so that ejs is used as the templating engine instead of jade. Replace the folowing line:
26 |
27 | ```js
28 | app.set('view engine', 'jade');
29 | ```
30 |
31 | with:
32 |
33 | ```js
34 | app.set('view engine', 'ejs');
35 | ```
36 |
37 | Third, remove the three *.jade* files in the *views* directory: *error.jade*, *index.jade* and *layout.jade*. You will need to build your own *.ejs* files in this folder to replace them.
38 |
39 | ## Render ejs templates for the posts resource
40 |
41 | The bulk of the assignment consists of creating template files or the posts resource whose routes you set up in the previous assignment. In that assignment you simply called `res.send()` with placeholder content to confirm the routes were working. Here you'll call `res.render()` to actually render views.
42 |
43 | You should create views and render them with data for the four `GET` requests handled by your routes. `GET` requests are the only ones which will generate html, so this makes sense:
44 |
45 |
46 |
47 |
48 |
HTTP Verb
49 |
Path
50 |
Used for
51 |
View file
52 |
53 |
54 |
55 |
56 |
GET
57 |
/posts
58 |
display a list of all posts
59 |
posts/index.ejs
60 |
61 |
62 |
GET
63 |
/posts/new
64 |
return an HTML form for creating a new post
65 |
posts/new.ejs
66 |
67 |
68 |
GET
69 |
/posts/:id
70 |
display a specific post
71 |
posts/show.ejs
72 |
73 |
74 |
GET
75 |
/posts/:id/edit
76 |
return an HTML form for editing a post
77 |
posts/edit.ejs
78 |
79 |
80 |
81 |
82 | Your views should do exactly what is described in the **Used for** column. In some cases you'll display a list of posts, which means you'll have to loop over an array in your view. In other cases you'll generate a form, and so on. Interpret the stylistic aspects as you see fit, but use twitter bootstrap templating in each case and wrap your content in a container:
83 |
84 | ```html
85 |
86 | ...
87 |
88 | ```
89 |
90 | If you're feeling intrepid, create links from the posts/index page to each respective post/:id page.
91 |
92 | Organize your view files according to the **View file** column. Create a *posts* directory in the *views* directory and create four templates there: *index.ejs*, *new.ejs*, *show.ejs* and *edit.ejs*. Render each template according to the route being handled.
93 |
94 | If you need help with twitter bootstrap, refer to: [Bootstrap Class](https://github.com/okcoders/bootstrap-class) and [Bootstrap Example](https://github.com/okcoders/bootstrap-example)
95 |
96 | **The Data**
97 |
98 | But you'll need some data to inject into your views! Use the included *post.js* file. Create a *models* folder in your project's root directory and place *post.js* there. From inside your *routes/posts.js* file, require it and access posts as such:
99 |
100 | ```js
101 | var Post = require('./../models/post');
102 |
103 | // acquire an array of all posts
104 | var posts = Post.all();
105 |
106 | // acquire a single post, perhaps by a post id as a url param
107 | var id = ...
108 | var post = Post.find(id);
109 | ```
110 |
111 | ## Upload your changes to heroku
112 |
113 | Save your changes using git and upload them to a heroku. If you're upgrading existing code you can just `git add` and `git commit` the changes the push to heroku. If you've started from scratch you'll need to create a new heroku application.
114 |
115 | For more info, see: [Bash Heroku Git Class](https://github.com/okcoders/bash-heroku-class)
--------------------------------------------------------------------------------
/A-exercise-solutions/08-javascript-oop/higher-order-functions.js:
--------------------------------------------------------------------------------
1 |
2 | // Instructions
3 | // cd into the correct directory and run this file with `node higher-order.js`
4 | // You will see a number of failing tests.
5 | // Complete each of the problems by filling in the provided variables and functions
6 | // with the correct values to get the tests to pass.
7 |
8 |
9 |
10 | // 1.
11 | // Create a select function that works as a higher order function.
12 | // It takes two parameters: a data parameter that is an array, and
13 | // a callback parameter that is a function.
14 | //
15 | // Select loops through the items in the data parameter, calling the
16 | // callback for each one. In this respects it is like the map function
17 | //
18 | // The callback function takes a single parameter, the item currently being
19 | // looped through, and it returns either true or false. If the callback
20 | // returns true, then select adds the current item to a local array. If it
21 | // returns false, it does not.
22 |
23 | // When select is finished looping through each item in data, it returns
24 | // the local array, which now contains some of the items from data, namely,
25 | // those for which the callback function returns true.
26 |
27 | // 1, 1, 2, 3, 5, 8, 13, 21
28 |
29 | function select(data, callback) {
30 | var newarray = [];
31 |
32 | for (var i = 0; i < data.length; i++) {
33 | var item = data[i];
34 | var result = callback(item);
35 |
36 | if (result) {
37 | newarray.push(item);
38 | } else {
39 |
40 | }
41 | }
42 | return newarray;
43 | }
44 |
45 | // Example usage
46 | // young ends up as an array which contains two items: [16, 21]
47 |
48 | var ages = [16,21,30,45,60,75];
49 |
50 | var young = select(ages, function(item) {
51 | return (item <= 25);
52 | });
53 |
54 |
55 | // 2.
56 | // Create a reject function that works as a higher order function.
57 | // It is the opposite of select. Like select it takes data and callback
58 | // arguments, but now only return those items that the callback function
59 | // returns false for.
60 |
61 | function reject(data, callback) {
62 | var newarray = [];
63 |
64 | for (var i = 0; i < data.length; i++) {
65 | var item = data[i];
66 | var result = callback(item);
67 |
68 | if (!result) {
69 | newarray.push(item);
70 | } else {
71 |
72 | }
73 | }
74 | return newarray;
75 | }
76 |
77 | // Example usage
78 | // old ends up as an array which contains four items: [30, 45, 60, 75]
79 |
80 | var ages = [16,21,30,45,60,75];
81 | var old = reject(ages, function(item) {
82 | return (item <= 25);
83 | });
84 |
85 |
86 | // 3.
87 | // Create a find function that works as a higher order function.
88 | // Find takes two parameters: a data parameter that is an array,
89 | // and a callback parameter that is a function.
90 | //
91 | // Find should return the first item it encouters for which calling
92 | // the callback returns true.
93 | //
94 | // If the callback never returns true for any of the items in the data
95 | // array, it should return undefined.
96 |
97 | function find(data, callback) {
98 | for (var i = 0; i < data.length; i++) {
99 | var item = data[i];
100 | var result = callback(item);
101 |
102 | if (result) {
103 | return item;
104 | }
105 | }
106 | return null;
107 | }
108 |
109 | // Example usage
110 | // firstEven ends up as the first even number in the array: 26
111 | // the % operator (or 'mod operator') returns the remainder after
112 | // dividing the left hand side by the right hand
113 |
114 | var nums = [1,89,45,26,57,34];
115 | var firstEven = find(nums, function(item) {
116 | return (item % 2 == 0);
117 | });
118 |
119 |
120 |
121 |
122 |
123 |
124 | // ==================================================
125 | // TESTS
126 |
127 | var tofilter = [0,1,2,3,4,5,6,7,8,9,10];
128 | var filtered = select(tofilter, function(item) {
129 | return (item % 2 == 0);
130 | });
131 |
132 | if (typeof filtered == 'object' && filtered[0] == 0 && filtered[1] == 2 && filtered[2] == 4 &&
133 | filtered[3] == 6 && filtered[4] == 8 && filtered[5] == 10) {
134 | console.log("test 1 passed");
135 | } else {
136 | console.log("test 1 failed *");
137 | }
138 |
139 |
140 | var toreject = [0,1,2,3,4,5,6,7,8,9,10];
141 | var rejected = reject(toreject, function(item) {
142 | return (item % 2 == 0);
143 | });
144 |
145 | if (typeof rejected == 'object' && rejected[0] == 1 && rejected[1] == 3 && rejected[2] == 5 &&
146 | rejected[3] == 7 && rejected[4] == 9) {
147 | console.log("test 2 passed");
148 | } else {
149 | console.log("test 2 failed *");
150 | }
151 |
152 |
153 | var testnums = [6,34,56,77,68,91,23];
154 | var firstOdd = find(testnums, function(item) {
155 | return (item % 2 == 1);
156 | });
157 |
158 | if (firstOdd == 77) {
159 | console.log("test 3 passed");
160 | } else {
161 | console.log("test 3 failed *");
162 | }
163 |
164 |
--------------------------------------------------------------------------------
/07-javascript-data-structures/07-exercises/javascript/objects.js:
--------------------------------------------------------------------------------
1 |
2 | // Instructions
3 | // cd into the correct directory and run the file with `node objects.js`
4 | // You will see a number of failing tests.
5 | // Complete each of the 9 problem by filling in the provided variables
6 | // with the correct values to get the tests to pass.
7 |
8 |
9 | // 1.
10 | // Create an object with a `name` property whose value is 'Michael'
11 |
12 | var obj1 = { };
13 |
14 |
15 | // 2.
16 | // Create an object with a `name` property whose value is 'James'
17 | // and and `age` property with the value 48
18 |
19 | var obj2 = { };
20 |
21 |
22 | // 3.
23 | // Create an object with a `happy-days` property whose value is true
24 | // Be sure to include the dash (-) in the property name. You'll need
25 | // to define the object slightly differently.
26 | // See lecture notes for help
27 |
28 | var obj3 = { };
29 |
30 |
31 | // 4.
32 | // Modify the object so that its `music` property is updated to 'Techno'
33 |
34 | var obj4 = {
35 | name: 'Carissa',
36 | age: 23,
37 | music: 'Country'
38 | };
39 |
40 |
41 | // 5.
42 | // Create an object with a `name` property that is itself an object.
43 | // The name object should have `first` and `last` properties whose
44 | // values are 'Ada' and 'Lovelace' respectively.
45 |
46 | var obj5 = { };
47 |
48 |
49 | // 6.
50 | // Create an object with a `name` property that is itself an object.
51 | // The name object should have `first` and `last` properties whose
52 | // values are 'Susan' and 'Kare' respectively.
53 | // The object should also have a `job` property that is an object.
54 | // The job object should `title` and `company` propeties whose
55 | // values are 'Creative Director' and 'NeXT' respectively.
56 | // Watch the capitalization and syntax!
57 |
58 | var obj6 = { };
59 |
60 |
61 | // 7.
62 | // Create an object with a single function named `meaningOfLife` which
63 | // returns the number 42.
64 |
65 | // Remember that you can declare a function and assign it to a variable like:
66 |
67 | var func = function() {
68 | // do something
69 | };
70 |
71 | var obj7 = { };
72 |
73 |
74 | // 8.
75 | // Create an object with two functions named `completed` and `failed`.
76 | // The completed function should update the variable `successMsg` below to 'Completed',
77 | // and the failed function should update `failureMsg` to 'Failed'.
78 | // e.g. successMsg = 'Completed' or failureMsg = 'Incomplete'
79 | // Don't redeclare the variables!
80 |
81 | var obj8 = { };
82 |
83 | // do not modify the following code for problem 8, but examine it
84 | // in order to under how it works. make sure you understand the control flow
85 |
86 | var successMsg = undefined;
87 | var failureMsg = undefined;
88 |
89 | function succeed(callbacks) {
90 | var succeeded = true;
91 | if (succeeded && callbacks.completed) {
92 | callbacks.completed();
93 | }
94 | }
95 |
96 | function fail(callbacks) {
97 | var succeeded = false;
98 | if (!succeeded && callbacks.failed) {
99 | callbacks.failed();
100 | }
101 | }
102 |
103 | succeed(obj8);
104 | fail(obj8)
105 |
106 |
107 | // 9.
108 | // Create an object with single function `quadruple` which takes a single numeric
109 | // paramater and returns its value multipled by 4
110 |
111 | var obj9 = { };
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 | // ====================================================
126 | // tests
127 |
128 |
129 | if (obj1.name === 'Michael') {
130 | console.log('test 1 passed');
131 | } else {
132 | console.log('test 1 failed *')
133 | }
134 |
135 | if (obj2.name === 'James' && obj2.age === 48) {
136 | console.log('test 2 passed');
137 | } else {
138 | console.log('test 2 failed *')
139 | }
140 |
141 | if (obj3['happy-days'] === true) {
142 | console.log('test 3 passed');
143 | } else {
144 | console.log('test 3 failed *')
145 | }
146 |
147 | if (obj4.music === 'Techno' ) {
148 | console.log('test 4 passed');
149 | } else {
150 | console.log('test 4 failed *')
151 | }
152 |
153 | if (obj5.name && obj5.name.first === 'Ada' && obj5.name.last === 'Lovelace') {
154 | console.log('test 5 passed');
155 | } else {
156 | console.log('test 5 failed *')
157 | }
158 |
159 | if (obj6.name && obj6.name.first === 'Susan' && obj6.name.last === 'Kare' &&
160 | obj6.job && obj6.job.title === 'Creative Director' && obj6.job.company === 'NeXT' ) {
161 | console.log('test 6 passed');
162 | } else {
163 | console.log('test 6 failed *')
164 | }
165 |
166 | if (obj7.meaningOfLife && obj7.meaningOfLife() === 42) {
167 | console.log('test 7 passed');
168 | } else {
169 | console.log('test 7 failed *')
170 | }
171 |
172 | if (successMsg === 'Completed' && failureMsg === 'Failed') {
173 | console.log('test 8 passed');
174 | } else {
175 | console.log('test 8 failed *')
176 | }
177 |
178 | if (obj9.quadruple && obj9.quadruple(1) === 4 && obj9.quadruple(2) == 8 ) {
179 | console.log('test 9 passed');
180 | } else {
181 | console.log('test 9 failed *')
182 | }
183 |
--------------------------------------------------------------------------------
/06-javascript-functions/06-exercises/javascript/built_in.js:
--------------------------------------------------------------------------------
1 |
2 | /*
3 | Javascript provides a number of built-in functions.
4 | We've already seen functions like console.log()
5 |
6 | Some functions are attached to bigger objects like the
7 | Math object. We've haven't learned about objects yet,
8 | but you can call a function on an object with the
9 | "dot notation", like
10 |
11 | Math.pow(2,8); or
12 | Math.exp(100);
13 |
14 | Other functions are attached to data, like a string or
15 | a number. In these cases, you can actually call a function
16 | on the data using the dot notation:
17 |
18 | "hello".toUpperCase();
19 |
20 | If the string has been assigned to a variable, you can
21 | call the function on the variable like:
22 |
23 | var str = "hello";
24 | str.toUpperCase();
25 |
26 | Programming like this is called object-oriented programming,
27 | which we'll learn more about in future lessons. For now just
28 | know that you can call a function on an object like obj.function()
29 |
30 | Let's get some practice with built in functions.
31 | Run this file with $ node built_in.js
32 |
33 | Work on the code until all the tests pass.
34 | */
35 |
36 | // References:
37 | // Math: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math
38 | // Strings: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
39 |
40 | // The absolute value of a number is that number with the sign removed
41 | // Use the Math.abs() function so that the following tests pass:
42 |
43 | var x1 = 100;
44 | var absX1 = x1;
45 |
46 | var y1 = -100;
47 | var absY1 = y1;
48 |
49 | if (absX1 == 100) {
50 | console.log("Test 1 passed");
51 | } else {
52 | console.log("Test 1 failed *");
53 | }
54 |
55 | if (absY1 == 100) {
56 | console.log("Test 2 passed");
57 | } else {
58 | console.log("Test 2 failed *");
59 | }
60 |
61 | // The square root of a number x finds the number y such that y * y = x;
62 | // Use the Math.sqrt() function so the following tests pass:
63 |
64 | var x2 = 16;
65 | var sqrtX2 = x2;
66 |
67 | if (sqrtX2 == 4) {
68 | console.log("Test 3 passed");
69 | } else {
70 | console.log("Test 3 failed *")
71 | }
72 |
73 | // The floor function returns the largest integer less than or equal to a number
74 | // The ceil function returns the smallest integer greater than or equal to a number
75 | // An integer is a whole number.
76 |
77 | // Use the Math.floor() and Math.ceil() functions so the following tests pass:
78 |
79 | var x3 = 3.14;
80 | var floorX3 = x3;
81 |
82 | var y3 = 3.14;
83 | var ceilingY3 = y3;
84 |
85 | if (floorX3 == 3) {
86 | console.log("Test 4 passed");
87 | } else {
88 | console.log("Test 4 failed *");
89 | }
90 |
91 | if (ceilingY3 == 4) {
92 | console.log("Test 5 passed");
93 | } else {
94 | console.log("Test 5 failed *");
95 | }
96 |
97 | // Strings have many funtions available on them.
98 | // Functions on strings are different from the Math functions.
99 | // Call the function directly on the string, for example:
100 | // "Hello".charAt(0);
101 |
102 | // charAt() returns the character at the specified index.
103 | // A character is a single letter, number or other symbol in the string.
104 | // The index is the character's position in the string, starting from 0.
105 | // Use charAt() so that the following tests pass:
106 |
107 | var x4 = "Hello World";
108 | var charAtX4 = x4;
109 |
110 | var y4 = "Munchen";
111 | var charAtY4 = y4;
112 |
113 | if (charAtX4 == 'W') {
114 | console.log("Test 6 passed");
115 | } else {
116 | console.log("Test 6 failed *");
117 | }
118 |
119 | if (charAtY4 == 'u') {
120 | console.log("Test 7 passed");
121 | } else {
122 | console.log("Test 7 failed *");
123 | }
124 |
125 | // Trimming a string means removing whitespace from its ends
126 | // Whitespace is characters like spaces, tabs and new lines.
127 | // Trimming doesn't require any parameters.
128 | // Use the trim() function so that the following tests pass:
129 |
130 | var x5 = " Hello Space ";
131 | var trimX5 = x5;
132 |
133 | if (trimX5 == "Hello Space") {
134 | console.log("Test 8 passed");
135 | } else {
136 | console.log("Test 8 failed *");
137 | }
138 |
139 | // Extract part of a string with the substr() function.
140 | // It takes two parameters, the start index and the length.
141 | // Use substr() so that the following tests pass:
142 |
143 | var x6 = "Hello World";
144 | var substrX6 = x6;
145 |
146 | if (substrX6 == "World") {
147 | console.log("Test 9 passed");
148 | } else {
149 | console.log("Test 9 failed *");
150 | }
151 |
152 | // Find a string inside a string with the indexOf() function.
153 | // Give the function a substring that appears inside the original string
154 | // and it returns where the substring starts.
155 | // Remember that indices in strings begin at 0.
156 | // Use indexOf() so that the following tests pass:
157 |
158 | var x7 = "Hello World";
159 | var substring = "World";
160 | var indexOfX7 = x7;
161 |
162 | if (indexOfX7 == 6) {
163 | console.log("Test 10 passed");
164 | } else {
165 | console.log("Test 10 failed *");
166 | }
167 |
--------------------------------------------------------------------------------
/09-javascript-oop/09-01-javascript-oop.md:
--------------------------------------------------------------------------------
1 | Intro to Object-Oriented Programming
2 | ===================================
3 |
4 | So far we've seen two ways of writing programmes. The first is called *imperative* programming where we provide the computer with a number of instructions and our code is executed in a mostly linear order. The second is *functional* programming where we organize our code into functions and execution revolves around calling functions and performing complex data operations with higher order functions.
5 |
6 | A third way to program is known as *object-oriented* programming, in which code is organized into groups known as objects which contain both data and the operations that can be done to the data. Instead of passing data to functions, objects hold on to data and have functions that work directly with it.
7 |
8 | We will learn the simplist way of using object-oriented patterns in javascript in this chapter. Javascript suppports much more advancd object-oriented programming using its *prototype-based* system, which will be discussed in class but not used quite as much by us.
9 |
10 | ## References
11 |
12 | [Eloquent Javascript](http://eloquentjavascript.net/chapter8.html)
13 |
14 | Chapter 8 in Eloquent Javascript discusses prototype-based object-oriented programming in javaScript
15 |
16 | [MDN Object-Oriented](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Introduction_to_Object-Oriented_JavaScript)
17 |
18 | The Mozilla Developer Network has an introduction to object-oriented programming in javascript.
19 |
20 | [MDN This](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this)
21 |
22 | The Mozilla Developer Network also has a reference document on the `this` keyword.
23 |
24 | ## Objects
25 |
26 | Recall that an object is a collection of key-value pairs or properties that give names to data. An object allows you to group data together and carry it around under a single identifier:
27 |
28 | ```js
29 | var person = {
30 | firstName: 'Philip',
31 | lastName: 'Dow',
32 | age: 33
33 | };
34 | ```
35 |
36 | Properties can be accessed using dot notation and bracket notation:
37 |
38 | ```js
39 | person.firstName;
40 | person['age'];
41 | ```
42 |
43 | We also know that objects can have functions associated with them. Define a function on the object just as you would one of its simple properties:
44 |
45 | ```js
46 | var person = {
47 | firstName: 'Johnny',
48 | lastName: 'Foobar',
49 | age: 33,
50 |
51 | fullName: function() {
52 | return 'Johnny' + ' ' + 'Foobar';
53 | }
54 | };
55 | ```
56 |
57 | What's wrong with our function `fullName`? It *hardcodes* the value it returns. We've actually written in code that it returns "Johnny Foobar" every time instead of whatever value is in `person.firstName` and `person.lastName`. What if we change `firstName` or `lastName`? Then the function still returns "Johnny Foobar", and this is obviously incorrect. Full name should instead refer to the two properties on the object. How can it do that?
58 |
59 | ## This
60 |
61 | We need a way to reference properties on an object from other properties on the object, specifically from functions that are attached to it. The javascript keyword `this` allows us to do this.
62 |
63 | `this` refers to the *context* in which a function is executed. By default `this` refers to the global context, but for functions attached to objects, the context will normally be the object itself. `this` gives us a way to refer to properties on the object that a function is attached to:
64 |
65 | ```js
66 | var person = {
67 | firstName: 'Johnny',
68 | lastName: 'Foobar',
69 | age: 33,
70 |
71 | fullName: function() {
72 | return this.firstName + ' ' + this.lastName;
73 | }
74 | };
75 | ```
76 |
77 | Notice that the `fullName` function now uses `this.firstName` and `this.lastName` to get the first and last names instead of hardcoding it. Now we can change those values and the function will work with the new ones.
78 |
79 | **Call functions with this**
80 |
81 | `this` simply refer to the context in which a function is executed, and for functions attached to an object that will normally be the object itself. `this` stands in for the object, and just as we can access properties with `this` we can also call functions with it.
82 |
83 | Define a function on an object that calls another function on the object:
84 |
85 | ```js
86 | var foo = {
87 | bar: function() {
88 | console.log('called bar');
89 | this.baz();
90 | },
91 | baz: functino() {
92 | console.log('called baz');
93 | }
94 | };
95 | ```
96 |
97 | Notice that the `bar` function on the `foo` object calls the `baz` function on it by way of `this.baz`. If we left off `this` the function would try to call a `baz` function in the global scope.
98 |
99 | **Context is not scope**
100 |
101 | Don't confuse *context* with *scope*. Although there are some similarities the two refer to different environments. Scope refers to the identifiers that are available at some point in the code, where identifiers include the variables and functions available at any given moment.
102 |
103 | Context on the other hand refers a specific object which is referenced by the `this` keyword. Asking for any property or function on `this` asks for it on that object and on no other.
104 |
105 | ## Modules
106 |
107 | This has been a very limited introduction to object-oriented programming in javascript. As it turns out we will not use object-oriented patterns in our node web application development too often. Instead we'll see the use of *modules* in later chapters, but as more object-oriented programming because necessary it will be introduced.
108 |
109 |
110 |
111 |
--------------------------------------------------------------------------------
/10-node/10-exercises/10-exercises.md:
--------------------------------------------------------------------------------
1 | OK Coders: Lesson 10 Exercises
2 | ==============================
3 |
4 | You have a number of homework assignments this week. Complete each assignment. These homework assignments will be difficult. The javascript is not difficult but you will likely spend a great deal of time reading online documentation to understand what built-in modules and functions to use in order to complete the assignments.
5 |
6 | You may download this entire respository from the command line with the git command:
7 |
8 | git clone https://github.com/okcoders/node-introduction-homework.git
9 |
10 | You'll find a number of files in the template subdirectory. Complete the assignment by modifying these files.
11 |
12 | ## References
13 |
14 | [Node API Documentation](http://nodejs.org/api/)
15 |
16 | ## Assignment 1
17 |
18 | **Files**
19 |
20 | - reader.js
21 | - test.txt
22 |
23 | **Instructions**
24 |
25 | Modify the simple file reader we built in class to accept a file path from the command line. The reader will print the contents of that file instead of one that we've *hard coded* into the program. You'll need to use `process.argv[2]` to read arguments from the command line and get the file to read.
26 |
27 | Example Usage:
28 |
29 | $ node reader.js relative/path/to/file
30 |
31 | Test it with text files on your computer. Try the "test.txt" file first. Remember you can use `..` to go up directories. When you get it working you'll have built the most basic version of the `cat` command line program.
32 |
33 | **Documentation**
34 |
35 | [File System Module](http://nodejs.org/api/fs.html)
36 |
37 | [Process global object](http://nodejs.org/api/process.html)
38 |
39 | ## Assignemnt 2
40 |
41 | **Files**
42 |
43 | - printer.js
44 | - printer-test.js
45 | - test.txt
46 |
47 | **Instructions**
48 |
49 | Copy the reader code responsible for reading a file and printing it to the console to a module, namely the printer.js file. Wrap all of that functionality in a single function which takes a parameter for the filename and export it as the `print` function.
50 |
51 | Run print-test.js to test if your printer works. The print-test is hardcoded to use the reader-sample.txt file. Modify it to accept any file path from the command line, like you did with the first assignment.
52 |
53 | Example usage:
54 |
55 | $ node printer-test.js
56 |
57 | And
58 |
59 | $ node printer-test.js relative/path/to/file
60 |
61 | **Documentation**
62 |
63 | [File System Module](http://nodejs.org/api/fs.html)
64 |
65 | [Process Global Object](http://nodejs.org/api/process.html)
66 |
67 | [Creating Modules](http://nodejs.org/api/modules.html)
68 |
69 | ## Assignment 3
70 |
71 | **Files**
72 |
73 | - mycopy.js
74 | - test.txt
75 |
76 | **Instructions**
77 |
78 | Create a program that can take two arguments when called from the command line. Both arguments should be filenames. Your program copies the contents of the file in the first argument to the file identified by the second argument.
79 |
80 | Be careful that you don't overwrite existing files! Keep it simple, try copying test.txt to test-copy.txt, for example.
81 |
82 | Example Usage
83 |
84 | node mycopy filename1 filename2
85 |
86 | Specifically
87 |
88 | node mycopy test.txt test-copy.txt
89 |
90 | You'll need to use the `process.argv` array to get the filenames from the command line.
91 |
92 | **Documentation**
93 |
94 | [File System Module](http://nodejs.org/api/fs.html)
95 |
96 | [Process Global Object](http://nodejs.org/api/process.html)
97 |
98 | ## Assignment 4
99 |
100 | **Files**
101 |
102 | - server.js
103 | - public/
104 | - public/index.html
105 |
106 | **Instructions**
107 |
108 | The simple http server we created in class responds to every request with the same page. Create an http server than can tell what file a user is requesting and send that file if it is located in the public directory.
109 |
110 | For example, if a user browses to *http://127.0.0.1/index.html* then respond with the *public/index.html* file. If they browse to *http://127.0.0.1/about.html* send *public/about.html* (you'll have to create that file). If the file does not exist, send back an error like our simple example from class does.
111 |
112 | You will need to understand the request object (req) in the server callback, part of the `http` module, how to parse the url on the request object with the `url` module, how to build a path with the `path` module, how to check for the existence of a file and read its contents with the fs module, and how to send the file back as the server's response through the response object (res) in the server callback.
113 |
114 | When you are finished you won't have a lot of code. This is actually a very small application. But you will probably spend a great deal of time studying documentation and looking up examples on Stack Overflow.
115 |
116 | Refer back to the Important APIs section of today's class material for more information about some of the modules you'll need to use.
117 |
118 | **Usage**
119 |
120 | $ node server.js
121 |
122 | **Documentation**
123 |
124 | [File System Module](http://nodejs.org/api/fs.html)
125 |
126 | [Path Module](http://nodejs.org/api/path.html)
127 |
128 | [URL Module](http://nodejs.org/api/url.html)
129 |
130 | [HTTP](http://nodejs.org/api/http.html)
131 |
132 | Specifically, you may find the following subsections of the http documentation helpful:
133 |
134 | - [http event request](http://nodejs.org/api/http.html#http_event_request)
135 | - [http incoming message](http://nodejs.org/api/http.html#http_http_incomingmessage)
136 | - [http server response](http://nodejs.org/api/http.html#http_class_http_serverresponse)
137 |
138 | ## Assignment 5
139 |
140 | Begin studying the express documentation. Browse through the Guide and the API Reference.
141 |
142 | [Express](http://expressjs.com/)
--------------------------------------------------------------------------------
/11-express/11-exercises/11-exercises.md:
--------------------------------------------------------------------------------
1 | OK Coders: Lesson 11 Exercises
2 | ====================================
3 |
4 | For this evening's assignment you will create a new express application from scratch and add a number of custom routes to it. Test your application locally with the help of the Postman chrome extension. When you are confident your application is working correctly upload it to heroku.
5 |
6 | ## Create a new express application
7 |
8 | Create a new express application from scratch. You'll need to create a directory for it and run the `express` command inside that directory. Use git to track changes to your application as you will eventually be uploading it to heroku.
9 |
10 | **References**
11 |
12 | [Bash Heroku Git Class](https://github.com/okcoders/bash-heroku-class)
13 |
14 | ## Add twitter bootstrap styling
15 |
16 | Download the twitter bootstrap css stylesheets, javascript files and fonts, and add them to the correct folders inside your project's "public" directory.
17 |
18 | **References**
19 |
20 | [Bootstrap Class](https://github.com/okcoders/bootstrap-class)
21 |
22 | ## Create a couple of static pages
23 |
24 | Add a couple of static html pages to your project, such as an "index.html" page and an "about.html" page. Fill them with whatever content you like, but make sure to apply the twitter bootstrap styling.
25 |
26 | **References**
27 |
28 | [Bootstrap Example](https://github.com/okcoders/bootstrap-example)
29 |
30 | ## Add routes for a posts resource
31 |
32 | Your application will represent a blogging application that has collections of posts. Add routes that support viewing all the posts, viewing a single post, creating a post, editing a post, and deleting a post. Don't worry about generating good responses for the routes. Just send a text response back that identifies the path and any named parameters, as we did in the example, e.g.:
33 |
34 | ```js
35 | app.get('/posts/:id', function(req, res) {
36 | var id = req.params.id;
37 | res.send("You requested post " + id);
38 | });
39 | ```
40 |
41 | Modern web applications use something called *resourceful routing* to represent editable collections of objects on a server. A *resource* is just a collection of data that can be modfied using standard HTTP requests. All of the operations listed above, such as viewing and editing posts, can be implemented with particular VERB and path combinations. The following tables lists those combinations:
42 |
43 |
44 |
45 |
46 |
HTTP Verb
47 |
Path
48 |
Used for
49 |
50 |
51 |
52 |
53 |
GET
54 |
/posts
55 |
display a list of all posts
56 |
57 |
58 |
GET
59 |
/posts/new
60 |
return an HTML form for creating a new post
61 |
62 |
63 |
POST
64 |
/posts
65 |
create a new post
66 |
67 |
68 |
GET
69 |
/posts/:id
70 |
display a specific post
71 |
72 |
73 |
GET
74 |
/posts/:id/edit
75 |
return an HTML form for editing a post
76 |
77 |
78 |
PUT
79 |
/posts/:id
80 |
update a specific post
81 |
82 |
83 |
DELETE
84 |
/posts/:id
85 |
delete a specific post
86 |
87 |
88 |
89 |
90 | Generate all of the following routes above with the VERB and path combinations identified. This implements a posts resource.
91 |
92 | However, you should create these routes inside a separate routing module and require it into the main application. That means you'll need a "posts.js" file inside the "routes" folder in your express project. Scope the module to the `/posts` path from the "app.js" file. Refer to the lesson material and template code for instructions on how to do this.
93 |
94 | ## Add routes for a comments resource on posts
95 |
96 | Add additional routes to your posts module that supports viewing comments on a specific post. Each post in your blog application can have comments. The comments behave like an additional resource attached to a given post. You'll need to use two named parameters to support these routes. Refer to the example used in class and implement all of the following routes:
97 |
98 |
99 |
100 |
101 |
HTTP Verb
102 |
Path
103 |
Used for
104 |
105 |
106 |
107 |
108 |
GET
109 |
/posts/:id/comments
110 |
display a list of all comments for a post
111 |
112 |
113 |
GET
114 |
/posts/:id/comments/new
115 |
return an HTML form for creating a new comment for a post
116 |
117 |
118 |
POST
119 |
/posts/:id/comments
120 |
create a new comment for a post
121 |
122 |
123 |
GET
124 |
/posts/:id/comments/:cid
125 |
display a specific comment for a post
126 |
127 |
128 |
GET
129 |
/posts/:id/comments/:cid/edit
130 |
return an HTML form for editing a comment for a post
131 |
132 |
133 |
PUT
134 |
/posts/:id/comments/:cid
135 |
update a specific comment for a post
136 |
137 |
138 |
DELETE
139 |
/posts/:id/comments/:cid
140 |
delete a specific comment
141 |
142 |
143 |
144 |
145 | You can implement these routes in the same "posts.js" file. Notice the use of the two named parameters `:id` for the post and `:cid` for the comment.
146 |
147 | ## Upload your application to heroku
148 |
149 | Test your application locally and with the Postman chrome extension as you go. When you've got your application working, create a new heroku application and upload it.
150 |
151 | **References**
152 |
153 | [Bash Heroku Git Class](https://github.com/okcoders/bash-heroku-class)
--------------------------------------------------------------------------------
/03-css/03-exercises/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Navigation Bar
6 |
7 |
8 |
9 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
Lorem Ipsum
118 |
The Latin
119 |
120 |
121 | "lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
122 |
123 |
124 |
125 | "sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"
126 |
127 |
128 |
129 |
130 |
131 |
132 |
Lorem Ipsum
133 |
English Translation
134 |
135 |
136 | "But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?"
137 |