Update my notebook as of 2021-06-06

This commit is contained in:
Gabriel Arazas 2021-06-06 14:09:23 +08:00
parent 801d74e9ad
commit ad8f37c356
9 changed files with 211 additions and 19 deletions

View File

@ -1,12 +0,0 @@
:PROPERTIES:
:ID: 15d394fc-2104-4193-af31-f16da1661758
:END:
#+title: Create package definitions for missing dependencies first before the package itself
#+date: "2020-09-15 03:08:22 +08:00"
#+date_modified: "2021-05-04 20:52:08 +08:00"
#+language: en
Certain ecosystems like in [[id:3b3fdcbf-eb40-4c89-81f3-9d937a0be53c][Nix package manager]] with [[https://github.com/NixOS/nixpkgs][nixpkgs]] or [[id:be917383-84c4-4bf5-9ca0-b04bfb778f4f][GNU Guix]] within their own packages follow a standard (officially) [fn:: If not, you can freely ~make build~ all you want.] about making sure all dependencies are present first before building the package.
Smaller libraries often go through this and so, you need to package the dependencies first.
It also helps with creating a global definition for other packages that requires those small libraries.

View File

@ -0,0 +1,8 @@
#/usr/bin/env bash
if $# -eq 1; then echo "No directories and files to be saved." && exit 1; fi
locations=$@
borg create --verbose --stats --compression lz4 --exclude '**/.node_modules' ::{hostname}-{now:%F-%H-%M-%S-%z} ${locations[@]}
borg check --verbose --verify-data
borg prune --verbose --keep-daily 7 --keep-hourly 7 --keep-weekly 6 --keep-monthly 6

View File

@ -3,8 +3,9 @@
:END:
#+title: BorgBackup
#+date: "2021-05-30 21:40:24 +08:00"
#+date_modified: "2021-06-04 21:47:36 +08:00"
#+date_modified: "2021-06-05 09:11:53 +08:00"
#+language: en
#+property: header_args :eval no
#+property: header_args:bash :results silent :exports code
@ -63,7 +64,7 @@ ${REPOSITORY_URL}::${ARCHIVE_NAME}
You can also refer to a name dynamically with placeholders.
#+begin_src
/home/foo-dogsquared/backup::{hostname}-{user}-{now}
/home/{user}/backup::{hostname}-{user}-{now}
#+end_src
For more information, you can see the related section for Borg placeholders.
@ -125,8 +126,8 @@ borg extract --verbose --progress ${REPO_PATH}::{hostname}-{now:%F-%T-%z} ~/Docu
Better be safe than sorry.
Here's the safe backup in all of its glory in Bash.
#+begin_src bash :file safe-borg-backup :shebang '/usr/bin/env bash'
if $# -eq 0; then echo "No directories and files to be saved." && exit 1; fi
#+begin_src bash :tangle (my/concat-assets-folder "safe-borg-backup") :shebang "#/usr/bin/env bash"
if $# -eq 1; then echo "No directories and files to be saved." && exit 1; fi
locations=$@
@ -135,6 +136,8 @@ borg check --verbose --verify-data
borg prune --verbose --keep-daily 7 --keep-hourly 7 --keep-weekly 6 --keep-monthly 6
#+end_src
#+results:
Since the script only lets you enter arguments used for saving into the archive, you have to use environment variables.
#+begin_src shell

View File

@ -1,6 +1,9 @@
:PROPERTIES:
:ID: c05e1aa9-0619-4617-abb6-870fceca3430
:END:
#+title: Niv
#+date: "2021-05-09 17:25:04 +08:00"
#+date_modified: "2021-05-09 17:25:23 +08:00"
#+date_modified: "2021-06-05 12:36:39 +08:00"
#+language: en

64
structured/editor.vim.org Normal file
View File

@ -0,0 +1,64 @@
#+title: Vim
#+date: "2021-06-06 05:12:20 +08:00"
#+date_modified: "2021-06-06 14:07:26 +08:00"
#+language: en
Every sysadmin's favorite default text editor.
Is being familiar to Vim a path to productivity?
No.
But being good at it can make for a difference in the day-to-day life of a sysadmin for there are advanced capabilities of this editor.
* The keybindings of Vim
One of the things that make Vim popular is the keybindings.
| Keybinding | Description |
|------------+--------------------------------------------|
| =[m= | Go to the previous method. |
| =g~w= | Toggle letter casing. |
| =2guW= | Convert two words into lowercase. |
| =10d)= | Delete 10 sentences. |
| =39zz= | Place the cursor in the middle in line 39. |
| =3d10w= | Delete 10 words and repeat 3 times. |
Most of the time, Vim keybindings is made of mainly two things:
- *The operators denoting an action.*
- *The motions describing the scope of the action.*
There's a certain pattern to it when you use it, too.
#+begin_src
[count][operator][motion]
#+end_src
* Tips and tricks
- =:h= is the help system of Vim.
It contains all of the documentation of the editor and the installed plugins.
I recommend to start with the default help page (e.g., =:h=).
+ You can get the meaning of the keybinding with the help section — e.g., ~:h gg~, ~:h G~.
- Vim has fine-grained control motions.
+ =(= and =)= for sentences.
+ ={= and =}= for paragraphs.
+ =[= and =]= for sections.
- There are many advanced navigation features in Vim.
+ =gf= will go to the file at point.
+ =K= goes to the definition of the keyword at point.
+ =Ctrl+O= will jump back at a previous jump point.
+ =gd= go the local definition of the keyword at point.
+ =H=, =M=, and =L= places the cursor in higher, middle, and lower part in the current screen, respectively.
+ =zt=, =zz=, and =zb= displays the current line in the top, middle, and bottom part of the screen, respectively.

View File

@ -1,11 +1,12 @@
#+title: Oil shell
#+date: "2021-05-09 16:40:50 +08:00"
#+date_modified: "2021-06-04 21:55:38 +08:00"
#+date_modified: "2021-06-05 16:36:01 +08:00"
#+language: en
#+property: header-args:oil :eval no
For future references, this note mainly notes Oil v0.8.11 and later versions.
Also, we'll be comparing to Bash shell (src_bash[:eval yes :results output]{bash --version}) as it is the most popular shell on the Unix world.
@ -67,6 +68,33 @@ for i in @keywords { echo "keyword: $i" }
#+end_src
** Strings
While strings are similar to Bash strings [fn:: Really more like Python strings.], there are subtle differences.
Most notably, Bash splits the string when trying to do something.
#+begin_src bash
d='echo 3'
e='echo "The quick brown fox jumps over the lazy dog."'
parallel -- $d $e
#+end_src
It should throw an error because =parallel= interprets it as if it has 4 arguments due to the splitting — i.e., ~parallel -- echo 3 echo "The quick brown fox jumps over the lazy dog."~.
The solution here is to quote the variables in evaluation (e.g., ~parallel -- "$d" "$e"~).
Compare that to Oil...
#+begin_src oil
var d = 'echo 3'
var e = 'echo "The quick brown fox jumps over the lazy dog."'
parallel -- $d $e
#+end_src
If you want splitting, you could use =split= Oil function — e.g., ~@split(array_var)~.
** Arrays
Arrays are mostly similar to Bash arrays except you have more options.
@ -94,6 +122,24 @@ _ a.append("biz")
#+end_src
** Conditionals
#+begin_src oil
# Ternary conditionals
echo $['dogs' if dogs == 'cute' else 'cats']
# If-else statements
if (4 == 5) {
echo "Alright, this is true."
} elif (1 > 5) {
echo "Another condition?"
} else {
echo "It seems you got me."
}
#+end_src
* Expression and command mode
@ -115,3 +161,13 @@ _ a.append("biz")
+ the === command where it will print the results — e.g., ~= 53~
+ you can interpolate expression mode expressions with =$[]= — e.g., ~echo $[4 + 43 + a]~, ~echo $[len(ARGV)]~
+ in =if= statements — e.g., ~if (true) { echo "WHOA" }~
* Tips and tricks
- Oil seems to evaluate in applicative order, evaluating only when the conditions passed — e.g., ~echo $['' + null if null else 'EEEEHHH']~ should print =EEEEHHH=.
+ Just like most modern mainstream languages... nice.
- Two operands of different types are considered unequal — e.g., ~'4' == 4~.
+ You can use Python-like type conversions like =Int=, =Bool=, and =Str= — e.g., ~Int('4') == 4~.

View File

@ -0,0 +1,15 @@
#+title: Summary of a Linux installation
#+date: "2021-06-05 22:30:48 +08:00"
#+date_modified: "2021-06-05 22:32:56 +08:00"
#+language: en
# TODO: Improve note
- initial setup
- partitioning
- installation of the operating system
+ base package set
+ feature-specific packages
+ boot loader
+ network manager
+ init system

55
structured/tools.nix.org Normal file
View File

@ -0,0 +1,55 @@
:PROPERTIES:
:ID: 892676b3-76cb-4cd4-9689-910c1fe6587a
:END:
#+title: The basics of Nix package manager
#+date: "2021-06-05 12:34:49 +08:00"
#+date_modified: "2021-06-05 13:32:22 +08:00"
#+language: en
[[id:3b3fdcbf-eb40-4c89-81f3-9d937a0be53c][Nix package manager]] is a great tool for reproducibility as you can easily set up your environment.
Taking it up to the next level with NixOS, your whole installation.
* Ecosystem
- Nix has tools to make setting up environments easier with direnv, lorri, and [[id:c05e1aa9-0619-4617-abb6-870fceca3430][Niv]]
You can create a [[https://nix.dev/tutorials/ad-hoc-developer-environments#reproducible-executables][reproducible executable]] that only requires Nix.
#+begin_src bash
#!/usr/bin/env nix-shell
#! nix-shell --pure -i bash -p curl jq fzf findutils
# A quick command line interface for creating a gitignore with the API from https://gitignore.io.
# This script comes with a simple caching to avoid creating too much requests.
set -eo pipefail
CACHE_FILE="${XDG_CACHE_DIR:-$HOME/.cache}/gitignore-io.langs.json"
# Check if the language list is downloaded for the last hour (3600 seconds).
if [ ! -e $CACHE_FILE ] || test $(expr $(date "+%s") - $(date -r $CACHE_FILE "+%s")) -gt 3600
then
ping "gitignore.io" --count 4 && curl --silent --location --output $CACHE_FILE "https://gitignore.io/api/list?format=json"
fi
KEYS=$(jq 'keys | .[] | @text' --raw-output $CACHE_FILE | fzf --multi | while read lang; do echo " .[\"$lang\"].contents"; done | paste -s -d ',')
jq "$KEYS" --raw-output $CACHE_FILE
#+end_src
* Components of the package manager
Holistically, Nix is made up of at least four components: the store, the language, the derivations, and the sandbox.
- The store is a immutable centralized location where all of the outputs are placed.
- The derivations are essentially build instructions.
- The language (also called as Nix but we'll refer to it as Nixlang) is a domain-specific language for creating derivations.
- The build process can be locked in a sandbox, improving the reproducibility of a setup and lowering the attack surface for a malicious package.