From 6c6aa17115a3c6d9d382ded66c43dd5920c90598 Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Sat, 29 Apr 2023 11:35:15 +0200 Subject: [PATCH] chore: improved knowledge base conventions definition --- .vscode/settings.json | 5 ++++ knowledge base/README.md | 58 ++++++++++++++++++++++++++++++++++++--- knowledge base/clamav.md | 47 ++++++++++++++++--------------- knowledge base/ffmpeg.md | 9 +++--- knowledge base/gcloud.md | 8 +++--- knowledge base/git.md | 8 ++++-- knowledge base/keybase.md | 8 +++--- 7 files changed, 101 insertions(+), 42 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index d018741..0f5a680 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -17,6 +17,9 @@ "chattr", "chezmoi", "chsh", + "clamav", + "clamd", + "clamscan", "compsize", "cowsay", "cpulimit", @@ -35,6 +38,7 @@ "fdupes", "firewalld", "flatpak", + "freshclam", "gcloud", "getfacl", "gettext", @@ -60,6 +64,7 @@ "mpiexec", "netcat", "nmap", + "nproc", "nvme", "ocsp", "openpgp", diff --git a/knowledge base/README.md b/knowledge base/README.md index 8acf8e0..96eb3a9 100644 --- a/knowledge base/README.md +++ b/knowledge base/README.md @@ -1,15 +1,65 @@ -# Knwoledge base +# Knowledge base This is the collection of all notes, reminders and whatnot I gathered during the years. ## Conventions -- Use `sh` as document language instead of `shell` when writing shell snippets in code blocks: +- Prefer keeping an 80 characters width limit in code blocks.
+ This improves readability on most locations. + +- Always use an highlighting annotation when writing code blocks (default to `txt`). + +- Use `sh` as highlighting annotation instead of `shell` when writing shell snippets in code blocks.
+ The local renderer just displays them better like this. ```diff - ```shell + ```sh - #!/usr/bin/env zsh + #!/usr/bin/env zsh ``` - The local renderer just displays them better like this. +- Group related options in commands where possible.
+ It gives enhanced clarity and a sense of continuation. + + ```diff + az deployment group validate \ + - -f 'template.bicep' -g 'resource_group_name' -p 'parameter1=value' parameter2="value" -n 'deployment_group_name' + + -n 'deployment_group_name' -g 'resource_group_name' \ + + -f 'template.bicep' -p 'parameter1=value' parameter2="value" + ``` + +- Split piped or concatenated commands into multiple lines.
+ It emphasizes they are indeed multiple commands. + + ```diff + - find . -type 'f' -o -type 'l' | awk 'BEGIN {FS="/"; OFS="|"} {print $NF,$0}' | sort --field-separator '|' --numeric-sort | cut -d '|' -f2 + + find . -type 'f' -o -type 'l' \ + + | awk 'BEGIN {FS="/"; OFS="|"} {print $NF,$0}' \ + + | sort --field-separator '|' --numeric-sort \ + + | cut -d '|' -f2 + ``` + +- Indent the arguments of a command when splitting it into multiple lines.
+ It makes sooo much easier to have clear what are arguments and what are different commands altogether. + + ```diff + dnf -y install --setopt='install_weak_deps=False' \ + - 'Downloads/tito-0.6.2-1.fc22.noarch.rpm' + + 'Downloads/tito-0.6.2-1.fc22.noarch.rpm' + ``` + +- Do **not** indent pipes or concatenations when splitting commands into multiple lines.
+ It makes clear those are different commands. + + ```diff + jq --sort-keys '.' datapipeline.json > /tmp/sorted.json \ + - && jq '.objects = [(.objects[] as $in | {type,name,id} + $in | with_entries(select(.value != null)))]' \ + - /tmp/sorted.json > /tmp/reordered.json \ + - && mv /tmp/reordered.json datapipeline.json + + && jq '.objects = [( + + .objects[] as $in + + | {type,name,id} + $in + + | with_entries(select(.value != null)) + + )]' /tmp/sorted.json > /tmp/reordered.json \ + + && mv /tmp/reordered.json datapipeline.json + ``` diff --git a/knowledge base/clamav.md b/knowledge base/clamav.md index 1bd1a04..422cbe1 100644 --- a/knowledge base/clamav.md +++ b/knowledge base/clamav.md @@ -3,35 +3,38 @@ ## TL;DR ```sh -# manually update the virus definitions -# do it once **before** starting a scan or the daemon -# the definitions updater deamon must be stopped to avoid complaints from it -sudo systemctl stop clamav-freshclam \ - && sudo freshclam \ - && sudo systemctl enable --now clamav-freshclam +# Manually update the virus definitions. +# Do this once **before** starting a scan or the daemon. +# The definitions updater daemon **must be stopped** to avoid its complaints. +sudo systemctl stop 'clamav-freshclam' \ +&& sudo 'freshclam' \ +&& sudo systemctl enable --now 'clamav-freshclam' -# scan a file or directory -clamscan path/to/file -clamscan --recursive path/to/dir +# scan a file or directory. +clamscan 'path/to/file' +clamscan --recursive 'path/to/dir' -# only return specific files -clamscan --infected /home/ -clamscan --suppress-ok-results Downloads/ +# only return specific files. +clamscan --infected '/home/' +clamscan --suppress-ok-results 'Downloads/' -# save results to file -clamscan --bell -i -r /home -l output.txt +# save results to file. +clamscan --bell -i -r '/home' -l 'output.txt' -# scan files in a list -clamscan -i -f /tmp/scan.list +# scan files in a list. +clamscan -i -f '/tmp/scan.list' -# remove infected files -clamscan -r --remove /home/user -clamscan -r -i --move=/home/user/infected /home/ +# remove infected files. +clamscan -r --remove '/home/user' +clamscan -r -i --move='/home/user/infected' '/home/' -# limit cpu usage -nice -n 15 clamscan && clamscan --bell -i -r /home +# limit cpu usage. +nice -n 15 clamscan \ +&& clamscan --bell -i -r '/home' -# use multiple threads +# use multiple threads. +find . -type f -printf "'%p' " | xargs -P "$(nproc)" -n 1 clamscan +find . -type f | parallel --group --jobs 0 -d '\n' clamscan {} ``` ## Gotchas diff --git a/knowledge base/ffmpeg.md b/knowledge base/ffmpeg.md index e6df2ef..1eacb53 100644 --- a/knowledge base/ffmpeg.md +++ b/knowledge base/ffmpeg.md @@ -4,9 +4,8 @@ ```sh # Convert a webm file to GIF. -ffmpeg -y -i rec.webm -vf palettegen palette.png \ - && ffmpeg -y -i rec.webm -i palette.png \ - -filter_complex paletteuse -r 10 out.gif +ffmpeg -y -i 'rec.webm' -vf 'palettegen' 'palette.png' +ffmpeg -y -i 'rec.webm' -i 'palette.png' -filter_complex 'paletteuse' -r 10 'out.gif' ``` ## Format conversion @@ -14,8 +13,8 @@ ffmpeg -y -i rec.webm -vf palettegen palette.png \ ### Webm to GIF ```sh -ffmpeg -y -i rec.webm -vf palettegen palette.png -ffmpeg -y -i rec.webm -i palette.png -filter_complex paletteuse -r 10 out.gif +ffmpeg -y -i 'rec.webm' -vf 'palettegen' 'palette.png' +ffmpeg -y -i 'rec.webm' -i 'palette.png' -filter_complex 'paletteuse' -r 10 'out.gif' ``` Here `rec.webm` is the recorded video. diff --git a/knowledge base/gcloud.md b/knowledge base/gcloud.md index ad24287..4c44724 100644 --- a/knowledge base/gcloud.md +++ b/knowledge base/gcloud.md @@ -1,8 +1,8 @@ # Google cloud platform CLI 1. [TL;DR](#tldr) -2. [Further readings](#further-readings) -3. [Sources](#sources) +1. [Further readings](#further-readings) +1. [Sources](#sources) ## TL;DR @@ -56,8 +56,8 @@ gcloud compute operations list \ # Use a specific service account for an operation. # The service account must have been activated. gcloud config set account serviceaccount@gcpproject.iam.gserviceaccount.com \ - && gcloud auth application-default login --no-launch-browser \ - && gcloud compute instances list +&& gcloud auth application-default login --no-launch-browser \ +&& gcloud compute instances list # Logout. gcloud auth revoke --all diff --git a/knowledge base/git.md b/knowledge base/git.md index 00a4ba3..0d4c901 100644 --- a/knowledge base/git.md +++ b/knowledge base/git.md @@ -193,7 +193,7 @@ git format-patch 'HEAD~2' --stdout > 'single/file.patch' # Create a full patch of the unstaged changes. git add . && git commit -m 'uncommitted' \ - && git format-patch 'HEAD~1' && git reset 'HEAD~1' +&& git format-patch 'HEAD~1' && git reset 'HEAD~1' # Apply a patch to the current index. git apply 'file.patch' @@ -272,7 +272,8 @@ git remote prune 'branch_name' # Delete branches which have been merged or are otherwise absent from a remote. git branch --merged | grep -vE '(^\*|master|main|dev)' | xargs git branch -d git fetch -p \ - && awk '/origin/&&/gone/{print $1}' <(git branch -vv) | xargs git branch -d +&& awk '/origin/&&/gone/{print $1}' <(git branch -vv) \ + | xargs git branch -d # List all tags. git tag @@ -625,7 +626,8 @@ Command source [here][prune local branches that do not exist on remote anymore]. ```sh # Branches merged on the remote are tagged as 'gone' in `git branch -vv`'s output. git fetch -p \ - && awk '/origin/&&/gone/{print $1}' <(git branch -vv) | xargs git branch -d +&& awk '/origin/&&/gone/{print $1}' <(git branch -vv) \ + | xargs git branch -d # Retain the current, 'master', 'main' and 'dev*' branches in all cases. git branch --merged | grep -vE '(^\*|master|main|dev)' | xargs git branch -d diff --git a/knowledge base/keybase.md b/knowledge base/keybase.md index 998f510..58f63f0 100644 --- a/knowledge base/keybase.md +++ b/knowledge base/keybase.md @@ -29,13 +29,13 @@ keybase git lfs-config # Clone a repository with LFS-enabled files. git clone --no-checkout 'keybase://private/user/repo' \ - && cd 'repo' && keybase git lfs-config && cd - \ - && git -C 'repo' checkout -f HEAD +&& cd 'repo' && keybase git lfs-config && cd - \ +&& git -C 'repo' checkout -f HEAD # Import an existing repository in Keybase keybase git create 'repo' \ - && git clone --mirror 'https://github.com/user/repo' '/tmp/repo.git' \ - && git -C '/tmp/repo.git' push --mirror 'keybase://private/user/repo' +&& git clone --mirror 'https://github.com/user/repo' '/tmp/repo.git' \ +&& git -C '/tmp/repo.git' push --mirror 'keybase://private/user/repo' # Run as root. KEYBASE_ALLOW_ROOT='1' keybase oneshot