Top Banner
Lecture 9: HTTP and Patterns Craig Zilles (Computer Science) March 30, 2020 https://go.illinois.edu/cs105fa19 CS 105
14

L9 HTTP and Patterns€¦ · Lecture 9: HTTP and Patterns Craig Zilles (Computer Science) March 30, 2020 CS 105. Today 1.The Internet •Domain names, IP, HTTP, HTML, CSS, JS 2.Patterns

Oct 12, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: L9 HTTP and Patterns€¦ · Lecture 9: HTTP and Patterns Craig Zilles (Computer Science) March 30, 2020 CS 105. Today 1.The Internet •Domain names, IP, HTTP, HTML, CSS, JS 2.Patterns

Lecture 9: HTTP and Patterns

Craig Zilles (Computer Science)

March 30, 2020

https://go.illinois.edu/cs105fa19

CS 105

Page 2: L9 HTTP and Patterns€¦ · Lecture 9: HTTP and Patterns Craig Zilles (Computer Science) March 30, 2020 CS 105. Today 1.The Internet •Domain names, IP, HTTP, HTML, CSS, JS 2.Patterns

Today1. The Internet• Domain names, IP, HTTP, HTML, CSS, JS

2. Patterns• E.g., Even/Odd, Count, Sum, Find, Find Best

2

Page 3: L9 HTTP and Patterns€¦ · Lecture 9: HTTP and Patterns Craig Zilles (Computer Science) March 30, 2020 CS 105. Today 1.The Internet •Domain names, IP, HTTP, HTML, CSS, JS 2.Patterns

The Internet• Is kind of important• I'm hoping you get the big picture (no memorization)

• Hostname -> name lookup -> IP address• Top-level domains

• You can buy your own domain• URL structure: (three parts: scheme, hostname, path)https://illinois.edu/assets/img/navigation/submenu_about.jpg

3

Page 4: L9 HTTP and Patterns€¦ · Lecture 9: HTTP and Patterns Craig Zilles (Computer Science) March 30, 2020 CS 105. Today 1.The Internet •Domain names, IP, HTTP, HTML, CSS, JS 2.Patterns

The Internet

4

192.168.0.101

192.168.0.182.10.251.47

192.168.0.102

192.168.0.104

ISP

INTERNET

172.217.23.174172.217.23.175172.217.23.176172.217.23.177

Your Homecompany.com

ISP = Internet Service Provider

Domain Name Server (DNS)78.46.75.45

Page 5: L9 HTTP and Patterns€¦ · Lecture 9: HTTP and Patterns Craig Zilles (Computer Science) March 30, 2020 CS 105. Today 1.The Internet •Domain names, IP, HTTP, HTML, CSS, JS 2.Patterns

HTTP/HTTPS• HyperText Transport Protocol (HTTP)

5

Page 6: L9 HTTP and Patterns€¦ · Lecture 9: HTTP and Patterns Craig Zilles (Computer Science) March 30, 2020 CS 105. Today 1.The Internet •Domain names, IP, HTTP, HTML, CSS, JS 2.Patterns

HTML5 = HTML, CSS, Javascript• Separation of Concerns• HTML = content, CSS = styling, JS = interactivity

• HTML documents are hierarchical, cause web pages are• Elements have begin/end tags• Elements can be nested in other elements

• CSS consist of:• Selectors that specify which elements • Attribute : value pairs• Like a Python dictionary

• Javascript is a lot like Python but looks pretty different• variables, expressions, functions, conditionals, loops

6

Page 7: L9 HTTP and Patterns€¦ · Lecture 9: HTTP and Patterns Craig Zilles (Computer Science) March 30, 2020 CS 105. Today 1.The Internet •Domain names, IP, HTTP, HTML, CSS, JS 2.Patterns

Common Idioms / Patterns• There are structures that show up in lots of programs

• Check if even/odd• Visit everything in a collection• Sum • Counter• Finding "best" in collection• Filtering a collection

7

Page 8: L9 HTTP and Patterns€¦ · Lecture 9: HTTP and Patterns Craig Zilles (Computer Science) March 30, 2020 CS 105. Today 1.The Internet •Domain names, IP, HTTP, HTML, CSS, JS 2.Patterns

Check if something is even/odd

(value % 2) == 0 # returns True if value is even

(value % 2) != 0 # returns True if value is odd(value % 2) == 1 # returns True if value is odd

8

Page 9: L9 HTTP and Patterns€¦ · Lecture 9: HTTP and Patterns Craig Zilles (Computer Science) March 30, 2020 CS 105. Today 1.The Internet •Domain names, IP, HTTP, HTML, CSS, JS 2.Patterns

Visit everything in a collection

for thing in collection:… thing …

9

Page 10: L9 HTTP and Patterns€¦ · Lecture 9: HTTP and Patterns Craig Zilles (Computer Science) March 30, 2020 CS 105. Today 1.The Internet •Domain names, IP, HTTP, HTML, CSS, JS 2.Patterns

Computing a sum / total

total = 0 # initialize variable to zero

… # usually in a looptotal += value # accumulate

… total … # do something with the total

Also Average = sum / count10

Page 11: L9 HTTP and Patterns€¦ · Lecture 9: HTTP and Patterns Craig Zilles (Computer Science) March 30, 2020 CS 105. Today 1.The Internet •Domain names, IP, HTTP, HTML, CSS, JS 2.Patterns

Counting

counter = 0 # initialize variable to zero

… # usually in a loop and/or conditional counter += 1 # increment

… counter … # do something with the counter

11

Page 12: L9 HTTP and Patterns€¦ · Lecture 9: HTTP and Patterns Craig Zilles (Computer Science) March 30, 2020 CS 105. Today 1.The Internet •Domain names, IP, HTTP, HTML, CSS, JS 2.Patterns

Compose patterns to solve problems• Write a function that counts the number of even

elements in a list

12

Page 13: L9 HTTP and Patterns€¦ · Lecture 9: HTTP and Patterns Craig Zilles (Computer Science) March 30, 2020 CS 105. Today 1.The Internet •Domain names, IP, HTTP, HTML, CSS, JS 2.Patterns

Finding best in a collection

current_best = a value you know is worse than best

for thing in collection:if thing is better than current_best:

current_best = thing

return / do something with current_best

13

Page 14: L9 HTTP and Patterns€¦ · Lecture 9: HTTP and Patterns Craig Zilles (Computer Science) March 30, 2020 CS 105. Today 1.The Internet •Domain names, IP, HTTP, HTML, CSS, JS 2.Patterns

Filtering a collection (pattern)

newlist = []

for thing in collection:if thing meets criteria:

newlist.append(thing)

14