- π File & Directory Management
- π File Viewing & Editing
- π Search & Navigation
- π§° System Utilities
- π¦ Package Management (APT)
- π Python & pyenv
- π SSH & Remote Access
- π‘ FTP & File Transfer
- π§ Shortcuts
- πΏ Git Essentials
- π§Ή Pre-commits
- π NumPy Docstrings
- π Generating Documentation
- π½οΈ Reveal presentations
| Command | Description |
|---|---|
| ls | List files in current directory |
| ls -la | List all files with details |
| cd folder_name | Change directory |
| cd | Go to home directory |
| cd .. | Go up one directory |
| cd - | Go to previous directory |
| mkdir folder_name | Create a new folder |
| rm file | Delete file |
| rm -rf folder | Force delete folder and contents |
| cp source dest/ | Copy file/folder |
| mv old new | Move or rename file/folder |
| touch file.txt | Create empty file |
| Command | Description |
|---|---|
| cat file.txt | Show file contents |
| less file.txt | Scrollable view of file |
| nano file.txt | Edit file in nano editor |
| code . | Open folder in VS Code (if installed) |
| Command | Description |
|---|---|
| find . -name '*.py' | Find all .py files |
| grep "pattern" file.txt | Search for text in a file |
| grep -r "text" folder/ | Recursive search in folder |
| pwd | Show current directory |
| history | View command history |
| Command | Description |
|---|---|
| whoami | Show current user |
| df -h | Show disk usage |
| free -h | Show memory usage |
| top / htop | Process monitor (install htop) |
| uptime | System uptime |
| Command | Description |
|---|---|
| sudo apt update | Refresh package index |
| sudo apt upgrade | Upgrade installed packages |
| sudo apt install pkgname | Install package |
| sudo apt remove pkgname | Remove package |
| Command | Description |
|---|---|
| python3 --version | Show system Python version |
| pyenv install 3.11.13 | Install specific Python version |
| pyenv global 3.11.13 | Set global Python version |
| pyenv local 3.11.13 | Set version only for current folder |
| pyenv versions | List installed versions |
| pyenv which python | Show path to Python binary |
| poetry init | Create new Poetry project |
| poetry env use $(pyenv which python) | Link Poetry to pyenv Python |
| poetry env list | Lists all exiting environments |
| poetry env remove | Removes poetry environment |
| poetry add | Add dependency |
| poetry install | Install all libraries in toml |
| poetry shell | Activate project virtual environment |
| Command | Description |
|---|---|
| ssh user@host | Connect to remote machine |
| ssh -i ~/.ssh/id_rsa user@host | Use specific SSH key |
| ssh-keygen -t ed25519 | Generate new SSH key |
| cat ~/.ssh/id_ed25519.pub | Show public key to add to GitHub/remote |
| scp file user@host:/remote/path | Copy file to remote server |
| scp user@host:/remote/file ./local/ | Copy file from remote server |
- On local PC, generate new SSH key
ssh-keygen -t ed25519 -C "your_email@example.com"Press enter to accept defaults.
If you are on Windows, your key is in C:/Users/User/.ssh
- Copy key to remote computer
ssh-copy-id username@host_nameItβll prompt for PC2 password once. After that, you're in passwordlessly.
- SSH like usually
ssh username@host_nameIt shouldn't ask you for a password.
- On local PC, generate new SSH key
ssh-keygen -t ed25519 -C "your_email@example.com"Press enter to accept defaults.
If you are on Windows, your key is in C:/Users/User/.ssh
- Open the public key (
.pub) and copy its contents - Got to GitHub
$\rightarrow$ Settings$\rightarrow$ SSH and GPG keys$\rightarrow$ Add new key - Type a title (something to mark the specific computer) and paste in the key you copied
All set, now git remote should allow you to connect to your GitHub repos.
You can use the same SSH key for all your remote connections, but it is reccommended to set up different keys for each connection for security.
- Generate keys for each purpose, ie.
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_github -C "your_email@example.com"
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_remote1 -C "remote1"
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_remote2 -C "remote2"-
Add GitHub public key to GitHub (instructions)
-
Add each remote key's
.pubto the respective PC usingssh-copy-id
ssh-copy-id -i ~/.ssh/id_ed25519_remote1.pub username@remote1_ip
ssh-copy-id -i ~/.ssh/id_ed25519_remote2.pub username@remote2_ip- Create (or edit) your
.ssh-configfile as follows:
# GitHub
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_github
IdentitiesOnly yes
# Remote 1
Host remote1
HostName remote1_ip
User username
IdentityFile ~/.ssh/id_ed25519_remote1
IdentitiesOnly yes
# Remote 2
Host remote2
HostName remote2_ip
User username
IdentityFile ~/.ssh/id_ed25519_remote2
IdentitiesOnly yesNow you can SSH all you want.
| Command | Description |
|---|---|
| ftp host | Connect to an FTP server |
| sftp user@host | Connect securely via SFTP |
| scp file user@host:/path | Copy file to remote server |
| scp user@host:/file ./ | Copy file from remote server |
| rsync -avz file user@host:/path | Sync file/directory over SSH |
| rsync -avz user@host:/path ./ | Download file/directory via rsync |
| mput *.txt | Upload multiple files in FTP |
| mget *.txt | Download multiple files in FTP |
| put file.txt | Upload file in FTP |
| get file.txt | Download file in FTP |
| bye | Exit FTP session |
| Command | Description |
|---|---|
| Ctrl + C | Cancel current command |
| Ctrl + D | Exit terminal or virtual env |
| Ctrl + L | Clear terminal screen |
| β / β | Navigate command history |
| Tab | Autocomplete files or commands (use this like you life depends on it!) |
| !! | Repeat last command |
| Ctrl+ | Move by word instead of character |
| Command | Description |
|---|---|
| git init | Initialize a new Git repository |
| git config --global user.name/email | Set global Git username/email |
| git clone | Clone a remote repository |
| git status | Check status of working directory |
| git add | Stage changes for commit |
| git add . | Stage all changes |
| git diff | Shows unstaged changes |
| git diff --staged | Shows staged changes |
| git diff HEAD | Shows changes since last commit |
| git diff commit1 commit2 | Shows changes between commits |
| git diff branch1 branch2 | Shows changes between branches |
| git commit -m 'msg' | Commit staged changes with message |
| git commit --amend | Edit and replace the most recent commit. |
| git log | View commit history |
| git branch | List branches |
| git checkout | Switch to branch |
| git checkout -b | Create and switch to new branch |
| git merge | Merge branch into current |
| git pull | Fetch and merge from remote |
| git push | Push local commits to remote |
| git remote -v | List remote connections |
| git restore | Restore a file to its last commited state |
| git reset --soft HEAD~1 | Undo the last commit, keep changes staged |
| git stash | Temporarily save uncommited changes |
| git stash pop | Apply and remove the most recent stash |
There are 2 ways to set up a GitHub repo
- Create a repo on GitHub and clone it locally
- Create a repo locally and push it on GitHub
- Go to GitHub and create a repo. Name it and create a README.md. Oprionally select a template for the .gitignore, licence and description.
- Once the the repo is created, go to Code
$\rightarrow$ SSH and copy the repo SSH link. - On your local PC go to the folder you want to clone the repo in and open cmd/bash.
4.
git clone link-you-copied
Your repo is cloned and ready for commits.
Let's assume you have already created a repo, even made some commits already and want to upload to GitHub.
- Go to GitHub and create a repo. Name it the same as your local repo and do not create a README.md (you already have one locally). You want your repo to be completely empty.
- Once the the repo is created, go to Code
$\rightarrow$ SSH and copy the repo SSH link. - Locally, on your cmd/bash do:
git remote add origin link-you-copied
git branch -M main
git push -u origin mainYour commits should be pushed to GitHub and your local repo is connected to the GitHub repo.
- Install GitHub CLI.
- Connect it to you GitHub with
gh auth loginand follow the promts. - Create you local repo with
gitas usual and do the 1st commit. gh repo create REPO_NAME --public --source=. --pushto create a new GitHub repo and push your local repo.
Pre-commits are scripts that run automatically before a commit is made. These can be used to ensure code quality by running linters, formatters, and other checks on the codebase.
poetry add pre-commit
pre-commit installThis adds the .pre-commit-config.yaml file, where you define the hooks you want to run.
Here's an example of a .pre-commit-config.yaml file:
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- repo: https://github.com/psf/black
rev: 21.12b0
hooks:
- id: black- Stage files you want to commit.
- Run all hooks against all files:
pre-commit run --all-files - Run hooks only on changed files:
pre-commit run - Update pre-commit hooks:
pre-commit autoupdate - If you run git commit with pre-commits and files are modified by hooks, commit will be
aborted. You need to:
- Stage them again
- Commit them
Analyze the code for syntax, style and potential bugs. Catch issues like:
- Unused variables
- Wrong import order
- Missing docstrings
Automatically reformat code to follow a consistent style.
- Indentation
- Quote style
- Line breaks
- Comma placements
Linters and formatters get their config from pyproject.toml
[tool.ruff]
exclude = ["docs"]
line-length = 88
target-version = "py311"
[tool.ruff.lint]
ignore = [
# pylint
# No pylints
# ruff
"RUF001",
# flake8-bandit
"S101",
...
"ISC001",
"N806",
"N803",
"SLF001"
]
select = ["ALL"]
[tool.ruff.lint.flake8-quotes]
inline-quotes = "double"
[tool.ruff.lint.pydocstyle]
convention = "numpy"NumPy docstrings follow a specific format to ensure consistency and clarity. Here's a basic template for writing NumPy-style docstrings:
def example_function(param1, param2):
"""
Brief summary of the function.
Extended description of the function, which can cover
multiple lines and provide more detailed information.
Parameters
----------
param1 : int
Description of the first parameter.
param2 : str
Description of the second parameter.
Returns
-------
bool
Description of the return value.
Raises
------
ValueError
If `param1` is not a positive integer.
See Also
--------
related_function : Description of related function.
Notes
-----
Additional notes about the function, its usage, or implementation details.
Examples
--------
>>> example_function(3, 'test')
True
"""
if param1 <= 0:
raise ValueError("param1 must be a positive integer")
# Example function logic
return True- Summary: A one-line summary that starts with a capital letter and ends with a period.
- Parameters: A list of parameters with types and descriptions.
- Returns: Description of the return value, including type information.
- Raises: Any exceptions that the function may raise and the conditions under which they occur.
- See Also: References to related functions or methods within the module.
- Notes: Additional information about the function, which may include implementation details.
- Examples: Usage examples with the expected output, helpful for understanding function behavior.
Assuming you already have numpy docstrings in your code.
- Add necessary packages
poetry add --group docs numpydoc sphinx sphinx-rtd-theme sphinx-math-dollar myst-parser- numpydoc: Parses NumPy-style docstrings for Sphinx.
- sphinx: Turns reStructuredText or Markdown + docstrings into HTML, LaTeX, PDF, etc.
- sphinx-math-dollar: Allows you to write math equations with LaTeX dollar signs (
$...$for inline,$$...$$for block). - sphinx-rtd-theme: The ReadTheDocs theme
- myst-parser: Enables writing docs in Markdown
.mdinstead of.rst
- Set up sphinx in the docs folder of your repo
poetry run sphinx-quickstart docsFollow prompts on the terminal.
- Configure conf.py For example
# -- General configuration ---------------------------------------------------
extensions = [
"sphinx.ext.autosummary",
"sphinx.ext.autodoc",
"numpydoc",
"sphinx_math_dollar",
"sphinx.ext.mathjax",
"sphinx_rtd_theme",
"myst_parser", # enables Markdown support via MyST
]
templates_path = ["_templates"]
exclude_patterns = []
autosummary_generate = True
numpydoc_class_members_toctree = False
# -- Options for HTML output -------------------------------------------------
html_theme = "sphinx_rtd_theme"
# -- Options for napoleon extension ------------------------------------------
napoleon_google_docstring = False
napoleon_numpy_docstring = True
- Autogenerate
.rstfiles for your code
sphinx-apidoc -o docs/source your_module- Include modules into
index.rstInclude something like:
.. toctree::
:maxdepth: 2
:caption: API Reference
your_module # don't forget the indent- π Build your documentation
sphinx-build -b html docs/source docs/buildGet template from githug aramp
Create local server with npm slides.md
| Command | Description |
|---|---|
--- |
Create new slide to the right |
-- |
Create new slide downwards |
To deploy changes online:
- Push to GitHub
- On the GitHub repo go to Settings
$\rightarrow$ Pages - Source:
Deploy from a branch - Branch:
main - Folder:
/root - Click Save