Introduction
I keep some notes here, mostly development related things, as well as "quick ref"-guides on Linux commands and similar things.
Note: This book contains public notes only. My private notes are kept elsewhere.
The source code from which this book is generated is available on github.com/christianfosli/notes.
Bash / Linux / GNU tools quick ref
Terminal Signals :stop_sign:
-
Exit
Ctrl-D -
Cancel (kill) app/job
Ctrl-C -
Suspend
Ctrl-Zsuspend (pause) an app/job (go back to bash)- Resume job
fg(list all withjobs)
- Resume job
Readline :ledger:
-
Go to beginning of line
Ctrl-a -
Go to end of line
Ctrl-e -
Delete line
Ctrl-x <Backspace> -
Move by words
Ctrl- <Arrow-Keys> -
Open command in $EDITOR, execute upon exit
Ctrl-x Ctrl-eorfc
Files and Directories :file_folder:
-
Copy file contents to clipboard (on WSL)
cat $file | clip.exe -
Copy file contents to clipboard (on Wayland)
cat $file | wl-copy -
Search command history:
<C-r> startOfCommand -
Search for "pattern" and print matching lines:
grep. Hint: ripgreprgis easier to use and super fast. -
Find files by filename:
find . -name Foo.txt.-
Find files case insensitive filename:
find . -iname "*foo*txt" -
Or use a fuzzy finder (fzf/skim/neovim telescope).
-
-
Create symlink
ln -s actual_file_path symlink_path -
Extract .tar.gz file
tar -xzf <filename(remember eXtract tZe File)
Networking :globe_with_meridians:
-
List ip-address
ip addr -
List ip addresses on same network:
ip neigh -
nslookup
-
SSH
ssh username@ip -p portnumber- Start ssh service to allow log-ins (fedora)
systemctl start sshd.service
- Start ssh service to allow log-ins (fedora)
-
Copy files between local computer and remote
scp $file username@ip:/home/$dirorscp username@ip:/home/$file $localdir
tmux :computer:
-
list sessions
tmux lsorCtrl-b s -
attach
tmux attach # -
rename window
Ctrl-b , -
new pane
Ctrl-b "orCtrl-b % -
break out pane to a new window
Ctrl-b ! -
toggle layouts
Ctrl-b <space> -
resize pane
Ctrl-b :resize-pane -{L|R|D|U} {cellSize}. Can also be done from the shell:$ tmux resize-pane -R 10 -
resize panes
Ctrl-b alt-arrows -
popup
tmux display-popup [-E 'python']
Gnome :framed_picture:
-
Activities overview:
<super> -
Move focus to menubar:
<super> <f10> -
Move focus between window and menubar:
<control> <alt> <tab> -
Switch between windows:
<super> <tab>- Then press
`or<down>to switch through windows within an application
- Then press
-
Switch between workspaces:
<super> <alt> <arrow> -
Snap window:
<super> <arrow-keys> -
Move window to another screen:
<shift> <super> <arrow-keys> -
Pop open window menu:
<alt> <space> -
Focus on active notification:
<super> n -
Show notification list:
<super> v -
Send notification from terminal:
$ notify-send 'Hello world' 'the command has finished' -
Lock screen:
<super> l -
Screenshot...:
<PrintScreen> -
Project external displays:
<super> P -
Toggle zoom:
<alt> <super> 8 -
Emoji picker:
<windows> <.> <keyword> <space> <space>- Note: Does not work in all applications. E.g. Currently doesn't work in Chrome.
alacritty :keyboard:
- Launch vi mode: Ctrl Shift Space
systemctl & UEFI/BIOS :control_knobs:
-
Boot into UEFI/BIOS:
sudo systemctl reboot --firmware-setup -
See boot order
sudo efibootmgr -
Boot next
sudo efibootmgr --bootnext XXXX
Configure systemd-resolved to not use azure private endpoints
-
Create file /etc/systemd/resolved.conf.d/az_blob_pub.conf with the following content
# Work around missconfigured peerings from on-prem networks to azure blob storage private endpoints # by forcing DNS to a public DNS server (in this case cloudflare DNS) [Resolve] DNS=1.1.1.1 2606:4700:4700::1111 Domains=~blob.core.windows.net
Good to know cURL options
-
Download to file using filename from URL:
-O|--remote-name -
Silent:
-s|--silent. Don't show the progress bar. -
Follow redirects:
-L|--location -
Retries:
--retry <n> -
Fail silently on HTTP errors / bad status codes:
-f|--fail -
Include response headers in output:
-i|--include -
Username/password:
-u username:pass -
Client certs:
--cert cert-w-key.pem:passwordor--cert cert.crt --key key.key -
Allow insecure TLS connections (i.e. untrusted certs):
-k|--insecure -
STDIN as body:
-d@-. E.g.cat f.json | curl -H "Content-Type: application/json" -d @- http://api -
json (curl >= 7.82):
jo name=christian tool=curl | curl --json @- http://api | jq -
Override dns resolve:
curl https://domain.example --connect-to domain.example:443:203.0.113.81:443
Docker quick ref :whale:
-
Most used commands:
docker ps,docker images,docker build,docker run -
Most used docker-run flags:
-itinteractive terminal,-ddetached (in the background) -
Detach from running container: Ctrl P Q
-
Remove all non-running images:
docker rmi $(docker ps -aq)ordocker image prune -a -
Check disk usage:
docker system df -
Exec as specific user:
docker exec -u root -it <containername> -
Run container with the same network namespace as another:
docker run -it --network container:<containername> alpine
.NET Quick-Ref
-
run xunit tests with output to console:
dotnet test --logger "console;verbosity=detailed" --filter <filterexpr><filterexpr>can be e.g. the test name, or with XUnit.Categories e.g.Feature=83922. But if we are interested in the output then it's best to run one test at a time, otherwise it's hard to find.
-
run fsharp fsx script
dotnet fsi <filename> -
open fsharp interpreter
dotnet fsi --readline
Fixes and work-arounds
-
Strings.PlatformNotSupported_DataSqlClienterror when running ef core database migrations on (some) linux platforms- Add
--runtime linux-x64to the cli command
- Add
-
Microsoft.Data.SqlClient.SqlExceptionwhen connecting to database over HTTPS on older versions of dotnet core with newer versions of OpenSSLMicrosoft.Data.SqlClient.SqlException (0x80131904): A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 35 - An internal exception was caught) ... ---> System.TypeInitializationException: The type initializer for 'SslInitializer' threw an exception. ---> Interop+Crypto+OpenSslCryptographicException: error:0E076071:configuration file routines:module_run:unknown module name- Set environment variable
OPENSSL_CONF=/dev/nullbefore/while running your command Source: https://stackoverflow.com/questions/73004195/phantomjs-wont-install-autoconfiguration-error
- Set environment variable
Git quick-ref :tanabata_tree:
Open help-page: git help command
-
Everyday work
-
Check what's up
git status -
See what happened
git log [--graph --date=human --stat])-
one-line commits:
git log [--graph] --oneline -
show the patch:
git log [--graph] -p
-
-
Add files to stage
git add filename- Stage part of file
git add -p filename
- Stage part of file
-
Unstage file
git restore --staged <filename> -
Check diff
git diff branch1 branch2orfile1 file2etc-
Check message and diff of commit:
git show <commit-hash>- Include commit (as well as author) date:
git show --format=fuller <commit-hash>
- Include commit (as well as author) date:
-
Check diff for a merge commit:
- Given this commit:
commit ccc333 Merge: aaa111 bbb222git diff aaa111...bbb222 -
Exclude specific file from diff:
git diff -- . ':!package-lock.json'orgit show HEAD -- . ':!Cargo.lock'
-
-
Commit stage to current branch
git commit-
Commit all tracked files with changes:
git commit -a -
Use interactive patch selection to decide what to commit:
git commit -p -
Show diff below the commit message:
git commit -v
-
-
Restore file to HEAD
git restore <filename> -
Restore file to branch
git restore -s <branchname> <filename>
-
-
Misc
-
Does origin/master have new commits? (commits not reachable from HEAD)
git fetch origin && git log ..origin/master -
Ignore future local changes to a tracked file (useful for config files...)
git update-index --skip-worktree <filename>- Undo with
git update-index --no-skip-worktree <filename>
- Undo with
-
Apply patch (3-way merge)
git show <sha1> | git apply -3
-
-
Branches
-
Show branches
git branchorgit branch -vvorgit branch -r -
Create branch
git branch <branch-name> -
Switch to branch
git switch <branch> -
Do both 2 above
git switch -c <branch name> -
Merge/rebase branch first checkout the to-branch then
git merge <from-branch>orgit rebase <from-branch> -
Delete branch
git branch -d <branch>force delete withgit branch -D <branch> -
Delete every branch except master
git branch | grep -v "master" | xargs git branch -D -
Reset branch to earlier commit / branch / tag
git reset --hard <commit> -
Clean up latest n commits (opens interactive rebase editor letting you squash, pick, fixup, reorder)
git rebase -i HEAD~n -
Rebase and update intermediate "feature branches"
git rebase --update-refs
-
-
Remotes
-
Fetch latest changes
git fetch <remote>- And remove remote remote tracking branches which have been deleted
git fetch -p <remote>(shows [gone] ongit branch -v)
- And remove remote remote tracking branches which have been deleted
-
Show remote info
git remote -vor more info withgit remote show <remote> -
Fetch and merge
git pull -
Push to remote
git push <remote> <branch> [--force-with-lease] -
Push and add upstream (tracking) reference
git push -u <remote> <branch> -
Delete remote branch
git push <remote> -d <branch> -
Update submodules
git submodule updateorgit submodule update --remote
-
-
Finding commits
-
Search by author:
git log --author <name> -
Search by commit message:
git log --grep <regexp> -
Search by patch text (i.e. diff content):
git log -G <regexp>
-
GitHub tips and tricks
- Clear cache, if using GitHub Actions cache (e.g. for docker build):
gh cache delete --all --repo {org}/{repo}
Notes about TLS, PKI, certs and keys.
Everything you should know about certificates and PKI but are too afraid to ask
Good read š by SmallStep
https://smallstep.com/blog/everything-pki/
Fun facts
PEM stands for Privacy Enhanced Email. It was originally developed to encrypt emails. It never cought on, though, and the related RFC's were eventually obsoleted by PGP and S/MIME.
Step CLI
Similar to openssl but with better UX.
https://github.com/smallstep/cli
ssh-rsa
-
It is now possible[1] to perform chosen-prefix attacks against the SHA-1 algorithm for less than USD$50K. For this reason, we will be disabling the "ssh-rsa" public key signature algorithm by default in a near-future release.
-
Solution: Switch SSH keys to Eliptic Curve ed25519
EC cryptography for dummies
https://blog.boot.dev/cryptography/elliptic-curve-cryptography/
Microsoft 365 related notes
MS Teams keyboard shortcuts
-
Focus on search field: Ctrl-E
-
Focus on search field for command: Ctrl-/
-
Switch chats: Alt-
-
Switch sidebar tabs: Ctrl-1/2/3/4.. (web Ctrl-Shift-1/2/3/4..)
-
Keyboard driven chat: Switch focus with
<up>and<down>, enter reaction menu with<enter>
Work-arounds / hacks
Misc
-
Update Microsoft Defender policies/definitions on Linux:
mdatp definitions update -
Check Microsoft Defender health:
mdatp health
Python Quick-Ref
Managing python versions, environments and dependencies
Use uv!
"uv-first" projects
-
Initialize new project
uv init {project_name} -
Initialize existing project and install deps
uv sync -
Install and update existing deps
uv sync --upgrade -
Add dep
uv add {dep}[version_constraint] -
Remove dep
uv remove {dep} -
Upgrade dep
uv lock --upgrade-package {dep}
uv-first scripts
uv add --script example.py pandas # Legger til kommentar pƄ toppen av filen
uv run example.py
Debugging and troubleshooting
-
Debugging pandas dataframes and series, plot pd.Series:
breakpoint() # Stop execution and enter debugger. Enter the remaining into debug console at the right time import matplotlib.pyplot as plt df.plot() plt.show() # plot appears
Convenient cli's
-
Generate a uuid:
python -m uuid -
Serve static files in current directory:
python -m http.server 8000
Logging in pytest output
pytest -o log_cli=true --log-level=DEBUG
or persistant in a config file, which by convention resides in the root directory of the repository
# pytest.ini
log_cli=true
log_level=DEBUG
# pyproject.toml
[tool.pytest.ini_options]
log_cli="true"
log_level="DEBUG"
Ruff
-
Format:
ruff format {file|dir} -
Lint:
ruff check [--fix] {file|dir} -
Organize imports:
ruff check --fix --select Ior add to pyproject.toml:[tool.ruff.lint] extend-select = ["I"] -
Example config:
[tool.ruff] line-length = 120 [tool.ruff.lint] extend-select = ["I"] [tool.ruff.lint.isort] known-first-party = ["myorg_*"]
BasedPyright
A fork of the Pyright LSP with various feature improvements, such as code action for missing imports!
Works nicely with terminal editors like Helix.
See https://docs.basedpyright.com/latest/
Interesting Python / JS Interop project
Vim favorite commands / built in stuff
-
CTRL-] or gd - Jump to definition
-
CTRL-O Jump back
-
CTRL-I Jump forward
-
K show definition of keyword
-
f {char} - go to first occurance of char
-
t {char} - go just before first occurance of char
Helix (move me somewhere?)
- Due to some intelligent(ish) workspace root detection looking for .git folder, make sure to open deno files from the correct folder.
Web related notes
Chromium features to follow :eyes:
-
Shared element transitions: Polished transitions/animations when navigating between pages in web applications.
-
Multi-Screen window placement: Allow web applications to offer compelling multi-screen experiences.
Chrome & Web news
-
https://web.dev
- Check https://web.dev/learn for tutorials :smile: e.g. https://web.dev/learn/pwa/ to learn about progressive web apps
"New" HTML elements
<dialog>mdn
WebAuthn
Web authentication using public key cryptography instead of passwords
FedCM
Federated credential management without needing third-party cookies.
Patterns
Check patterns.dev