Lecture 25 - Course Revision
Source: The Turing Way Community (2025)
FF
is 11111111
binary, 255 decimal)#FF0000
) or memory addresses conciselyConversion table
ASCII table
Languages bridge the gap between human instructions and machine execution:
High and low-level languages
Core commands:
pwd
: Print Working Directory (shows current location)ls
: List directory contents (ls -l
for details, ls -a
for hidden files)cd <directory>
: Change Directory (cd ..
up, cd ~
home)mkdir <name>
: Make Directorytouch <name>
: Create empty file / update timestampcp <source> <dest>
: Copy file/directory (-r
for directories)mv <source> <dest>
: Move or Rename file/directoryrm <file>
: Remove file (permanently!)rmdir <empty_dir>
: Remove empty directoryrm -r <dir>
: Remove directory recursively (DANGEROUS! No undo)cat <file>
: Display entire file contenthead <file>
/ tail <file>
: Show first/last lines (-n #
)wc <file>
: Word Count (lines, words, characters)grep <pattern> <file>
: Search for text patterns using regular expressions
-i
(ignore case), -r
(recursive), -n
(line numbers), -v
(invert match)find <path> [options]
: Powerful search tool
-name <pattern>
: Find by name (use quotes for patterns with *
)-iname <pattern>
: Case-insensitive search-type d
/ -type f
: Find directories / files-size +1M
: Find files larger than 1 Megabyte*
(any characters), ?
(single character)Source: Julia Evans (2024)
>
: Redirect output to file (overwrites)>>
: Append output to file<
: Redirect input from file (less common)|
: Chain commands; output of the left command becomes input for the right command (e g, history | grep cd
).sh
file for automation
#!/bin/bash
(shebang)chmod +x script.sh
./script.sh
A simple script that moves .png
files to the Desktop
git add <file>
(moves changes to the Staging Area)git commit -m "message"
(creates a commit in the local Repository)git status
, git add
, git commit
, git log
, git diff
Source: Atlassian
GitHub provides a central location (remote repository, often called origin
) for sharing code and tracking project progress
Interactions:
git push
: Uploads local commits to the remote repositorygit commit
: Records changes in the local repositorygit pull
: Downloads remote changes and merges them locally.gitignore
tells Git which files/directories should not be tracked
Other GitHub features:
main
/master
) branchgit checkout -b feature-x
), make commits, then merge back into main (git checkout main
, git merge feature-x
)Read more: Git Branching
.qmd
or .ipynb
) into multiple formats like HTML, PDF (via LaTeX), MS Word, presentations, websites, and booksA typical Quarto (.qmd
) document includes:
---
, defines document metadata (title, author, date) and output format options (format: html
, format: pdf
, format: revealjs
)$...$
, $$...$$
){python}
) with options (prefixed with #|
) controlling execution (eval
), visibility (echo
), figure generation (fig-cap
), etcquarto render mydoc.qmd
You can also use Quarto for:
[@citekey]
, needs .bib
)@fig-label
)WebUI GitHub repository: https://github.com/browser-use/web-ui
.pem
file)ssh
command from your local terminal with your private key file (.pem
) Requires correct permissions (chmod 400 key.pem
)
ssh -i key.pem ubuntu@<public-ip-or-dns>
apt
package manager
sudo apt update
: Refresh package listssudo apt upgrade
: Install updatessudo apt install <package-name>
: Install softwarescp
): Securely copy files between local machine and EC2 instance
scp -i key.pem local_file ubuntu@ip:/remote/path
(local to remote)scp -i key.pem ubuntu@ip:/remote/file ./local/path
(remote to local)DataFrame
(2D table) and Series
(1D array)melt()
: Converts wide data to long formatpivot()
/pivot_table()
: Converts long data to wide format; pivot_table
handles aggregation if neededpd.concat()
: Stacks DataFrames row/column-wisepd.merge()
: Performs database-style joins (inner
, left
, right
, outer
)df.groupby('column')
splits data for group-wise operationsmean
, sum
, size
, count
, std
, min
, max
, custom functions) to groups, often using .agg()
for flexibility.apply()
(row/column-wise), .applymap()
(element-wise DF), .map()
(element-wise Series)NaN
isnull()
, notnull()
, info()
dropna()
fillna()
(with value, mean, median, method='ffill'
, etc)Core commands:
CREATE TABLE
: Define table schema (columns, data types like INTEGER
, TEXT
, REAL
)INSERT INTO
: Add new rowsSELECT
: Retrieve data (SELECT cols FROM table WHERE condition ORDER BY col
)UPDATE
: Modify existing rows (UPDATE table SET col = val WHERE condition
)DELETE FROM
: Remove rows (DELETE FROM table WHERE condition
)ALTER TABLE
: Modify table structureDROP TABLE
: Delete a tableGoing beyond basic queries:
WHERE
): Use operators (=
, >
, LIKE
, IN
, BETWEEN
, IS NULL
) and logic (AND
, OR
)GROUP BY
): Group rows and apply functions (COUNT
, SUM
, AVG
, etc); filter groups with HAVING
INNER JOIN
, LEFT JOIN
) based on related columnsSELECT
statementsRANK() OVER (...)
, AVG(...) OVER (PARTITION BY ...)
), preserving individual rowsSUBSTR
, LENGTH
, REPLACE
, ||
for concatenation in SQLite)CASE WHEN condition THEN result ... ELSE default END
sqlite3
module provides direct access to SQLite databases (connect, cursor, execute, commit, fetch, close)pd.read_sql(query, conn)
: Query database and load results into a DataFramedf.to_sql('table', conn, ...)
: Write DataFrame to a database tablejoblib
: Simple single-machine parallelism (Parallel
, delayed
)dask
: Scalable library for parallel/distributed computing
venv
, conda
): Isolate project package dependencies, preventing conflicts between projects
requirements.txt
(pip) or environment.yml
(conda) to define and recreate these environments easilyFROM
, RUN
, COPY
, etc) to build the imageBasic workflow:
docker build -t myimage:latest .
(creates the image locally)docker run -p 8888:8888 -v $(pwd):/app myimage:latest
(starts the container)
-p
: Port mapping (host:container)-v
: Volume mounting (host:container) for data persistence/code access-it
: Interactive terminaldocker push
, docker pull
(via a registry like Docker Hub)FROM ubuntu:24.04
RUN apt-get update && \
apt-get install -y python3 python3-pip && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
RUN python3 --version
RUN pip3 --version
CMD ["python3"]
COPY . /app
WORKDIR /app
RUN pip3 install -r requirements.txt
CMD ["python3", "your_script.py"]
Example Dockerfile
A summary of the key skills and concepts from QTM350: