From 7e28ba2efdc1eab4fde900a7cb804f4f4559d0ff Mon Sep 17 00:00:00 2001 From: Joshua Potter Date: Fri, 2 Feb 2024 11:41:17 +0000 Subject: [PATCH] Notes for 2024-02-01 (#1) Database system concepts and Nix's `callPackage`. Reviewed-on: https://git.jrpotter.com/r/notebook/pulls/1 Co-authored-by: Joshua Potter Co-committed-by: Joshua Potter --- .../plugins/obsidian-to-anki-plugin/data.json | 15 ++- notes/bash/quoting.md | 47 +++++++ notes/bash/robustness.md | 10 +- notes/bash/shebang.md | 9 +- notes/gawk.md | 115 ++++++++++++++++- notes/journal/2024-02-01.md | 18 +++ notes/nix/callPackage.md | 116 ++++++++++++++++++ notes/nix/index.md | 3 + notes/posix/signals.md | 35 +++++- 9 files changed, 351 insertions(+), 17 deletions(-) create mode 100644 notes/bash/quoting.md create mode 100644 notes/journal/2024-02-01.md create mode 100644 notes/nix/callPackage.md create mode 100644 notes/nix/index.md diff --git a/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json b/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json index c1a444c..5cbd355 100644 --- a/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json +++ b/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json @@ -60,14 +60,19 @@ "Linux/Signals.md": "f58f1a36a9fe53928fdc3dc02fc4c3e3", "linux/index.md": "6e50c924ee9e09294fd3b907fbdeaf0f", "linux/signals.md": "e9ab74723981ebc232189c84d3b0da74", - "templates/daily.md": "0f22c7ef0b0f35efada88d61c95e9815", + "templates/daily.md": "7866014e730e85683155207a02e367d8", "daily/2024-01-31.md": "72e343cef8d56e169cac7b360a88fcf0", "posix/index.md": "f7b1ae55f8f5e8f50f89738b1aca9111", - "posix/signals.md": "26161c6a79a0c413032c6c17e460412c", - "gawk.md": "9bf70ef138a9a281b86400aee393cae7", + "posix/signals.md": "2120ddd933fc0d57abb93c33f639afd8", + "gawk.md": "4517acfbf4e186e8cc66a9002fbad73f", "bash/index.md": "3b5296277f095acdf16655adcdf524af", - "bash/shebang.md": "bc30f75bcddff59d6f907fae89c17283", - "bash/robustness.md": "e474fd33469fc393bfde45cd7b9411ba" + "bash/shebang.md": "ad178efeb4a05190b80b5df108c175c7", + "bash/robustness.md": "de97cd77aae047b5eea27440b43c9c42", + "journal/2024-02-01.md": "f4cc061bfc8e41ce15ae9a354c65ffe9", + "journal/2024-01-31.md": "7c7fbfccabc316f9e676826bf8dfe970", + "bash/quoting.md": "b1d8869a91001f8b22f0cdc54d806f61", + "nix/callPackage.md": "5ef6bc5d1a549c55d43ebb4d48c64427", + "nix/index.md": "dd5ddd19e95d9bdbe020c68974d77a33" }, "fields_dict": { "Basic": [ diff --git a/notes/bash/quoting.md b/notes/bash/quoting.md new file mode 100644 index 0000000..5712e00 --- /dev/null +++ b/notes/bash/quoting.md @@ -0,0 +1,47 @@ +--- +title: Quoting +TARGET DECK: Obsidian::STEM +FILE TAGS: bash +tags: + - bash +--- + +%%ANKI +Basic +How do you escape a `'` within a single-quote string? +Back: This is impossible. +Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf) + +END%% + +%%ANKI +Basic +What does the null string refer to? +Back: The empty string, i.e. `""`. +Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf) + +END%% + +%%ANKI +Basic +When does Bash remove null strings from a command? +Back: When they occur as part of a non-null command-line argument. +Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf) + +END%% + +%%ANKI +Basic +Why does the following not work correctly? +```bash +$ # -F specifies the field separator +$ awk -F"" 'program' files +``` +Back: Bash removes the null string before executing the command. +Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf) + +END%% + +## References + +* Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf) \ No newline at end of file diff --git a/notes/bash/robustness.md b/notes/bash/robustness.md index 9e67484..ffbc400 100644 --- a/notes/bash/robustness.md +++ b/notes/bash/robustness.md @@ -7,7 +7,9 @@ tags: - shell --- -An interesting point Robbins[^robbins] discusses in his introduction to [[gawk]] is this idea of command robustness. He states that: +## Overview + +An interesting point Robbins discusses in his introduction to [[gawk]] is this idea of command robustness. He states that: > A self-contained shell script is more reliable because there are no other files to misplace. @@ -27,7 +29,7 @@ Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 202 END%% -The point he is arguing is that the first command below is considered more robust than the second since the command is more loosely coupled to its environment: +He argues that the first command below is more robust than the second since the command is more loosely coupled to its environment: ```bash $ awk 'program' input-file1 input-file2 ... @@ -55,4 +57,6 @@ It's interesting to think what else can be used as a measure of a command's robu * Whether a program acts atomically * Is it possible intermediate files are left that affect subsequent runs? -[^robbins]: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf) +## References + +* Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf) diff --git a/notes/bash/shebang.md b/notes/bash/shebang.md index 34ccf02..25e10f4 100644 --- a/notes/bash/shebang.md +++ b/notes/bash/shebang.md @@ -6,6 +6,8 @@ tags: - bash --- +## Overview + The shebang (also writting shabang or sha-bang) is a magic character at the start of a script indicating what command should be run when invoking the script directly. It always begins with ASCII characters `#!`.[^mendel] %%ANKI @@ -44,12 +46,13 @@ Some systems limit the length of interpreters to just 32 characters. A simple wo %%ANKI Basic -What workaround is used when shabang interpreter names are too long? +What workaround is used when shebang interpreter names are too long? Back: Introduce a symbolic link. Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf) END%% -[^mendel]: Cooper, Mendel. “Advanced Bash-Scripting Guide,” n.d., 916. +## References -[^robbins]: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf) \ No newline at end of file +* Cooper, Mendel. “Advanced Bash-Scripting Guide,” n.d., 916. +* Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf) \ No newline at end of file diff --git a/notes/gawk.md b/notes/gawk.md index c472189..607513a 100644 --- a/notes/gawk.md +++ b/notes/gawk.md @@ -8,7 +8,7 @@ tags: - gawk --- -## Introduction +## Overview %%ANKI Basic @@ -25,7 +25,7 @@ Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 202 END%% -> Dark corners are basically fractal - no matter how much you illuminate, there's always a smaller but darker one. +> Dark corners are basically fractal - no matter how much you illuminate, there's always a smaller but darker one. #quote The above quote is attributed to Brian Kernighan (one of the authors of the [[C]] K&R book). @@ -38,7 +38,7 @@ END%% ## Setup -Robbins[^robbins] suggests executing command `set +H` on [[bash]] startup to disable [[C]] shell-style command history. +Robbins suggests executing command `set +H` on [[bash]] startup to disable [[C]] shell-style command history. ## Usage @@ -83,4 +83,111 @@ Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 202 END%% -[^robbins]: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf) +%%ANKI +Basic +Write the `awk` command that searches file `mail-list` for string `li`. +Back: +```bash +$ awk '/li/ { print }' mail-list +``` +Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf) + +END%% + +%%ANKI +Basic +How is an `awk` rule without a pattern interpreted? +Back: As applying the specified action for every input line. +Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf) + +END%% + +%%ANKI +Basic +How is an `awk` rule without an action interpreted? +Back: As printing every line matching the specified pattern. +Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf) + +END%% + +%%ANKI +Basic +Describe what the following command does in in a single sentence: +```bash +$ awk 'length($0) > 80' data +``` +Back: Prints every line of `data` that is longer than `80` characters. +Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf) + +END%% + +**Targets** are specified as `$n` where `n` is a placeholder for the `n`th whitespace-separated **field**s of the input line. For example, `$1` refers to the first field of the input line. `$0` is a special target referring to the entire list of arguments, i.e. the entire line. + +%%ANKI +Basic +What is `$0` a placeholder for? +Back: The entire input line. +Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf) + +END%% + +%%ANKI +Basic +What is `$1` a placeholder for? +Back: The first field of the input line. +Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf) + +END%% + +%%ANKI +Basic +What is the `BEGIN` pattern? +Back: Code associated with it executes before any input is read. +Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf) + +END%% + +%%ANKI +Basic +What is the `END` pattern? +Back: Code associated with it executes after all input has been read. +Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf) + +END%% + +%%ANKI +Basic +Describe what the following command does in in a single sentence: +```bash +$ awk 'NF > 0' data +``` +Back: Prints every line of `data` with at least one field. +Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf) + +END%% + +%%ANKI +Basic +Describe what the following command does in in a single sentence: +```bash +$ awk 'END { print NR }' data +``` +Back: Prints the number of lines in `data`. +Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf) + +END%% + +%%ANKI +Basic +Describe what the following command does in in a single sentence: +```bash +$ awk 'NR % 2 == 0' data +``` +Back: Prints every even-numbered line in `data`. +Reference: Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf) + +END%% + +## References + +* Robbins, Arnold D. “GAWK: Effective AWK Programming,” October 2023. [https://www.gnu.org/software/gawk/manual/gawk.pdf](https://www.gnu.org/software/gawk/manual/gawk.pdf) \ No newline at end of file diff --git a/notes/journal/2024-02-01.md b/notes/journal/2024-02-01.md new file mode 100644 index 0000000..bf3f32a --- /dev/null +++ b/notes/journal/2024-02-01.md @@ -0,0 +1,18 @@ +--- +title: "2024-02-01" +--- + +- [x] Anki Flashcards +- [x] KoL +- [x] Sheet Music (10 min.) +- [x] OGS (1 Life & Death Problem) +- [x] Korean (Read 1 Story) +- [ ] Interview Prep (1 Practice Problem) +- [x] Log Work Hours (Max 3 hours) + +* Today was the first day using the FSRS algorithm with Anki. Continuing to use Just "Again" and "Good" on my original deck and using all options when using the Obsidian-generated deck. Goal is to eventually migrate back to using all the options. +* Spent some time migrating the Quartz setup to use Nix instead. I lose the ability to run Quartz locally (at least without more work), but upgrades are significantly easier. Theoretically the only thing I should care about is that my notes look good in Markdown/Obsidian anyways so fine with this trade-off. +* Read 해님 달님 (The Sun and the Moon) from Korean stories. +* Read sections 11.2 and 13.6 of "Database System Concepts". +* Practiced [reverse keyboard identification](https://www.musictheory.net/exercises/keyboard-reverse). +* Spent time learning how Nix's `callpackage` function works. diff --git a/notes/nix/callPackage.md b/notes/nix/callPackage.md new file mode 100644 index 0000000..54682c9 --- /dev/null +++ b/notes/nix/callPackage.md @@ -0,0 +1,116 @@ +--- +title: callPackage +TARGET DECK: Obsidian::STEM +FILE TAGS: nix +tags: + - nix +--- + +## Overview + +We first examine `lib.makeOverridable`. It's implementation isn't too important but understanding how it's used is. We adapt the example found in [nixpkgs](https://github.com/NixOS/nixpkgs/blob/56df668386ac83c5bcddf9849c645cf0d25706d7/lib/customisation.nix#L77): + +```nix +nix-repl> x = {a, b}: { example = a + b; } +nix-repl> y = lib.makeOverridable x { a = 1; b = 2; } +nix-repl> y +{ override = «lambda»; overrideDerivation = «lambda»; example = 3; } +nix-repl> y.override { a = 10; } +{ override = «lambda»; overrideDerivation = «lambda»; example = 12; } +``` + +`lib.makeOverridable` is an example of partial function application. Notice `y` still contains the result (`example`) of evaluating `x`. We can re-run the computation with a different value (in this case `a`) by invoking `y.override`. + +%%ANKI +Basic +What is the result of the following? +```nix +x = {a, b}: { example = a + b; } +lib.functionArgs x +``` +Back: `{ a = false; b = false; }` +Reference: Yin, Ryan. “NixOS and Flakes Book.” Nix, February 1, 2024. [https://github.com/ryan4yin/nixos-and-flakes-book](https://github.com/ryan4yin/nixos-and-flakes-book) + +END%% + +%%ANKI +Basic +What does each boolean returned by `lib.functionArgs` indicate? +Back: Whether the associated attribute has a default value. +Reference: Yin, Ryan. “NixOS and Flakes Book.” Nix, February 1, 2024. [https://github.com/ryan4yin/nixos-and-flakes-book](https://github.com/ryan4yin/nixos-and-flakes-book) + +END%% + +%%ANKI +Basic +What additional attributes is included in the set returned by `lib.makeOverridable`? +Back: `override` and `overrideDerivation`. +Reference: Yin, Ryan. “NixOS and Flakes Book.” Nix, February 1, 2024. [https://github.com/ryan4yin/nixos-and-flakes-book](https://github.com/ryan4yin/nixos-and-flakes-book) + +END%% + +%%ANKI +Basic +What is the value of `y.example` in the following? +```nix +x = {a, b}: { example = a + b; } +y = lib.makeOverridable x { a = 1; b = 2; } +``` +Back: `3` +Reference: Yin, Ryan. “NixOS and Flakes Book.” Nix, February 1, 2024. [https://github.com/ryan4yin/nixos-and-flakes-book](https://github.com/ryan4yin/nixos-and-flakes-book) + +END%% + +%%ANKI +Basic +What is the value of `(y.override { a = 10; }).example` in the following? +```nix +x = {a, b}: { example = a + b; } +y = lib.makeOverridable x { a = 1; b = 2; } +``` +Back: `12` +Reference: Yin, Ryan. “NixOS and Flakes Book.” Nix, February 1, 2024. [https://github.com/ryan4yin/nixos-and-flakes-book](https://github.com/ryan4yin/nixos-and-flakes-book) + +END%% + +Now we can understand how `pkgs.callPackage` works. The following is a simplification of the [actual implementation](https://github.com/NixOS/nixpkgs/blob/56df668386ac83c5bcddf9849c645cf0d25706d7/lib/customisation.nix#L153): + +```nix +callPackageWith = autoArgs: fn: args: + let + f = if isFunction fn then fn else import fn; + fargs = functionArgs f; + allArgs = intersectArgs fargs autoArgs // args; + in + lib.makeOverridable f allArgs + +callPackage = callPackageWith pkgs; +``` + +%%ANKI +Basic +What two functions is `callPackage` implemented on top of? +Back: `callPackageWith` and `lib.makeOverridable`. +Reference: Yin, Ryan. “NixOS and Flakes Book.” Nix, February 1, 2024. [https://github.com/ryan4yin/nixos-and-flakes-book](https://github.com/ryan4yin/nixos-and-flakes-book) + +END%% + +%%ANKI +Basic +What is the purpose of `callPackage`? +Back: It calls package functions with arguments automatic supplied if not overridden. +Reference: Yin, Ryan. “NixOS and Flakes Book.” Nix, February 1, 2024. [https://github.com/ryan4yin/nixos-and-flakes-book](https://github.com/ryan4yin/nixos-and-flakes-book) + +END%% + +%%ANKI +Basic +What attribute must be invoked in `callPackage`'s return value to override arguments? +Back: `override` +Reference: Yin, Ryan. “NixOS and Flakes Book.” Nix, February 1, 2024. [https://github.com/ryan4yin/nixos-and-flakes-book](https://github.com/ryan4yin/nixos-and-flakes-book) + +END%% + +## Reference + +* Yin, Ryan. “NixOS and Flakes Book.” Nix, February 1, 2024. [https://github.com/ryan4yin/nixos-and-flakes-book](https://github.com/ryan4yin/nixos-and-flakes-book) \ No newline at end of file diff --git a/notes/nix/index.md b/notes/nix/index.md new file mode 100644 index 0000000..39e7a6e --- /dev/null +++ b/notes/nix/index.md @@ -0,0 +1,3 @@ +--- +title: Nix +--- diff --git a/notes/posix/signals.md b/notes/posix/signals.md index d563053..29916c9 100644 --- a/notes/posix/signals.md +++ b/notes/posix/signals.md @@ -7,7 +7,9 @@ tags: - signal --- -This is an overview of specific POSIX signals.[^dowling] +## Overview + +This is an overview of specific POSIX signals. Code | Name ----- | -------------- @@ -112,4 +114,33 @@ Reference: `man 1 ps` END%% -[^dowling]: Dowling, “A List of Signals and What They Mean.” +### SIGINT (2) + +Indicates the process was interrupted by the user. Happens when pressing `Ctrl-C` from the controlling terminal. + +%%ANKI +Cloze +Signal {`SIGINT`} corresponds to number {2}. +Reference: Dowling, “A List of Signals and What They Mean.” + +END%% + +%%ANKI +Basic +What control sequence usually triggers a `SIGINT`? +Back: `Ctrl-C` +Reference: Dowling, “A List of Signals and What They Mean.” + +END%% + +%%ANKI +Basic +What is the `INT` in `SIGINT` short for? +Back: **Int**errupt +Reference: Dowling, “A List of Signals and What They Mean.” + +END%% + +## References + +* Dowling, “A List of Signals and What They Mean.”