chore: improved knowledge base conventions definition

This commit is contained in:
Michele Cereda
2023-04-29 11:35:15 +02:00
parent e5f0e606e1
commit 6c6aa17115
7 changed files with 101 additions and 42 deletions

View File

@@ -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",

View File

@@ -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.<br/>
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.<br/>
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.<br/>
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.<br/>
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.<br/>
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.<br/>
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
```

View File

@@ -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

View File

@@ -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.

View File

@@ -1,8 +1,8 @@
# Google cloud platform CLI <!-- omit in toc -->
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

View File

@@ -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

View File

@@ -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