MIDTERM REVIEW NEXT MONDAY: IN-CLASS MIDTERM CANNOT MAKE IT? If - - PowerPoint PPT Presentation

midterm review next monday in class midterm cannot make it
SMART_READER_LITE
LIVE PREVIEW

MIDTERM REVIEW NEXT MONDAY: IN-CLASS MIDTERM CANNOT MAKE IT? If - - PowerPoint PPT Presentation

CS 498RK FALL 2016 MIDTERM REVIEW NEXT MONDAY: IN-CLASS MIDTERM CANNOT MAKE IT? If for some special circumstance, you CANNOT make the in-class midterm, please email me ASAP. If we don't know about your special circumstance by 11.59pm


slide-1
SLIDE 1

FALL 2016 CS 498RK

MIDTERM REVIEW

slide-2
SLIDE 2

NEXT MONDAY: IN-CLASS MIDTERM

slide-3
SLIDE 3

CANNOT MAKE IT?

If for some special circumstance, you CANNOT make the in-class midterm, please email me ASAP. If we don't know about your special circumstance by 11.59pm Monday, Oct 24th, we won't be able to accommodate you.

slide-4
SLIDE 4

THINGS YOU SHOULD KNOW ABOUT THE MIDTERM

Anything from lecture and MPs is fair game One-sheet of handwritten notes (front and back) Expect to write code: Javascript, HTML, CSS, SASS, JQuery, AngularJS, Mongo Query Language Will test your ability to apply what you've learned in new situations -- NOT regurgitate memorized facts (i.e., history of HTML)

slide-5
SLIDE 5

HOW TO STUDY FOR MIDTERM

Go through all the questions on slides Go through all code examples on slides/CODE PEN Review the challenging aspects of the MPs

slide-6
SLIDE 6

Be sure to review the following topics…

slide-7
SLIDE 7

STRUCTURAL SEMANTIC TAGS

<body> <header> <h1>How to Get a PhD</h1> <nav>...</nav> </header> <article> <section> <figure><img src="benfranklin.jpg"></figure> <h3>Bribing your Committee</h3> <p>When blackmail fails...</p> </section> <aside> <h4>Useful Links></h4> <a href="www.bevmo.com">Research Supplies</a> </aside> </article> </body>

slide-8
SLIDE 8

STRUCTURAL SEMANTIC APPLICATIONS?

slide-9
SLIDE 9

STRUCTURAL SEMANTIC APPLICATIONS

Reuse stylesheets Remix pages and applications Retarget between form factors

<header> <nav> <article> <article> <article>

slide-10
SLIDE 10

<!DOCTYPE html> <html> ... <body> <div class="photo"> <h3>My first photo</h3> <img src="picture1.jpg"/> </div> ... </body> </html> .photo { width:300px; } .photo h3 { font-weight:bold; } img { border:1px solid black; } ...

CSS SELECTORS

map HTML elements to CSS rules

slide-11
SLIDE 11

Which selectors promote the most reuse?

slide-12
SLIDE 12

WHY CASCADING?

more than one rule can apply to an HTML element priority rules for resolving conflicts more specific = higher priority (class trumps element) some properties (font-size) are inherited, while

  • thers aren’t (border, background)
slide-13
SLIDE 13

LINKING TO HTML

higher priority

<link rel=“stylesheet" href=“gallery.css" type="text/css"/> <html> <head> <style> h1 {color:red;} p {color:blue;} </style> <div style="color:blue;text-align:center">

(1) (2) (3)

slide-14
SLIDE 14

Box Model

control over white space

CONTENT PADDING BORDER MARGIN

slide-15
SLIDE 15

position

VALUE DESCRIPTION fixed positioned relative to browser window; will not move when window is scrolled static

  • default. positioned by the flow model;

unaffected by top, bottom, le", right relative positioned relative to its normal position absolute positioned relative to the first ancestor where position!=static

use with top bottom left right

slide-16
SLIDE 16

Design Challenge: vertically center a <div>

  • f unknown height

CODEPEN

slide-17
SLIDE 17

.table-outer { width: 100%; display: table; } .outer { height: 200px; background-color: #144057; display: table-cell; vertical-align: middle; } .inner { width: 100px; height: 50%; background-color: #B6C4C9; }

SOLUTION

<div class=“table-outer"> <div class="outer"> <div class="inner"> </div> </div> </div>

css tables!

slide-18
SLIDE 18

Separation of CONTENT from PRESENTATION?

<div class=“table-outer"> <div class="outer"> <div class="inner"></div> </div> </div>

purely presentational html!

a lot of HTML suffers from presentational div bloat

slide-19
SLIDE 19

CSS PREPROCESSORS

languages that extend CSS in meaningful ways features: variables, nesting, mixins, inheritance shrinks developer’s codebase and compiles into CSS popular CSS preprocessors: LESS and SASS

slide-20
SLIDE 20

JAVA : JAVASCRIPT ::

:

slide-21
SLIDE 21

Functions are first-class objects

slide-22
SLIDE 22

FUNCTIONS ARE OBJECTS that are callable!

reference by variables, properties of

  • bjects

pass as arguments to functions return as values from functions can have properties and other functions

slide-23
SLIDE 23

ANONYMOUS FUNCTIONS

create a function for later use store it in a variable or method of an

  • bject

use it as a callback

see more examples next class

slide-24
SLIDE 24

this the other implicit parameter

a.k.a. function context

  • bject that is implicitly associated

with a function’s invocation defined by how the function is invoked (not like Java)

slide-25
SLIDE 25

apply()and call()

two methods that exist for every function explicitly define function context apply(functionContext,arrayOfArgs) call(functionContext,arg1,arg2,…)

slide-26
SLIDE 26

function forEach(list, callback){ for (var n = 0; n < list.length; n++){ callback.call(list[n],n); } } var numbers = [5,3,2,6]; forEach(numbers, function(index){ numbers[index]= this*2;}); console.log(numbers);

implemented in Javascript 1.6

slide-27
SLIDE 27

Classes are defined through functions

slide-28
SLIDE 28

OBJECT-ORIENTED PROGRAMMING

new operator applied to a constructor function creates a new object no traditional class definition newly created object is passed to the constructor as this parameter, becoming the constructor’s function context constructor returns the new object

slide-29
SLIDE 29

CONSTRUCTOR INVOCATION

function Llama() { this.spitted = false; this.spit = function() { this.spitted = true; } } var llama1 = new Llama(); llama1.spit(); console.log(llama1.spitted); var llama2 = new Llama(); console.log(llama2.spitted);

true false constructors are given the class name

slide-30
SLIDE 30

scopes are declared through functions and not blocks {}

slide-31
SLIDE 31

closure scope created when a function is declared that allows the function to access and manipulate variables that are external to that function

slide-32
SLIDE 32

PRIVATE VARIABLES

var add = (function () { var counter = 0; return function () {return counter += 1;} })(); add();

self-invoking

slide-33
SLIDE 33

PRIVATE VARIABLES

function Llama() { var spitted = false; this.spit = function() { spitted = true; } this.hasSpitted = function() { return spitted; } }

private data member now!

slide-34
SLIDE 34
  • ne-to-one correspondence between HTML elements and DOM nodes

DOCUMENT OBJECT MODEL

<body> <div class="photo"> <h3>My first photo</h3> <img src="picture1.jpg"/> </div> ... </body>

BODY DIV H3 IMG

“My first photo”

slide-35
SLIDE 35

TRAVERSING THE DOM

www.w3schools.com/jsref/dom_obj_all.asp

BODY DIV H3 IMG

“My first photo” var body = document.body; var div = body.children[0]; var h3 = div.children[0]; var textNode = h3.childNodes[0]; var textString = textNode.nodeValue;

slide-36
SLIDE 36

DOM ELEMENT OBJECT

position: element.offsetTop, element.scrollTop, … dimensions: element.clientWidth, element.offsetWidth, … style: element.style

www.w3schools.com/jsref/dom_obj_all.asp

CONTENT

PADDING

BORDER

MARGIN

clientWidth

  • ffsetWidth

(includes scrollbar) relative to

  • ffsetParent
slide-37
SLIDE 37

DOM MANIPULATION

programmatically change the structure and modify element properties element.style.backgroundColor = “red”; element.innerHTML = “<div><h3>Llama!</h3>…</div>” augment DOM structure: element.appendChild(), element.removeChild(), …

www.w3schools.com/jsref/dom_obj_all.asp

slide-38
SLIDE 38

single-threaded: events processed one at a time

THE BROWSER EVENT LOOP

Event Queue Parse HTML and create DOM Check for events Process event Event? YES NO USER BROWSER NETWORK TIMER

slide-39
SLIDE 39

events propagate in two phases capture phase: root to innermost element bubble phase: innermost element to root DOM standard: capture then bubble

EVENT PROCESSING

slide-40
SLIDE 40

element.addEventListener(event, function, useCapture)

EVENT PROCESSING

set capture or bubble phase

CODEPEN

event.stopPropogation()

slide-41
SLIDE 41

JQUERY

cross-browser use for all DOM manipulation: (e.g., positioning relative to document and not

  • ffsetParent)

jquery.com

slide-42
SLIDE 42

ANGULAR CONCEPTS

1.3

Controllers $scope object Directives

MVC Client-side Templating Data Binding

slide-43
SLIDE 43

WAYS OF DATA BINDING

Dependency Object Dependency Property Object Property

OneWay TwoWay OneWayToSrc

slide-44
SLIDE 44

MADLIBS TEMPLATE

<div ng-app> <div ng-controller='MadlibsController'> <div>Hola <span class="madlib">{{madlibs.animal}}</span>, </div> <div>Se llama <span class="madlib" ng-bind="madlibs.name"></span>! </div> <form> <input ng-model="madlibs.name"> </form> </div> </div>

CODEPEN

slide-45
SLIDE 45

MONGO SCHEMA DESIGN

For “one-to-few”, you can use an array of embedded documents For “one-to-many”, or on occasions when the “N” side must stand alone, you should use an array of references. You can also use a “parent-reference” on the “N” side if it

  • ptimizes your data access pattern

For “one-to-squillions”, you should use a “parent- reference” in the document storing the “N” side

blog.mongodb.org/post/88473035333/6-rules-of-thumb-for-mongodb-schema-design-part-3

slide-46
SLIDE 46

RESTful API DESIGN

if a relation is usually requested alongside the resource, embed the relation's representation within the output representation of the resource if a relation can exist independently, include an identifier for it within the output representation

  • f the resource
slide-47
SLIDE 47

GET Get a representation of resource DELETE Destroy resource POST Create a new resource based on the given representation PUT Replace resource state with the one described in the given representation HEAD Get the headers that would be sent with a representation, but not the representation itself OPTIONS Discover which HTTP methods this resource responds to PATCH Modify part of the state of this resource based on the given representation

Verbs

slide-48
SLIDE 48

COLLECTIONS

GET Return all the objects in the collection POST Create a new entry in the collection; automatically assign new URI and return it PUT and DELETE not generally used <VERB> http://example.com/users

slide-49
SLIDE 49

ELEMENTS

GET Return the specific object in collection PUT Replace object with another one DELETE Delete element POST not generally used <VERB> http://example.com/users/12345

slide-50
SLIDE 50

CALLBACK STYLE PROGRAMMING

callbackhell.com

slide-51
SLIDE 51

FALL 2016 CS 498RK

Exam Practice Questions

slide-52
SLIDE 52

<ul id="awesome"> <li class="favorite"> <span class="highlight">Camelid</span> </li> </ul> <style> #awesome .favorite .highlight { color: red; } #awesome .highlight { color: blue; } </style>

1) What color will the string "Camelid" be?

A: Red B: Blue

slide-53
SLIDE 53

var bar = 20; var foo = (function() { var bar = 10; return function(llama) { return llama + bar; } })(); var result = bar + foo(5); console.log(result);

2) What will print?

A: undefined B: 25 C: 35 D: 45

slide-54
SLIDE 54

function foo() { var result = ''; for (var i = 0; i < arguments.length; i++) { result += arguments[i]; } return result; } function bar() { return arguments.join(''); } console.log(foo('a', 'b', 'c')); console.log(bar('a', 'b', 'c'));

3) What will print?

A: foo and bar both print 'abc' B: foo prints 'abc', bar throws a TypeError C: foo throws a TypeError, bar prints 'abc' D: foo and bar both throw a TypeError

slide-55
SLIDE 55

0.1 + 0.2 == 0.3

4) What does this evaluate to?

A: true B: false

slide-56
SLIDE 56

<div class="row"> <div class="medium-3 columns">3</div> <div class="medium-3 columns end">3</div> <div class="medium-3 columns end">3 end</div> </div>

5) What will the following HTML code produce?

A: 3 divs aligned to the left B: 3 divs center aligned C: 2 divs aligned to the left, 1 div aligned to the right D: 1 div aligned to the left, 2 divs aligned to the right

slide-57
SLIDE 57

6) Which of the following is NOT true of MongoDB?

A: Mongo automatically generates an ID for each document. B: Only regular JSON types are allowed. C: Mongo does not support table joins. D: Documents in Mongo have a maximum size.

slide-58
SLIDE 58

var fun = (function outside() { var name = "cat"; var cry = "meow"; return (function inside() { return function() { console.log(name + " goes " + cry); } var name = "dog"; })(); var cry = "woof"; })(); fun();

7) What will print?

A: cat goes meow B: dog goes meow C: undefined goes meow D: dog goes woof

slide-59
SLIDE 59

1) A: Red 2) C: 35 3) B: foo prints ‘abc’ , bar throws a TypeError 4) B: False 5) A: 3 divs aligned to the lefu 6) B: Only regular JSON types are allowed 7) C: undefined goes meow

Answers