CS50 notes
Scratch
try
- hello people
- what’s you name
- hi,response
- meow
- meow module
C
VSCode debug
- Open Developer Command Prompt for Visual Studio:
- Open the “Developer Command Prompt for Visual Studio” from the Start menu. This sets up the necessary environment variables for Visual C++ development.
- Start Visual Studio Code from Developer Command Prompt:
- After opening the Developer Command Prompt, navigate to your project directory using the cd command.
- Launch Visual Studio Code from this command prompt: This ensures that Visual Studio Code inherits the environment variables set up by the Developer Command Prompt.
1
code .
- Configure Environment Variables in Visual Studio Code:
- In Visual Studio Code, you can configure environment variables in the .vscode/settings.json file.
- Open the settings.json file by clicking on the gear icon in the lower-left corner and selecting “Settings.”
- Click on the “Open Settings (JSON)” icon in the top-right corner.
- Add or modify the “env” settings to include the necessary paths. For example: Make sure to adjust the path to match your Visual Studio installation.
1
2
3
4
5{
"env": {
"PATH": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\bin\\Hostx64\\x64"
}
}
- Install the C/C++ Extension:
- Make sure you have the “C/C++” extension installed in Visual Studio Code. This extension provides IntelliSense, debugging, and build support for C and C++ languages.
- Verify Compiler Path:
- In your Visual Studio Code project, create or check the .vscode/c_cpp_properties.json file to ensure the correct path to the compiler is set. For example: Adjust the compilerPath according to your Visual Studio installation.
1
2
3
4
5
6
7
8
9
10
11
12
13
14{
"configurations": [
{
"name": "Win32",
"includePath": ["${workspaceFolder}/**"],
"defines": ["_DEBUG", "UNICODE", "_UNICODE"],
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "msvc-x64"
}
],
"version": 4
}
After these steps, you should be able to build and debug your C++ code within Visual Studio Code, and it should recognize the compiler and tools from your Visual Studio installation.
remove a PATH from this cmd
1 | set PATH=%PATH:C:\cygwin64\bin;=% |
build cs50 lib and link by local
1 | // hello.c |
1 | # build static library |
Valgrind
Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools.
add MSYS2 path
1 | set PATH=%PATH%;D:\app\msys64\ucrt64\bin |
python
install
1 | # install cs50 |
vscode debug
setting
1 | # vscode plugin install |
launch.json - args for parameter
1 | { |
some code
1 |
|
1 | from cs50 import SQL |
1 | # tuple |
SQL
basic
1 | # CRUD |
command and word
1 | .quit |
example #1
1 | sqlite3 shows.db |
example #2
1 | sqlite> DROP TABLE houses; |
HTML/CSS/JavaScript
HTTP query
1 | C:\Users\win10>curl -I https://www.harvard.edu/ |
1st example
1 |
|
link to google search
1 |
|
greet response
1 |
|
1 | document.addEventListener('DOMContentLoaded', function(){ |
input quickly response
1 |
|
Flask
1 | Jinja |
debug mode - auto reload
linux
1 | export FLASK_APP=your_application.py |
windows
1 | set FLASK_APP=your_application.py |
hello
hello #1
auto.bat
1 | set FLASK_APP=app.py |
app.py
1 | from flask import Flask, render_template, request |
templates/index.html
1 |
|
run
1 | PS D:\work\run\python\python_100ds\flask\hello> flask run |
hello #2
app.py
1 | from flask import Flask, render_template, request |
templates/index.html
1 |
|
hello #3
app.py
1 | from flask import Flask, render_template, request |
templates/index.html
1 |
|
templates/greet.html
1 |
|
hello #4 - layout
templates/layout.html
1 |
|
templates/index.html
1 | {% extends "layout.html" %} |
templates/greet.html
1 | {% extends "layout.html" %} |
hello #5 - no show name at URL(POST)
app.py
1 | from flask import Flask, render_template, request |
templates/index.html
1 | {% extends "layout.html" %} |
hello #6 - / for GET and POST
app.py
1 | from flask import Flask, render_template, request |
templates/index.html
1 | {% extends "layout.html" %} |
froshims
froshims #1
app.py
1 | from flask import Flask, render_template, request |
layout.html
1 |
|
index.html
1 | {% extends "layout.html" %} |
success.html
1 | {% extends "layout.html" %} |
registrants.html
1 | {% extends "layout.html" %} |
froshims #2 - add some check and protect
app.py
1 | from flask import Flask, render_template, request |
index.html
1 | {% extends "layout.html" %} |
failure.html
1 | {% extends "layout.html" %} |
froshims4 - add to SQL
create DB
1 | D:\work\run\python\python_100ds\flask\froshims4>sqlite3 froshims.db |
app.py
1 | # Implements a registration form, storing registrants in a SQLite database, with support for deregistration |
index.html
1 | {% extends "layout.html" %} |
registrants.html
1 | {% extends "layout.html" %} |
login
app.py
1 | from flask import Flask, redirect, render_template, request, session |
index.html
1 | {% extends "layout.html" %} |
login.html
1 | {% extends "layout.html" %} |
store
app.py
1 | from cs50 import SQL |
books.html
1 | {% extends "layout.html" %} |
cart.html
1 | {% extends "layout.html" %} |
show2(API)
app.py
1 | # Searches for shows using Ajax with JSON |
index.html
1 | <!DOCTYPE html> |
library
app.py
1 | from cs50 import SQL |
helpers.py
1 | import random |
index.html
1 | {% extends "layout.html" %} |