0-scratch
[Link]
免费开源工具:Visual studio code for cs50 [Link]
云编辑器:[Link]
1-C
程序名、扩展名小写,没有空格
code hello.c
make hello
./hello
Manual pages:
[Link]/#cs50.h
String answer = get_string(“what’s your name? ”);
Printf(“hello, %s\n”,answer);
$clear / ctrl+L
格式代码 format code
%s
%c
%f 浮点 32 位
%i 整数 32 位
%li 长整数 64 位
conditionals
If (x<y)
{
Printf(“x is less than y\n”);
}
If (x<y)
{
Printf(“x is less than y\n”);
}
Else
{
Printf(“x is not less than y\n”);
}
If (x<y)
{
Printf(“x is less than y\n”);
}
Else if (x>y)
{
Printf(“x is greater than y\n”);
}
Else
{
Printf(“x is equal to y\n”);
}
Variables
Int Count = 0;
Count = count+1;
Count += 1;
Count ++;
bool
char 单个字符,用’’
double 双精度
float
int
long 32 位
string 字符串,用””
and: &&
or: ||
loops
int i = 3;
while (i > 0)
{
printf(“meow\n”);
i = i - 1;
}
int i = 0; 通常从 0 开始
while (i <3)
{
printf(“meow\n”);
i ++;
}
for (int i = 0; i < 3; i++)
{
printf(“meow\n”);
}
void 创建函数 meow(void 函数没有返回值)
{
printf(“meow\n”);
}
int main(void)
{
for (int i=0; i < 3; i++)
{
meow( );
}
}
void meow(int n)
{
for (int i = 0; i < n; i++)
{
printf(“meow\n”);
}
}
linux
GUI graphical user interface
CLI command line interface
Docker 容器
cd 切换目录
cp 复制
ls 列出
mkdir 创建目录
mv: $mv 重命名 meow.c 原文件名 woof.c 新文件名
rm
rmdir 删除目录
constants
const int n = 5;
问题集
help50 make hello 寻求建议
style50 hello.c 格式建议
↑:过往指令
tab:根据历史代码补全
// 注释
truncation
type casting
printf(“%.5f\n”,z); 保留 5 位小数
floating-point imprecision
2-arrays
clang c 语言编译器
clang hello.c
./[Link]
clang -o hello hello.c
./hello
clang -o hello hello.c -lcs50
./hello
#预处理指令
preprocessing
compiling 编译 转为汇编代码
assembling 汇编 转为 0 和 1
linking
GCC 编译器 GNU 编译器
debugging
$debug50 ./buggy
“And the problem with that logic is that you begin to build up technical debt, what’s so to speak,
where you really should have learned it earlier. You really should have learned it earlier. You really
should have learned it earlier, at which point you end up spending more time wasted using printf
and doing things manually than if you had just spent 10 minutes, 30 minutes just learning the
user interface and the buttons of a proper debugger. So please take that advice, because it will
save you significant amounts of time over time.”
[Link]
bool: 1 byte
int: 4 bytes
long: 8 bytes
float: 4 bytes
double: 8 bytes
char: 1 byte
string: ? bytes
只要有浮点数参与,整个算术表达式就会变成浮点数运算
arrays
int scores[3];
scores[0]=72; 从 0 开始计数
scores[1]=73;
scores[2]=33;
常量字母习惯大写,为了视觉上引起注意
全局变量 主函数之上
字母和数字可以互相转换
所有字符串都是 n+1(NUL:00000000,代表字符串的结束 表示方式:\0) 格字节
在字符串库中,有意计算字符串长度的函数 strlen
ctype.h
[Link]/#ctype.h
command-line arguments
#include <stdio.h>
int main(int argc 参数个数, string 字符串数组 argv 参数向量[])
{
...
}
ASCⅡ art
exit status
echo $?
cryptography
encryption
plaintext→cipher→ciphertext
decryption
3-algorithms
linear search
binary search
running time
大 O 表示法:表示对可能要计数的步骤的上限
O(n2)
O(n log n)
O(n):linear search
O(log n):binary search
O(1):常数步骤
Ω(omega)表示法:表示对可能要计数的步骤的下限
Ω(n2)
Ω(n log n)
Ω(n)
Ω(log n)
Ω(1):linear search, binary search
Θ 表示法:O 与 Ω 恰好相同
Θ(n2)
Θ(n log n)
Θ(n)
Θ(log n)
Θ(1):
string.h
strcmp 用于字符串的比较
电话号码保存为字符串:1.防数据溢出 2.无算术意义
data structures
typedef struct
{
string name;
string number;
}
person;
typedef struct
{
string name;
string number;
}person; 同一行(style50)
sorting
1. selection sort O(n2) Ω(n2) Θ(n2)
For i from 0 to n-1
Find smallest number between numbers[i] and numbers[n-1]
Swap smallest number with numbers[i]
n(n-1)/2
2. bubble sort
Repeat n-1 times
For i from 0 to n-2
If numbers[i] and numbers[i+1] out of order
Swap them
If no swaps
Quit
(n-1)(n-1) O(n2) Ω(n)
recursion 递归
merge sort
If only one number
Quit
Else
Sort left half of numbers
Sort right half of numbers
Merge sorted halves
nlog2n
O(n log n) Ω(n log n) Θ(n log n)
4-Memory
RGB
black: ##000000
white: ##FFFFFF
hexadecimal 十六进制
base-16
0xFF: 255
& 地址操作符
* 解引用操作符
pointers 指针
int n = 50;
int *p = &n; 让编译器提供一个变量 p,里面可以存储一个整数的地址
0x7ffe434904bc
50
int *p 声明变量
*p 去那个位置
通常指针会占用更多内存,比如 8 字节
0x564dfc6f3004
0x564dfc6f3004
0x564dfc6f3004
0x564dfc6f3004
0x564dfc6f3005
0x564dfc6f3006
0x564dfc6f3007
string s = “HI!”;
char *s = “HI!”;
typedef uint8_t BYTE;
typedef char *string;
pointer arithmetic
malloc
free
<stdlib.h>
如果没有内存,直接返回
valgrind 检查内存的使用情况
$ valgrind ./meomry
garbage values
scope 范围
passing by value 按值/副本传递
heap 堆
stack 堆栈
fram 帧
passing by reference
heap overflow 堆溢出
stack overflow 栈溢出
buffer overflow 缓冲区溢出
“不要警告未初始化”
指针通常为 8 个字节
file I/O
fopen
fclose
fprintf
fscanf
fread
fwrite
fseek
...
fopen(“[Link]”, “a”)
“r”——reading
“rb”——reading binary
“w”——writing
“a”——appending
<stdint.h>
uint8: 无符号的 8 位值,为没有负数的原始数据
$make cp
$code [Link]
$./cp [Link] [Link]
$code [Link]
BMP 位图
5-data structures
1. abstract data types
1.1 queues
FIFO 先进先出
enqueue 入列
dequeue 出列
1.2 stacks
LIFO 后进先出
push 推送
pop 弹出
arrays
struct
.
*
linked lists
数据 指针 元数据
typedef struct node
{
int number;
node *next;
}node;
node *list = NULL;
node *n = malloc(sizeof(node));
(*n).number = 1;
n -> number = 1;
n -> next = NULL;
node *n = malloc(sizeof(node));
n -> number = 2;
node *ptr = list;
添加:O(1)
搜索:O(n)
trees
binary search trees
typedef struct node
{
int number;
struct node *left;
struct node *right;
} node;
bool search(node *tree, int number)
{
if (tree == NULL)
{
return false;
}
else if (number < tree->number)
{
return search(tree->left, number);
}
else if (number > tree->number)
{
return search(tree->right, number);
}
else
{
return true;
}
}
dictionaries
hashing 散列法
hashing function
hash tables
typedef struct node
{
char *name;
char *number;
struct node *next;
}node;
node *table[26];
#include<ctype.h>
unsigned int hash(const char *word) 不更改字符串
{
return toupper(word[0]) - ‘A’;
}
tries 数组的树
typedef struct node
{
struct node *children[26];
char *number;
}node;
node *trie;
O(1)
06-Python
make hello
clang -o hello hello.c -lcs50 命名 引用库
./hello
print(“hello, world”)
python [Link] 解释器
dictionary: 1.检查函数 2.加载函数 3.大小函数 4.卸载函数
set() 不包含重复项
python 图像库:PIL
$python [Link]
$code [Link]
在实际开发过程中,例如 Python 编程语言中的 pip 就是一个经典的 wheel 使用例子。通过 pip 命令,开发者可以轻松地安装、卸载
Python 软件包,不必关心复杂的依赖关系处理。像 Django、Flask 等 web 框架,也是 web 开发中常用的 wheel 之一,它们简化了
路由、数据库操作、会话管理等复杂任务。
faces/ $ code [Link]
faces/ $ code [Link]
faces/ $ python [Link]
faces/ $ code [Link]
faces/ $ python [Link]
faces/ $ code [Link]
functions
print(“hello, world”)
libraries
import cs50
from cs50 import get_string
answer = get_string(“what’s your name? ”)
print(“hello, ” + answer)
print(“hello, ” , answer)
print(f“hello, {answer}” ) 格式化字符串,f 字符串
answer = input(“what’s your name? ”)
print(f”hello, {answer}”)
variables
counter = 0
counter += 1
types
C: bool, char, double, float, int, long, string...
python: bool, float, int, str...
python 的其他类型
range
list 通常是不变的值组合
tuple
dict dictionary
set 值的集合,去除了重复项
...
C
get_char
get_double
get_float
get_int
get_long
get_string
...
python
get_float
get_int
get_string 不那么有用
from cs50 import get_float, get_int, get_string
1 import cs50
2
3 x = cs50.get_int(“x: ”) 避免函数重名
4 y = cs50.get_int(“y: ”)
5
6 print(x + y)
conditionals
if x < y:
print(“x is less than y”)
python 约定使用四个空格,(Tab 键自动转换为相同的缩进)
if x < y:
print(“x is less than y”)
else:
print(“x is not less than y”)
if x < y:
print(“x is less than y”)
elif x > y:
print(“x is greater than y”)
else:
print(“x is equal to y”)
str
object-oriented programming OOP
[Link]/3/library/[Link]#string-methods
[Link]/3/library/[Link]
[Link]
loops
i=0
while i < 3:
print(“meow”)
i += 1
for _ in rang(3): 只是一个用于循环的变量,变量的名称不重要
print(“hello, world”)
while True:
print(“meow”)
named parameters e.g. end
positional parameters
定义函数:
主函数上移(需要调用主函数)
加参数:
truncation
floating-point imprecision
integer overflow
exceptions
遇到错误也可以直接 pass:
[Link]
????
###
###
###
list 在 python 中更像一个链表
[Link]/3/library/[Link]#sequence-types-list-tuple-range
[Link]/3/library/[Link]#len
让用户输入成绩:
电话本【for 循环&else】
dict
在 Python 中,字典本质上是一个哈希表,一个键值对的集合
or:
print(f”found {person[‘number’]}”) 不能连续套用两个双引号
[Link]/3/library/[Link]#mapping-types-dict
sys 库
[Link]/3/library/[Link]
or
1 import sys
2
3 if len([Link]).....
pip
6-Artificial Intelligence
DALL-E 2
[Link]
Midjourney
[Link]
ChatGPT
API = Application Programming Interface
API 的英文即 Application Programming Interface 首字母的缩写。不要被这么长的单词吓到,直译过来的意思就是:程序之间的接
口。我更倾向于把 API 理解为,程序之间的合约。
Vector Database
向量数据库也叫矢量数据库,是一种以数学向量的形式存储数据集合的数据库。更通俗的说法,向量就是一个数字列表,例如:[12, 13, 19, 8,
9]。这些数字表示维度空间中的一个位置,代表在这个维度上的特征。就像行和列号表示电子表格中特定单元格一样(例如,“A10”表示 A 列
10 行)。向量数据库的应用是使机器学习模型更容易记住先前的输入,从而使机器学习能够用于支持搜索、推荐和内容生成等应用场景。向量数据
可以基于相似性搜索进行识别,而不是精确匹配,使计算模型能够在上下文中理解数据。
prompt engineering
system prompt
user prompt
√ adivises students on how to improve their code’s style
√ answers(most of the) questions asked online by students
√ explains arcane error messages, hints how to solve
√ provides students with virtual office hours 24/7
[Link]
[Link]
√ approximates a 1:1 teacher-to-student ratio
generative artificial intelligence
decision trees
while game is ongoing:
if ball is left of paddle:
move paddle left
else if ball is right of paddle:
move paddle right
else:
don’t move paddle
minimax
if player is X:
for each possible move:
calculate score for board
choose move with highest score
else if player is O:
for each possible move:
calculate score for board
choose move with lowest score
machine learning
reinforcement learning
explore vs. exploit
epsilon = 0.10
if random() < epsilon:
make a random move
else:
make the move with the highest value
deep learning
neural networks
ax + by + c > 0
generative artificial intelligence
large language models
transformer architecture
hallucinations 幻觉
8-SQL
flat-file database
我们所说的平面文件数据库是指包含所有数据的文件文件的代码
CSV
在 CSV 中的一个惯例:引用那些本身带有逗号的字符串,这样读取文件的程序不会混淆
with open(“[Link]”, “r”) as file: 文件将在之后自动关闭 默认,可省略
DictReader 阅读每一列相对应的内容,更稳定
用字典计数:
sorted() ——按字母排序
key=[Link]——按值排序(递增)
key=[Link], reverse=True——按值排序(递减)
计数器 Counter()
favorite problem
relational database
SQL 结构化查询语言,是一种声明性语言
SQL 遵循 CRUD 范式:
C——Create, insert
R——Read, select
U——Update
D——Delete, drop(删除整个数据库表格)
CREATE TABLE table (column type, ...);
sqlite3
sqlite3 FILE
.schema 显示数据库表的架构
Ctrl + L 清除
SELECT columns FROM table; *——通配符,显示所有
AVG
COUNT
DISTINCT
LOWER
MAX
MIN
UPPER
...
WHERE
LIKE
ORDER BY
LIMIT
GROUP BY
...
默认升序(ASC),降序:DESC
重命名 AS
INSERT INTO table(column, ...) VALUES(value, ...)
DELETE FROM table WHERE condition;
UPDATE table SET column = value WHERE condition;
IMDb
one-to-one
数据类型
BLOB 二进制大对象
INTEGER
NUMERIC 日期、时间
REAL
TEXT
NOT NULL
UNIQUE
PRIMARY KEY
FOREIGN KEY
JOIN
one-to-many
这些临时表只是为了我们查看和分析数据,实际上没有在数据库中重复储存
many-to-many
大小写只是为了方便理解,SQL 本身不关心大小写
第二种方法:使用 JOIN,更慢
第三种方式,同时对三个表进行筛选,也比嵌套慢
sqlite> .schema
不指定具体的表则会显示所有表的结构
sqlite> .timer ON 打开计时功能
indexes 索引
CREATE INDEX name ON table (column, ...)
B-trees
主键会自动创建索引。默认情况下,外键是没有索引的。
from cs50 import SQL
重新导入文件
将 SQL 和 Python 结合:
SQL 擅长从数据库中读取数据,Python 可能是创建用户界面或最终制作 Web 应用程序的最佳选择
[Link]/libraries/cs50/python/#[Link]
race conditions
解决方案
BEGIN TRANSACTION
COMMIT
ROLLBACK
这意味着,基本上,这三行代码应该要么一起发生,要么根本不发生
SQL injection attacks
安全的代码(用了“?”占位符):
不安全的代码:
rows = [Link](f”SELECT * FROM users WHERE username = ‘{username}’ AND password =
‘{password}’”)
if rows:
...
rows = [Link](f”SELECT * FROM users WHERE username = ‘malan@[Link]’--’ AND
password = ‘{password}’”)
-- 忽略后面的内容
‘’: 意味着指的是一个字面引号
利用的漏洞是软件未正确“转义”名称输入中的单引号。因此,当名称嵌入到某个 SQL 语句中时,引号被错误地解析为该语句中的结束引号,而不
是作为名称的一部分进行解析。缺少这种转义是一个常见的 SQL 漏洞;这种类型的漏洞称为 SQL 注入。
9-HTML, CSS, JavaScript
internet
routers
TCP/IP
IP 互联网协议
IP 地址: #.#.#.# IPv4(32 位,232≈40 亿)→ IPv6(128 位,2128)
共享 IP
一个数据包的布局
TCP (通过文件的序列号)
仅依靠 IP 是不足以保证交付的,因为有时候数据包可能根本无法到达目的地
ports 端口号
源地址、目标地址、备忘录字段、序列号、端口号
80 HTTP(代表 Web)
443 HTTPS(代表 HTTP 的某种安全版本)
DNS 域名系统服务器(这个域名的 IP 地址是什么?)
一种分层系统
根服务器
DHCP 动态主机配置协议
(我的 DNS 服务器和路由器应该是什么?设备应该使用什么 IP 地址?)
HTTP 全球网络
是一种规定了 Web 浏览器和 Web 服务器如何通信的协议
HTTP 代表的是超文本传输协议,规范了我们如何从点 A 到点 B 获取网络流量,从浏览器到服务器再返回
HTTPS:连接以某种方式进行了加密,以至于在点 A 到点 B 截取数据包的人几乎不可能知道信封里面有什么
统一资源定位符(Uniform Resource Locator)”简称为 URL。
[Link]
[Link] 表示网站的默认页面
[Link] 路径
[Link] 实际的文件
现在很多时候会省略.html
[Link] 通常表示服务器上的一个文件夹
[Link]
www 主机名,大多数 URL 可能仍然以 www 开头,但不是严格要求
com 顶级域(.com 代表商业、.edu 代表教育、.gov 代表政府、.uk、.jp、.tv、.ai 都是国家代码、.ly 也是国家代码,允许购买域
名,如:.cs50)
https 方案/协议
有两种从服务器请求信息的方式:
1. GET:默认(获取),点击链接
2. POST:(发送)比如提交信用卡、上传图片
GET / HTTP/2 版本号
Host: [Link] (:提供了一个键值对)
服务器返回给浏览器的内容:
HTTP/2 200 状态码
Content-Type:text/html
curl:连接到一个 URL
这是一个命令行程序,随 Linux、Mac OS、Windows 一起提供
developer tools F12
GET / HTTP/2
Host: [Link]
301 意味着哈佛的网站已经永久性地移动了
HTTP/2 404
Content-Type:text/html
...
以 3 开头的代码都与重定向有关
以 4 开头的代码意味着浏览器某种方式做错了什么
GET / HTTP/1.1
Host: [Link]
...
HTML 一种基于文本的标记语言,只是关于呈现信息
tags
attributes 属性
缩进不是必须的
http-server
8080——端口号
开始标签和结束标签之间的所有内容通常被泛称为元素
Squarespace、Wix 这样的第三方服务可以轻松创建网站,只需点击、拖动、放置就可以生成 HTML
每当用浏览器从服务器请求页面时,该服务器可能会记录一些信息(IP 地址、浏览器类型、操作系统版本...)即使是隐身模式仍会被记录
添加终端:
想要获取更新的内容,需要点击浏览器的重新加载按钮
HTML 不关心空格的数量
<p></p> 段落标签
unordered list tag
<ul></ul>
list item tag
<li></li>
ordered list tag
<ol></ol>
table
table row: <tr></tr>
table data: <td></td>
image
alt 图像的替代文本
video
link
在超链接上悬停可以在网页左下角看到网址
网络钓鱼
meta
调整尺寸
创建预览
[Link]
[Link]
[Link]
autocomplete
autofocus
placeholder
regular expressions(regexes) 正则表达式:一种使用模式来验证输入或从字符串中提取信息的方法
[Link]/en-US/docs/Web/JavaScript/Guide/Regular_expressions
. any single character(expect line terminators)
* zero or more times
+ one or more times
? 0 or 1 time
{n} n occurrences
{n,m} at least n occurrences, at most m occurrences
[0123456789] any one of the enclosed characters
[0-9] any one of the range of characters
\d any digit
\D any character that is not a digit
...
pattern=”.+@.+\.edu ” 转义“.”代表真正的“.”,而非任意字符
不安全,可以在开发者工具里面进行修改
[Link]
来自万维网联盟的免费网络服务,该联盟基本上是规范化 HTML 语言的组织
验证代码,通过上传文件或直接输入来检查其准确性
CSS 层叠样式表
properties
type selector
class selector
ID selector
attribute selector
...
方法一:
<!DOCTYPE html>
<html lang="en">
<head>
<style>
</style>
<title>
hello, title
</title>
</head>
<body>
hello, body
</body>
</html>
方法二:
<!DOCTYPE html>
<html lang="en">
<head>
<link href=”[Link]” rel=”stylesheet”> 意味着两个文件在某种概念上是相关联的
<title>
hello, title
</title>
</head>
<body>
hello, body
</body>
</html>
字号
居中
division
修改:1.在 body 处统一设置属性 2.特殊符号 3.语义标签
搜索引擎优化 (SEO)
样式标签
创建类
CSS
1. 更改链接字体颜色
2. 去除链接下划线
3. 悬停时显示下划线
.harvard{} 代表类
#harvard{} 代表 id
harvard{} 代表字面上的标签
给不同 id 设置不同属性
frameworks
Bootstrap
[Link]
[Link]
min 意味着删除了大部分空白
[Link]
选择关键字,检查,可以看到相关 CSS 属性
JavaScript
在 HTML 的世界里,不仅可以在页面头部放置样式标签,还可以放置脚本标签,其中包含 JavaScript 代码
[Link]
return false 不要将表单提交到服务器
[Link]
addEventListener 监听
[Link](); 阻止表单提交内容至服务器
[Link]
DOM 文档对象模型,是一种在计算机内存中表示网页的树的高级说法
DOMContentLoaded 这确保,即使脚本位于顶部而表单位于顶部,除非整个 DOM 准备就绪,否则不会执行任何此代码
在 JavaScript 中,不能使用 background-color,因为系统会把“-”看作减法。解决方案:采用驼峰命名法,把单词首字母大写
backgroundColor
[Link]
[Link]
keyup 监听键盘弹起的这个动作
‘’ 单/双引号皆可,JavaScript 程序员倾向单引号
blur
change
click
drag
focus
keyup
load
mousedown
mouseover
mouseup
submit
touchmove
unload
...
[Link]
10-Flask
http-server:是一个 Linux 程序,只是运行你自己的 Web 服务器,它允许你在非标准端口上运行它
我们一直使用端口 8080,是因为 Codespaces 正在使用 80 和 443
[Link]
[Link]
[Link] 路径
[Link] 路由(指向应用程序的某个部分)
[Link] 获取输入
[Link]
GET /search?q=cats HTTP/2
Host: [Link]
...
Flask
实际上是一个第三方库,让使用 Python 实现 Web 变得更容易(类似的还有 Django
)。允许直接允许 flask run 启动 Web 应用程序,而不是 http-server
[Link]
[Link]
static 放置图片或 .css 文件或 .js 文件,可能偶尔会更改
templates/ 包含我们编写的任何实际 HTML、可能的 CSS 或 JavaScript
__name__ 当前文件的名称
“/” 按照约定
查看网页源代码,它是一个文本而不是 HTML,只是以网页的方式呈现
再次查看网页源代码,此时是 HTML
[Link] 指任何 HTTP 请求
{{ placeholder }}
Jinja 规范了一些占位符的语法和其他功能的一种语言
手动更改 URL
[Link]
查看源代码
如果没有手动更改 URL:
如果没有手动更改 URL(默认值):
如果没有”name”就使用默认值”world”
当占位符不止一个时,更好的风格是命名为一个有意义的变量
方法二(更加用户友好):
建立模板:
套用模板:
HTTP 参数出现在网址中的好处是网址是有状态的
有一种方法可以不显示状态:使用 post(替代方法)而不是 get(默认)
@[Link](“/greet”, methods=[“GET”]) 默认
@[Link](“/greet”, methods=[“GET”, “POST”]) 同时支持两种
[Link]
对 C 语言、Python 来说,一旦返回一个值,那个函数中的任何内容之后都不会被执行
(省略了 else)
form action=”/” 可省略,表单将假定用户要将其提交到来自的那个路由
保持 greet 和 index 分开是合理的,但可以 避免为可能想要实现的每个功能都设置两种方法来使 [Link] 文件膨胀
去除”world”,因为不会被选择
Ctrl + C 退出 Flask/http-server
为了避免干扰用户选择可以设置一个默认选项
required 用户必须进行输入
检查用户是否输入:
补全另一种情况:
在 [Link] 模板中传入一个名为 sports 的占位符,并将其设置为全局变量 SPORTS 的值(便于添加新的运动)
查看源代码:
验证运动种类:
这样即使通过开发者工具注册额外的运动种类也无法成功
改用单选按钮:
改成多选按钮:
type=”checkbox”
检查每一个选中的运动有没有在列表中:
froshims4
redirect
302 某种重定向
froshims5
查看登记页面源代码,每行数据都有自己的表单:
Model View Controller(MVC 范式)
其中视图是人类看到的一切,比如模板、HTML、CSS、JavaScript。控制器是在 [Link] 中的所有东西。模型是所有数据储存的地方
登录界面:
GET / HTTP/2
Host: [Link]
实际登陆:
HTTP/2 200
Content-Type:text/html
Set-Cookie:session=value
(session:描述客户端和服务器之间状态维持的一个词)
下次当你访问 Google 的同一服务器时,你的浏览器应该提醒服务器设置了什么 cookie
GET / HTTP/2
Host: [Link]
Cookie:session=value
cookie 只是一个提醒服务器你是谁的东西
[Link][“SESSION_PERMANENT”] = False
会话 cookie:关闭选项卡时,通常会删除会话中的内容
[Link][“SESSION_TYPE”] = “filesystem”
确保您的购物车或类似内容存储在服务器的文件中,而不是 cookie(出于隐私考虑)
store
重定向总是 get 请求
show
不能使用 f 字符串,防止注入攻击
ajax:这个术语源自描述从基于 Web 的应用到基于数据的应用的转换。在基于数据的应用中,用户需求的数据如联系人列表,可以从独立于实际
网页的服务端取得并且可以被动态地写入网页中,给缓慢的 Web 应用体验着色使之像桌面应用一样。
response 里面是列表而不是 URL
异步函数
API 应用程序编程接口
通常是一种标准化的方式,从其他人的服务器或服务中获取数据到你的应用程序中
<li>列表项是一种发送信息的不太规范的方式。现在更常见的是返回一种叫 JSON(JavaScript 对象表示)的数据格式
看起来和 Python 中的字典和列表非常相似,但是必须在字符串周围用双引号(不能用单引号)
show3
jsonify:将某物转换为 JSON
11-Cybersecurity
[Link]/Hacks/by_year/1991/fire_hydrant/
[Link]/Hacks/by_year/2022/cs50_duck/
编程准备:
Install command-line tools
[Link]
[Link]
...
Learn Git(版本控制软件)
[Link]
...
Download VS Code
[Link]
[Link]
Host a web site(静态托管)
[Link]
[Link]
...
Host a web app(动态托管)
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
...
Ask questions
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
...
Take classes
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
passwords
4-digit passcode
brute-force attacks
8-digit passcode
password managers
two-factor authentication(2FA)
multi-factor authentication(MFA)
one-time passwords
hashing
单向的
rainbow table
salting
cryptography
是可逆的
secret-key cryptography 又称对称加密 symmetric cryptography
public-key cryptography 又称不对称加密 asymmetric cryptography
是 HTTPS 的工作原理
人们很常用非对称加密来生成一个大的共享密钥,然后在此后使用更快的算法。
passkeys
不需要设置用户名和密码,当你首次访问一个网站时,设备会生成一个公钥和私钥对。然后设备会把公钥发给正在注册的网站,但私钥是私密的。
在加密世界中,你使用别人的公钥来发送加密的消息,然后他们使用他们的私钥来解密它。在签名或者说是密码验证的世界中,颠倒了这个过程。使
用私钥来有效地加密收到的一些随机挑战,然后网站、第三方可以使用公钥来验证。
end-to-end encryption
端到端加密是一种安全通信形式,防止第三方的窥探或未经授权的访问。
deletion
secure deletion
将原始数据变成随机的 1 或 0
full-disk encryption 将磁盘上所有内容都随机化了
· BitLocker (windows 系统)
· FileVault (app 系统)
...
ransomware