From 27514d58573ce1f844af4ea60afa72c7f58f1cd7 Mon Sep 17 00:00:00 2001 From: Jasper Ras Date: Thu, 21 Aug 2025 22:09:29 +0200 Subject: vault backup: 2025-08-21 22:09:29 --- .obsidian/app.json | 3 +- .trash/How to return from a function.md | 5 + ...s do not have an architecture dependent size.md | 5 + .trash/Untitled 1.md | 0 .trash/Untitled 2 2.md | 0 .trash/Using if let or let else matching.md | 3 + A cool tool that visualizes the borrow checker.md | 5 - ... vendor module to the fixture for spec tests.md | 5 + Array notation.md | 2 - Bash Arrays.md | 2 + Bash.md | 6 +- Bilat 20 Augustus 2025.md | 5 + Bilat 23 July 2025.md | 2 + Bilat 25 juni 2025.md | 2 + Bilat 6 Augustus 2025.md | 1 + Bilaterale gesprekken met Rutger.md | 4 - Box deallocation principle.md | 2 +- Building NixOS disk images using disko.md | 7 ++ Cargo.md | 35 ++++++- Cleanup queues without consumers.md | 3 + Cluster issues openstack.md | 11 ++ Conditional.md | 3 + ...gging issues with updating Puppet dependency.md | 2 +- Delayed conditionals.md | 1 + ...ce between string slice and slice of strings.md | 4 + External Tools.md | 1 + GroupVPS Platform.md | 4 +- GroupVPS.md | 2 + Heredoc struggles.md | 21 ++++ How to return from a function.md | 6 -- If is not a statement but an expression.md | 1 - Input redirection.md | 4 + ...ed by default in Rust are called the prelude.md | 2 - JQ data types.md | 13 +++ JQ.md | 9 ++ Lifetime.md | 35 +++++++ Listing queues.md | 4 + Lookahead.md | 11 ++ Nix direnv.md | 6 ++ Nix flake.md | 20 ---- Nix flakes.md | 24 +++++ Nix.md | 6 +- NixOS modules.md | 13 +++ NixOS.md | 7 +- Option declarations.md | 20 ++++ Pass arguments to JQ.md | 7 ++ Puppet.md | 7 ++ Quorum Queues.md | 17 ++++ RabbitMQ Cluster.md | 4 + RabbitMQ.md | 7 ++ Rand Crate for random numbers.md | 1 + Random numbers in Rust.md | 3 - Referencing a nix flake.md | 12 +++ Regex.md | 1 + Relationships Puppet.md | 12 +++ Resetting cluster members.md | 11 ++ Rust Collections.md | 3 + Rust Control Flow.md | 3 + Rust Data Types.md | 113 +++++++++++++++++++++ Rust Hash Map.md | 0 Rust Looping.md | 3 + Rust Ownership.md | 24 +++++ Rust Principles.md | 3 + Rust String.md | 0 Rust Vector.md | 0 Rust principles.md | 3 - Rust struct associated functions.md | 22 ++++ Rust struct init shorthand.md | 16 +++ Rust struct update syntax.md | 22 ++++ Rust types.md | 0 Rust.md | 52 +++------- Secrets with Agenix.md | 0 Shadowing variables.md | 2 - Spec Testing.md | 41 ++++++++ ...ss functions are called associated functions.md | 3 - Systemd input output redirection.md | 24 +++++ TTL and Expiration.md | 8 ++ The option enum.md | 21 ++++ Trigger a service refresh with Puppet.md | 3 + ...s do not have an architecture dependent size.md | 5 - Untitled.md | 0 Why it is good to learn rust.md | 3 - 82 files changed, 677 insertions(+), 106 deletions(-) create mode 100644 .trash/How to return from a function.md create mode 100644 .trash/Unlike integers floats do not have an architecture dependent size.md create mode 100644 .trash/Untitled 1.md create mode 100644 .trash/Untitled 2 2.md create mode 100644 .trash/Using if let or let else matching.md delete mode 100644 A cool tool that visualizes the borrow checker.md create mode 100644 Adding new vendor module to the fixture for spec tests.md create mode 100644 Bash Arrays.md create mode 100644 Bilat 20 Augustus 2025.md create mode 100644 Building NixOS disk images using disko.md create mode 100644 Cleanup queues without consumers.md create mode 100644 Cluster issues openstack.md create mode 100644 Conditional.md create mode 100644 Delayed conditionals.md create mode 100644 Difference between string slice and slice of strings.md create mode 100644 External Tools.md create mode 100644 Heredoc struggles.md delete mode 100644 How to return from a function.md create mode 100644 Input redirection.md create mode 100644 JQ data types.md create mode 100644 JQ.md create mode 100644 Lifetime.md create mode 100644 Listing queues.md create mode 100644 Lookahead.md create mode 100644 Nix direnv.md delete mode 100644 Nix flake.md create mode 100644 Nix flakes.md create mode 100644 NixOS modules.md create mode 100644 Option declarations.md create mode 100644 Pass arguments to JQ.md create mode 100644 Puppet.md create mode 100644 Quorum Queues.md create mode 100644 RabbitMQ Cluster.md create mode 100644 RabbitMQ.md create mode 100644 Rand Crate for random numbers.md delete mode 100644 Random numbers in Rust.md create mode 100644 Referencing a nix flake.md create mode 100644 Relationships Puppet.md create mode 100644 Resetting cluster members.md create mode 100644 Rust Collections.md create mode 100644 Rust Control Flow.md create mode 100644 Rust Data Types.md create mode 100644 Rust Hash Map.md create mode 100644 Rust Looping.md create mode 100644 Rust Ownership.md create mode 100644 Rust Principles.md create mode 100644 Rust String.md create mode 100644 Rust Vector.md delete mode 100644 Rust principles.md create mode 100644 Rust struct associated functions.md create mode 100644 Rust struct init shorthand.md create mode 100644 Rust struct update syntax.md create mode 100644 Rust types.md create mode 100644 Secrets with Agenix.md create mode 100644 Spec Testing.md create mode 100644 Systemd input output redirection.md create mode 100644 TTL and Expiration.md create mode 100644 The option enum.md delete mode 100644 Unlike integers floats do not have an architecture dependent size.md delete mode 100644 Untitled.md diff --git a/.obsidian/app.json b/.obsidian/app.json index c9e99e1..ef1c27f 100644 --- a/.obsidian/app.json +++ b/.obsidian/app.json @@ -1,4 +1,5 @@ { "alwaysUpdateLinks": true, - "promptDelete": false + "promptDelete": false, + "defaultViewMode": "preview" } \ No newline at end of file diff --git a/.trash/How to return from a function.md b/.trash/How to return from a function.md new file mode 100644 index 0000000..095cea0 --- /dev/null +++ b/.trash/How to return from a function.md @@ -0,0 +1,5 @@ +[[Adding a semicolon to the end of a line turns it into a statement]] + +In Rust we can return from a function with simply an expression at the end of the scope. + +The `return` keyword is mostly used for returning early. \ No newline at end of file diff --git a/.trash/Unlike integers floats do not have an architecture dependent size.md b/.trash/Unlike integers floats do not have an architecture dependent size.md new file mode 100644 index 0000000..f6b962f --- /dev/null +++ b/.trash/Unlike integers floats do not have an architecture dependent size.md @@ -0,0 +1,5 @@ +[[Rust]] + +Integers come in many sizes with the smallest being 8-bit and the largest 128-bit. However there is also `usize or isize` which specifies that the size is dependent on the CPU architecture. + +In contrast, floating points only have two sizes: f32 and f64. There is no fsize. \ No newline at end of file diff --git a/.trash/Untitled 1.md b/.trash/Untitled 1.md new file mode 100644 index 0000000..e69de29 diff --git a/.trash/Untitled 2 2.md b/.trash/Untitled 2 2.md new file mode 100644 index 0000000..e69de29 diff --git a/.trash/Using if let or let else matching.md b/.trash/Using if let or let else matching.md new file mode 100644 index 0000000..48d0bd2 --- /dev/null +++ b/.trash/Using if let or let else matching.md @@ -0,0 +1,3 @@ +We can use `if let` if we have a match expression with just one pattern/arm that we care about. +```rust +``` diff --git a/A cool tool that visualizes the borrow checker.md b/A cool tool that visualizes the borrow checker.md deleted file mode 100644 index 425e6d2..0000000 --- a/A cool tool that visualizes the borrow checker.md +++ /dev/null @@ -1,5 +0,0 @@ -[[Rust]] - ---- - -https://github.com/cognitive-engineering-lab/aquascope \ No newline at end of file diff --git a/Adding new vendor module to the fixture for spec tests.md b/Adding new vendor module to the fixture for spec tests.md new file mode 100644 index 0000000..0a1266c --- /dev/null +++ b/Adding new vendor module to the fixture for spec tests.md @@ -0,0 +1,5 @@ +[[Puppet]] + +--- + +Add to: `/home/jras/projects/group.one/vps/puppet/modules/profile/.fixture.yml` \ No newline at end of file diff --git a/Array notation.md b/Array notation.md index b4cc810..caab634 100644 --- a/Array notation.md +++ b/Array notation.md @@ -1,5 +1,3 @@ -[[Rust]] - The array notation is a bit special compared to other languages so I will write it down here: Unlike tuples, arrays can only hold one type: diff --git a/Bash Arrays.md b/Bash Arrays.md new file mode 100644 index 0000000..db222ee --- /dev/null +++ b/Bash Arrays.md @@ -0,0 +1,2 @@ +Length of an array: `${#arr[@]}` -> `$#` = number of args , `${#str}` length of string str, `${#arr[@]` length of array, `${#arr}` length of first entry in array ie length of str for example. + diff --git a/Bash.md b/Bash.md index 239ac40..ee80a2e 100644 --- a/Bash.md +++ b/Bash.md @@ -2,5 +2,7 @@ tags: - bash --- -A scripting language in which a user can string together [[Shell]] commands in a reusable file called a script. The script can be executed (or "called") and it will execute the string of commands. -They are not full general purpose programming languages, even though they often have similar constructs available. \ No newline at end of file +[[Shell]] +[[Input redirection]] + +[[Bash Arrays]] \ No newline at end of file diff --git a/Bilat 20 Augustus 2025.md b/Bilat 20 Augustus 2025.md new file mode 100644 index 0000000..6d10cd1 --- /dev/null +++ b/Bilat 20 Augustus 2025.md @@ -0,0 +1,5 @@ +[[Bilaterale gesprekken met Rutger]] +# Jasper +t.b.d +# Rutger +t.b.d \ No newline at end of file diff --git a/Bilat 23 July 2025.md b/Bilat 23 July 2025.md index 5b8ff22..bd61753 100644 --- a/Bilat 23 July 2025.md +++ b/Bilat 23 July 2025.md @@ -1,3 +1,5 @@ +[[Bilaterale gesprekken met Rutger]] + calendar keystone auth middleware maken -> restrict ip per user. marcel huck - share netwerk diff --git a/Bilat 25 juni 2025.md b/Bilat 25 juni 2025.md index 181e478..64cab2c 100644 --- a/Bilat 25 juni 2025.md +++ b/Bilat 25 juni 2025.md @@ -1,3 +1,5 @@ +[[Bilaterale gesprekken met Rutger]] + Blij met Ali. Doet het erg goed, pakt zelf dingen snel op, weinig assistentie nodig gehad dusver. Stelt op tijd vragen en snapt vrijwel direct wat je bedoelt. Mohammed vind een ERROR loggen wanneer iets werkt als verwacht normaal.. ik heb duidelijk aangegeven dat dat niet normaal is. diff --git a/Bilat 6 Augustus 2025.md b/Bilat 6 Augustus 2025.md index 2e50edd..781b4a1 100644 --- a/Bilat 6 Augustus 2025.md +++ b/Bilat 6 Augustus 2025.md @@ -1,3 +1,4 @@ +[[Bilaterale gesprekken met Rutger]] # Jasper Rust aan het leren in vrije tijd.. Verder niets noemenswaardigs gebeurd de afgelopen 2 weken. diff --git a/Bilaterale gesprekken met Rutger.md b/Bilaterale gesprekken met Rutger.md index 48d6ab4..e69de29 100644 --- a/Bilaterale gesprekken met Rutger.md +++ b/Bilaterale gesprekken met Rutger.md @@ -1,4 +0,0 @@ -[[Bilat 25 juni 2025]] -[[Bilat 9 july 2025]] -[[Bilat 23 July 2025]] -[[Bilat 6 Augustus 2025]] diff --git a/Box deallocation principle.md b/Box deallocation principle.md index 10975c4..0174a4b 100644 --- a/Box deallocation principle.md +++ b/Box deallocation principle.md @@ -1,4 +1,4 @@ -[[Rust principles]] +[[Rust Principles]] [[When heap data is deallocated]] --- diff --git a/Building NixOS disk images using disko.md b/Building NixOS disk images using disko.md new file mode 100644 index 0000000..8634155 --- /dev/null +++ b/Building NixOS disk images using disko.md @@ -0,0 +1,7 @@ +[Documentation](https://github.com/nix-community/disko/blob/master/docs/disko-images.md) + +--- + +No special configuration is required besides the disk config from disko and setting the `imageSize` property in it. + +Disko includes a script that we can call using nix build and via referencing it through the flake: `nix build .#nixosConfigurations.myhost.config.system.build.diskoImageScript`. \ No newline at end of file diff --git a/Cargo.md b/Cargo.md index baa57ed..009aff9 100644 --- a/Cargo.md +++ b/Cargo.md @@ -1,4 +1,37 @@ -[[Rust]] +Module -> Crate -> Package + +Binary Crate +Library Crate (tip: should contain the module tree, binary crate should be a client to the lib) + +Package: n binary crates, 1 library crate +`src/main.rs` package exports binary crate of package name +`src/bin/*.rs` multiple binary crates +`src/lib.rs` package exports library crate of package name + +--- + +Absolute import path start with `crate::` etc. +Relative import path start with `self::` , `super::`, or an identifier in the current mod. +`super` starts rel path from the parent module. +child scope can access everything in parent scope even privates. + +`use` to create a shortcut to crates **only** in the **current** scope. + +It's idiomatic when calling a function to import its parent module so it's clear that the function call is not to a local function. For importing structs and enums and such it's idiomatic to import them all the way (unless its name collides ofc). + +`use .. as name` is also possible. + +`pub use ..` to re-export it so external callers can also reference it shortly, exposing a different structure to callers than the internal package actually is. + +Nesting `use` stmts: `use std::{cmp::Ordering, io};` +or `use std::io::{self, Write};` instead of `std::io;` and `std::io::Write;`. + +Glob: `use std::collections::*;` + +`pub mod blaat;` -> `src/blaat.rs` -> `pub mod henk;` -> `src/blaat/henk.rs`. +old-style: `src/blaat/mod.rs` -> `src/blaat/henk/mod.rs` (many mod.rs files) + +--- Standard stuff: - cargo build diff --git a/Cleanup queues without consumers.md b/Cleanup queues without consumers.md new file mode 100644 index 0000000..0fa534c --- /dev/null +++ b/Cleanup queues without consumers.md @@ -0,0 +1,3 @@ +```bash +sudo rabbitmqctl list_queues consumers name | awk '$1 == "0" { print $2 }' | xargs -n1 sudo rabbitmqctl delete_queue +``` \ No newline at end of file diff --git a/Cluster issues openstack.md b/Cluster issues openstack.md new file mode 100644 index 0000000..100e086 --- /dev/null +++ b/Cluster issues openstack.md @@ -0,0 +1,11 @@ +[[Resetting cluster members]] + +--- + +[Mirantis](https://docs.mirantis.com/mcp/q4-18/mcp-operations-guide/openstack-operations/rabbitmq-ops.html) +> We recommend that you do not restart a RabbitMQ node on a production environment by executing **systemctl restart rabbitmq-server** since a cluster can become inoperative. + +Check `rabbitmqctl list_queues messages consumers name` if the dashboard shows a lot of ready messages it might be that there are queues where messages are being sent to but have no consumers. They expire after 30 minutes so wait for that first and then see. + +A lot of unacknowledged messages on a specific node: `rabbitmq-upgrade drain` and then `rabbitmq-upgrade revive` seems to help, but in some cases the symptom moves to another node. + diff --git a/Conditional.md b/Conditional.md new file mode 100644 index 0000000..f70ba6b --- /dev/null +++ b/Conditional.md @@ -0,0 +1,3 @@ +```shell +jq 'if . | length == 1 then "hello" else null end' +``` \ No newline at end of file diff --git a/Debugging issues with updating Puppet dependency.md b/Debugging issues with updating Puppet dependency.md index acfa3d0..6fee1da 100644 --- a/Debugging issues with updating Puppet dependency.md +++ b/Debugging issues with updating Puppet dependency.md @@ -2,7 +2,7 @@ tags: - puppet --- -[[GroupVPS Platform]] +[[Puppet]] --- diff --git a/Delayed conditionals.md b/Delayed conditionals.md new file mode 100644 index 0000000..1d32884 --- /dev/null +++ b/Delayed conditionals.md @@ -0,0 +1 @@ +Use `mkIf` if a set of options depends on the state of another option such as a boolean option. \ No newline at end of file diff --git a/Difference between string slice and slice of strings.md b/Difference between string slice and slice of strings.md new file mode 100644 index 0000000..1105ce7 --- /dev/null +++ b/Difference between string slice and slice of strings.md @@ -0,0 +1,4 @@ +A string slice: `&str` +A slice of strings: `&[String]` + +`&[String]` for example can be used to reference a subset of a `Vec` while `&str` references part of a `String`. \ No newline at end of file diff --git a/External Tools.md b/External Tools.md new file mode 100644 index 0000000..aff98df --- /dev/null +++ b/External Tools.md @@ -0,0 +1 @@ +Borrowchecker visualizer: https://github.com/cognitive-engineering-lab/aquascope \ No newline at end of file diff --git a/GroupVPS Platform.md b/GroupVPS Platform.md index 42a3bab..230eda4 100644 --- a/GroupVPS Platform.md +++ b/GroupVPS Platform.md @@ -3,10 +3,12 @@ tags: - work - groupvps --- -[[Bilaterale gesprekken met Rutger]] [[SOPs]] [[ceilometer data is going into Prometheus as Ihor fixed the out of order issue]] [[Project naming conventions]] [[Application credentials]] + + +[[RabbitMQ]] \ No newline at end of file diff --git a/GroupVPS.md b/GroupVPS.md index f2b95fb..35bd5b3 100644 --- a/GroupVPS.md +++ b/GroupVPS.md @@ -1 +1,3 @@ [[GroupVPS Platform]] + +[[Bilaterale gesprekken met Rutger]] \ No newline at end of file diff --git a/Heredoc struggles.md b/Heredoc struggles.md new file mode 100644 index 0000000..076b248 --- /dev/null +++ b/Heredoc struggles.md @@ -0,0 +1,21 @@ +```puppet +@(END) <- no str interpolation +@("END") <- quotes around END enable string interpolation ${} +@("END"/$) <- interpolation + we can escape from it using \$ for a literal $ +END + | END + +``` + +#### Escape sequences + +|Switch to put in the heredoc tag|Escape sequence to use in the heredoc string|Result in the string value| +|---|---|---| +|(automatic)|`\\`|Single backslash. This switch is enabled when any other escape sequence is enabled.| +|`n`|`\n`|New line| +|`r`|`\r`|Carriage return| +|`t`|`\t`|Tab| +|`s`|`\s`|Space| +|`$`|`\$`|Literal dollar sign (to prevent interpolation)| +|`u`|`\uXXXX` or `\u{XXXXXX}`|Unicode character number `XXXX` (a four-digit hexadecimal number) or `XXXXXX` (a two- to six-digit hexadecimal number)| +|`L`|`\`|Nothing. This lets you put line breaks in the heredoc source code that does not appear in the string value. \ No newline at end of file diff --git a/How to return from a function.md b/How to return from a function.md deleted file mode 100644 index 0fde1fc..0000000 --- a/How to return from a function.md +++ /dev/null @@ -1,6 +0,0 @@ -[[Rust]] -[[Adding a semicolon to the end of a line turns it into a statement]] - -In Rust we can return from a function with simply an expression at the end of the scope. - -The `return` keyword is mostly used for returning early. \ No newline at end of file diff --git a/If is not a statement but an expression.md b/If is not a statement but an expression.md index 4ece748..9794d49 100644 --- a/If is not a statement but an expression.md +++ b/If is not a statement but an expression.md @@ -1,4 +1,3 @@ -[[Rust]] [[Statement vs expression]] An if statement is not a statement in rust! It is an expression! Thus we can use it in an assignment for example. diff --git a/Input redirection.md b/Input redirection.md new file mode 100644 index 0000000..22055e2 --- /dev/null +++ b/Input redirection.md @@ -0,0 +1,4 @@ +`> file.txt` : stdout to file +`2> file.txt`: stderr to file +`2>&1 > file.txt`: stderr to stdout then to file +`&> file.txt`: stderr and stdout to file \ No newline at end of file diff --git a/Items that are always imported by default in Rust are called the prelude.md b/Items that are always imported by default in Rust are called the prelude.md index 6a4fa2f..4755839 100644 --- a/Items that are always imported by default in Rust are called the prelude.md +++ b/Items that are always imported by default in Rust are called the prelude.md @@ -1,5 +1,3 @@ -[[Rust]] - Every function and other thing that are always accessible in every Rust program are together called the `prelude`. What is included in the prelude is documented [here](https://doc.rust-lang.org/std/prelude/index.html) \ No newline at end of file diff --git a/JQ data types.md b/JQ data types.md new file mode 100644 index 0000000..e25e365 --- /dev/null +++ b/JQ data types.md @@ -0,0 +1,13 @@ +This can be done using built-in functions: +- tostring +- toboolean +- tonumber + +the `type` function returns the type of its argument: +- string +- boolean +- number +- array +- object +- null + diff --git a/JQ.md b/JQ.md new file mode 100644 index 0000000..b7bae00 --- /dev/null +++ b/JQ.md @@ -0,0 +1,9 @@ + +# Command-line +[[Pass arguments to JQ]] + +# Language +[[A nice way to select IPv4 addresses with JQ]] +[[Using JQ to construct an array and filtering empty strings]] +[[Conditional]] +[[JQ data types]] \ No newline at end of file diff --git a/Lifetime.md b/Lifetime.md new file mode 100644 index 0000000..45ab96c --- /dev/null +++ b/Lifetime.md @@ -0,0 +1,35 @@ +[[Rust]] +[[Data must outlive any references to it]] + +Associated permission: Flow: +Indicates whether or not a reference argument is allowed to be used, or a reference is allowed to be returned. + +Simple example: +```rust +fn a_or_b(a: &str, b: &str) -> &str { + if something { + a + } else { + b + } +} + +let a = vec![]; +let b = String::from("a"); +let c = a_or_b(&a, &b); +drop(b); +println!("{}", c); +``` + +In the above example `c` is being printed after `b` is dropped but `a_or_b` could have returned `b` so the println uses freed data ( null pointer exception) . + +It is also not possible to return a reference to heap data that will be dropped at the end of the function. + +```rust +fn epic_ref() -> &str { + let cool = String::from("yo"); + let coolref = &cool; + coolref +} +``` +^ will fail \ No newline at end of file diff --git a/Listing queues.md b/Listing queues.md new file mode 100644 index 0000000..a7d29ec --- /dev/null +++ b/Listing queues.md @@ -0,0 +1,4 @@ +With `rabbitmqctl list_queues` we can add columns to show: +- `rabbitmqctl list_queues messages consumers name` + +`man rabbitmqctl` for more options. diff --git a/Lookahead.md b/Lookahead.md new file mode 100644 index 0000000..5405b91 --- /dev/null +++ b/Lookahead.md @@ -0,0 +1,11 @@ +v the match any statements are like: match `hallo`, `hallobob`, `hallobier` + +Negative lookahead: `hallo(?!blaat)`: match any hallo but not in halloblaat +Positive lookahead: `hallo(?=blaat)`: only match hallo in halloblaat + +--- + +Negative lookbehind: `(? Look behind has limited browser compatibility + diff --git a/Nix direnv.md b/Nix direnv.md new file mode 100644 index 0000000..420e693 --- /dev/null +++ b/Nix direnv.md @@ -0,0 +1,6 @@ +[[Nix flakes]] +[[Referencing a nix flake]] + +--- + +`use flake "/home/jras/nixos#hieradata"` : this references the `devShells.{system}.hieradata` output of the flake in `/home/jras/nixos. \ No newline at end of file diff --git a/Nix flake.md b/Nix flake.md deleted file mode 100644 index 09b9b09..0000000 --- a/Nix flake.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -tags: - - nix ---- -Root directory contains flake.nix: -Specifies inputs (other flakes) and outputs ([[Nix derivations]]). Allows pinning versions of inputs (dependencies) making it easier to write reproducable expressions. - -Avoid multiple nixpkgs by including a follows on the input: -``` -inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/"; - hyprland = { - url = "github:hyprwm/Hyprland"; - inputs.nixpkgs.follows = "nixpkgs"; - }; -}; -``` - -Outputs: -[Flake check](https://github.com/NixOS/nix/blob/master/src/nix/flake-check.md) diff --git a/Nix flakes.md b/Nix flakes.md new file mode 100644 index 0000000..f57ed36 --- /dev/null +++ b/Nix flakes.md @@ -0,0 +1,24 @@ +--- +tags: + - nix +--- +[[Referencing a nix flake]] + +--- + +Root directory contains flake.nix: +Specifies inputs (other flakes) and outputs ([[Nix derivations]]). Allows pinning versions of inputs (dependencies) making it easier to write reproducable expressions. + +Avoid multiple nixpkgs by including a follows on the input: +``` +inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/"; + hyprland = { + url = "github:hyprwm/Hyprland"; + inputs.nixpkgs.follows = "nixpkgs"; + }; +}; +``` + +Outputs: +[Flake check](https://github.com/NixOS/nix/blob/master/src/nix/flake-check.md) diff --git a/Nix.md b/Nix.md index adf40f4..9a8dc9c 100644 --- a/Nix.md +++ b/Nix.md @@ -4,4 +4,8 @@ tags: --- Nix is a build system & package manager with its own functional programming language also called Nix. -[[NixOS]] is a complete Linux operating system built and packaged with Nix. \ No newline at end of file +[[NixOS]] is a complete Linux operating system built and packaged with Nix. + +--- + +[[Secrets with Agenix]] diff --git a/NixOS modules.md b/NixOS modules.md new file mode 100644 index 0000000..d5e82b5 --- /dev/null +++ b/NixOS modules.md @@ -0,0 +1,13 @@ + +[[Option declarations]] + +--- + +```nix +{ pkgs, config, ... }: +{ + options = {}; + config = {}; +} +``` + diff --git a/NixOS.md b/NixOS.md index 3a39f82..f0a13c1 100644 --- a/NixOS.md +++ b/NixOS.md @@ -1,3 +1,6 @@ -A declaratively configured Linux OS using the [[Nix]] build system. +[Manual](https://nixos.org/manual/nixos/stable/) -The [Manual](https://nixos.org/manual/nixos/stable/) holds a lot of valuable information. \ No newline at end of file +--- + +[[NixOS modules]] +[[Building NixOS disk images using disko]] \ No newline at end of file diff --git a/Option declarations.md b/Option declarations.md new file mode 100644 index 0000000..0bc59f6 --- /dev/null +++ b/Option declarations.md @@ -0,0 +1,20 @@ +[Types](https://nixos.org/manual/nixos/stable/#sec-option-types) +[[Delayed conditionals]] + +--- + +```nix +{ + options = { + name = mkOption { + type = type specification; + default = default value; + example = example value; + description = "Description for use in the NixOS manual."; + }; + }; +} +``` + +# Utility functions +`mkEnableOption "what"` -> a bool opt with a desc like: "Whether to enable what". \ No newline at end of file diff --git a/Pass arguments to JQ.md b/Pass arguments to JQ.md new file mode 100644 index 0000000..0411444 --- /dev/null +++ b/Pass arguments to JQ.md @@ -0,0 +1,7 @@ +[[JQ data types]] + +--- + +`jq --arg blaat test '.name == $blaat` + +argument is a string, so if we want to cmp integers for example we need to cast it. \ No newline at end of file diff --git a/Puppet.md b/Puppet.md new file mode 100644 index 0000000..8222d92 --- /dev/null +++ b/Puppet.md @@ -0,0 +1,7 @@ +[[GroupVPS Platform]] +[Documentation](https://www.puppet.com/docs/puppet/7/puppet_index.html) + +--- +[[Spec Testing]] +[[Relationships Puppet]] +[[Heredoc struggles]] \ No newline at end of file diff --git a/Quorum Queues.md b/Quorum Queues.md new file mode 100644 index 0000000..4792c14 --- /dev/null +++ b/Quorum Queues.md @@ -0,0 +1,17 @@ +[Docs](https://www.rabbitmq.com/docs/quorum-queues) + +# Growing replicas +```shell +sudo rabbitmq-queues grow rabbit@rabbitmq.env.vps1-lej1.one.com all +``` +> Idempotent, should be done for each node in the cluster +### Check quorum status on all quorum queues +```shell +sudo rabbitmq-diagnostics list_queues arguments name | grep quorum | cut -f2 | sudo xargs -n1 rabbitmq-diagnostics quorum_status +``` +> quorum_status --formatter json + +```shell +sudo rabbitmq-diagnostics list_queues arguments name | grep quorum | cut -f2 | while read name; do sudo rabbitmq-diagnostics quorum_status --formatter json "${name}" | jq '. | length == 3' | xargs test true == || echo ${name}; done +``` +> List only queues that less than 3 replicas \ No newline at end of file diff --git a/RabbitMQ Cluster.md b/RabbitMQ Cluster.md new file mode 100644 index 0000000..f62e7c2 --- /dev/null +++ b/RabbitMQ Cluster.md @@ -0,0 +1,4 @@ + +# Partition handling strategy +`ignore` +`pause-minority`: pauses the nodes in the partition that have a minority and restarts them when they regain connection. \ No newline at end of file diff --git a/RabbitMQ.md b/RabbitMQ.md new file mode 100644 index 0000000..cf2d7e9 --- /dev/null +++ b/RabbitMQ.md @@ -0,0 +1,7 @@ +[[Quorum Queues]] +[[Listing queues]] +[[Cleanup queues without consumers]] +[[RabbitMQ Cluster]] +[[TTL and Expiration]] +[[Cluster issues openstack]] +[[Resetting cluster members]] \ No newline at end of file diff --git a/Rand Crate for random numbers.md b/Rand Crate for random numbers.md new file mode 100644 index 0000000..efe9af6 --- /dev/null +++ b/Rand Crate for random numbers.md @@ -0,0 +1 @@ +To do random numbers we can use the [rand crate](https://crates.io/crates/rand). \ No newline at end of file diff --git a/Random numbers in Rust.md b/Random numbers in Rust.md deleted file mode 100644 index 85b4e59..0000000 --- a/Random numbers in Rust.md +++ /dev/null @@ -1,3 +0,0 @@ -[[Rust]] - -To do random numbers we can use the [rand crate](https://crates.io/crates/rand). \ No newline at end of file diff --git a/Referencing a nix flake.md b/Referencing a nix flake.md new file mode 100644 index 0000000..cf2dec9 --- /dev/null +++ b/Referencing a nix flake.md @@ -0,0 +1,12 @@ +[Documentation](https://nix.dev/manual/nix/2.28/command-ref/new-cli/nix3-flake#flake-references) + +--- + +If no `attrpath` then `default` is tried. + +`github:Owner/repo#attrpath` +`git+https://github.com/NixOS/patchelf?ref=master&rev=f34751b88bd07d7f44f5cd3200fb4122bf916c7e` + +can also reference flakes by just a filesystem path, ie: +`/home/jras/nixos#hieradata`. + diff --git a/Regex.md b/Regex.md index 3239e44..7e89331 100644 --- a/Regex.md +++ b/Regex.md @@ -2,3 +2,4 @@ https://www.regular-expressions.info/ [[Non Capturing Groups]] +[[Lookahead]] diff --git a/Relationships Puppet.md b/Relationships Puppet.md new file mode 100644 index 0000000..123ccb9 --- /dev/null +++ b/Relationships Puppet.md @@ -0,0 +1,12 @@ +A resource can be `refreshed` when `notified` by another resource. + +--- + +Relationship params: +- `before`: before target resource +- `require`: after target resource +- `notify`: before target resource, target refreshes if this changes +- `subscribe`: after target resource and then notified if target changes + +> Can be a list of resources + diff --git a/Resetting cluster members.md b/Resetting cluster members.md new file mode 100644 index 0000000..2b4c6c3 --- /dev/null +++ b/Resetting cluster members.md @@ -0,0 +1,11 @@ +It seems that this can be safely done on our openstack cluster. The procedure is as follows: + +*On the node that you wish to reset* +- `sudo rabbitmqctl stop_app` (no systemctl stop otherwise the reset will fail) +- `sudo rabbitmqctl reset` +- `sudo rabbitmqctl join_cluster rabbit@anothermember` +- `sudo rabbitmqctl start_app` + +*On one of the other nodes* +- `sudo rabbitmq-queues grow rabbit@resetnode all` +- `sudo rabbitmq-queues rebalance all` || quorum \ No newline at end of file diff --git a/Rust Collections.md b/Rust Collections.md new file mode 100644 index 0000000..b9cfa1a --- /dev/null +++ b/Rust Collections.md @@ -0,0 +1,3 @@ +[[Rust Vector]] +[[Rust String]] +[[Rust Hash Map]] \ No newline at end of file diff --git a/Rust Control Flow.md b/Rust Control Flow.md new file mode 100644 index 0000000..d4cc9a6 --- /dev/null +++ b/Rust Control Flow.md @@ -0,0 +1,3 @@ +[[There is no truthiness]] +[[If is not a statement but an expression]] +[[Pattern matching with a match expression]] \ No newline at end of file diff --git a/Rust Data Types.md b/Rust Data Types.md new file mode 100644 index 0000000..d46b2a3 --- /dev/null +++ b/Rust Data Types.md @@ -0,0 +1,113 @@ +# Scalar +[[Integers can overflow if compiled with --release]] +[[Char is a unicode scalar value]] + +`bool` +`char` + +integer (signed, unsigned): `i/u8`, `i/u16`,` i/u32`, `i/u64`, `i/u128` or `i/usize` (cpu arch). + +`f32` or `f64` + +#### Number Literals +Decimal: `500_000_000` +Hex: `0xff` +Octal: `0o77` +Binary: `0b1111_0000` +Byte (u8 only): `b'A'` + +# Compound +tuple: `(i32, f64, char)` +array: `[i32; len]` + +[[Accessing a tuple by index is different from an array]] +[[An empty tuple is called a unit]] +[[Primitive values such as the array are allocated on the stack]] +[[Arrays are useful when you know the length will not change]] +[[Array notation]] + +string slice: `&str` +general slice: `&[type]` ie `&[i32]` or `&[String]` which is different from `&str`. + +[[Difference between string slice and slice of strings]] +## Structs +[[Rust struct init shorthand]] +[[Rust struct update syntax]] +[[Rust struct associated functions]] + +```rust +struct Blaat { + name: i32, + other: String, +} +``` + +**tuple struct** +Type enforcement so we know what we're dealing with is semantically correct. +```rust +struct Point3D(i32, i32, i32); +``` + +**unit struct** +useful for implementing behaviour that doesn't require data. +```rust +struct Blaat; +``` + +## Enums +[[The option enum]] + +```rust +enum IpAddrKind { + V4(i8, i8, i8, i8) + V6(String) +} + +IpAddrKind::V4(String::from(127, 0, 0, 1)); +``` +It is obviously also possible to use custom type's (ie struct) in an enum so the above could be rewritten as +```rust +struct IPV4Addr { ... } +struct IPV6Addr { ... } + +enum IPAddr { + V4(IPV4Addr) + V6(IPV6Addr) +} +``` +In this sense enum's can be used as some sort of inheritance, ie both are IPAddr's. +It is also possible to associate functions with enum's using `impl`. + +#### Match +```rust +match { + IpAddr::V4(s1, s2, s3, s4) => { + println!("ip address = {}.{}.{}.{}", s1, s2, s3, s4); + } + other => something(), + _ => (), +} +``` + +##### using if let or else let matching + +```rust +fn handle_message(msg: Msg) { + if let Message::OK(innerMsg) = msg { + println!("{}", innerMsg) + } + + + let innerMsg = if let Message::OK(innerMsg) = msg { + innerMsg + } else { + return None + } + + // ^ Can be written as v: + + let Message::OK(innerMsg) = msg else { + return None + } +} +``` \ No newline at end of file diff --git a/Rust Hash Map.md b/Rust Hash Map.md new file mode 100644 index 0000000..e69de29 diff --git a/Rust Looping.md b/Rust Looping.md new file mode 100644 index 0000000..774927f --- /dev/null +++ b/Rust Looping.md @@ -0,0 +1,3 @@ +[[Returning values from loops]] +[[Loop over an array with for-in]] + diff --git a/Rust Ownership.md b/Rust Ownership.md new file mode 100644 index 0000000..7d8c97e --- /dev/null +++ b/Rust Ownership.md @@ -0,0 +1,24 @@ +[[Ownership]] +[[Lifetime]] + + +[[Undefined behaviour is caught by the compiler]] +[[Variables lives on the stack]] +[[To put data on the heap use a Box]] +[[Cloning a box does a deep copy of the heap data]] +[[Aliasing just means that multiple variables point to the same heap data]] +[[A place is anything that is valid to put on the left-hand side of an assignment]] + +[[Dereferencing is to access the data behind a pointer]] +[[Aliasing just means that multiple variables point to the same heap data]] +[[Variables are subject to permissions similar to files on linux]] +[[References temporarily remove permissions]] +[[Creating a reference to a variable is called borrowing]] +[[It is illegal to create a mutable reference while an immutable reference is live]] +[[Data must outlive any references to it]] +[[Move ownership out of the function]] +[[Return a static literal]] +[[Defer borrow checking to runtime with garbage collection]] +[[Provide a slot by the caller]] +[[Clone a reference in a function to modify it]] +[[Shortening the lifetime of borrowed variables before mutating it]] diff --git a/Rust Principles.md b/Rust Principles.md new file mode 100644 index 0000000..7a23c84 --- /dev/null +++ b/Rust Principles.md @@ -0,0 +1,3 @@ +[[Box deallocation principle]] +[[Moved heap data principle]] +[[Pointer safety principle]] \ No newline at end of file diff --git a/Rust String.md b/Rust String.md new file mode 100644 index 0000000..e69de29 diff --git a/Rust Vector.md b/Rust Vector.md new file mode 100644 index 0000000..e69de29 diff --git a/Rust principles.md b/Rust principles.md deleted file mode 100644 index 7a23c84..0000000 --- a/Rust principles.md +++ /dev/null @@ -1,3 +0,0 @@ -[[Box deallocation principle]] -[[Moved heap data principle]] -[[Pointer safety principle]] \ No newline at end of file diff --git a/Rust struct associated functions.md b/Rust struct associated functions.md new file mode 100644 index 0000000..4c5e660 --- /dev/null +++ b/Rust struct associated functions.md @@ -0,0 +1,22 @@ +Associated functions are an umbrella term for all `fn` declared in an `impl` block. +A method is just an associated `fn` with `Self` as its first argument but it's not mandatory, for ie constructors or what in PHP would be a static class function. + +```rust +struct Rectangle { + width: u32, + height: u32, +} + +impl Rectangle { + fn area(&self) -> u32 { + self.width * self.height + } + + fn square(size: u32) -> Rectangle { + Rectangle { + width: size, + height: size, + } + } +} +``` \ No newline at end of file diff --git a/Rust struct init shorthand.md b/Rust struct init shorthand.md new file mode 100644 index 0000000..01c740c --- /dev/null +++ b/Rust struct init shorthand.md @@ -0,0 +1,16 @@ +A struct can be initialized in a function like we do in Go. Rust has a nice shorthand: if the function args are named identically to the struct fields we don't have to pass the struct field name: + +```rust +struct User { + name: String, + age: i8, +} + +fn init_user(name: String, what: i8) -> User { + User { + name <- shorthand + age: what, + } +} +``` + diff --git a/Rust struct update syntax.md b/Rust struct update syntax.md new file mode 100644 index 0000000..299ac55 --- /dev/null +++ b/Rust struct update syntax.md @@ -0,0 +1,22 @@ +Instantiate a new instance of a struct with most of the fields from an other instance: + +```rust +struct User { + name: String, + email: String, +} + +fn main () { + let user1 = User { + name: String::from("Jasper"), + email: String::from("jaspert.ras@gmail.com"), + } + + let user2 = User { + email: String::from("maffe_jasper@hotmail.nl"), + ..user1 + } +} +``` + +Will reuse `name` from `user1`. \ No newline at end of file diff --git a/Rust types.md b/Rust types.md new file mode 100644 index 0000000..e69de29 diff --git a/Rust.md b/Rust.md index d053f90..9ae4bb9 100644 --- a/Rust.md +++ b/Rust.md @@ -1,48 +1,26 @@ [[Why it is good to learn rust]] -[[A cool tool that visualizes the borrow checker]] -[[Rust principles]] +[[External Tools]] + +--- +[[Rust Principles]] +[[Rust Data Types]] +[[Rust Control Flow]] +[[Rust Looping]] +[[Rust Ownership]] +[[Rust Collections]] + +--- [[Cargo]] +[[Rand Crate for random numbers]] + [[Items that are always imported by default in Rust are called the prelude]] [[Static class functions are called associated functions]] [[References are also immutable by default]] -[[Random numbers in Rust]] -[[Pattern matching with a match expression]] + [[Shadowing variables]] -[[Integers can overflow if compiled with --release]] -[[Char is a unicode scalar value]] -[[Unlike integers floats do not have an architecture dependent size]] + [[Why is it called destructuring]] -[[Accessing a tuple by index is different from an array]] -[[An empty tuple is called a unit]] -[[Primitive values such as the array are allocated on the stack]] -[[Arrays are useful when you know the length will not change]] -[[Array notation]] [[A scope block is an expression]] [[Adding a semicolon to the end of a line turns it into a statement]] -[[How to return from a function]] [[Statement vs expression]] -[[There is no truthiness]] -[[If is not a statement but an expression]] -[[Returning values from loops]] -[[Loop over an array with for-in]] -[[Undefined behaviour is caught by the compiler]] -[[Variables lives on the stack]] -[[To put data on the heap use a Box]] -[[Cloning a box does a deep copy of the heap data]] -[[Aliasing just means that multiple variables point to the same heap data]] -[[A place is anything that is valid to put on the left-hand side of an assignment]] -[[Ownership]] -[[Dereferencing is to access the data behind a pointer]] -[[Aliasing just means that multiple variables point to the same heap data]] -[[Variables are subject to permissions similar to files on linux]] -[[References temporarily remove permissions]] -[[Creating a reference to a variable is called borrowing]] -[[It is illegal to create a mutable reference while an immutable reference is live]] -[[Data must outlive any references to it]] -[[Move ownership out of the function]] -[[Return a static literal]] -[[Defer borrow checking to runtime with garbage collection]] -[[Provide a slot by the caller]] -[[Clone a reference in a function to modify it]] -[[Shortening the lifetime of borrowed variables before mutating it]] diff --git a/Secrets with Agenix.md b/Secrets with Agenix.md new file mode 100644 index 0000000..e69de29 diff --git a/Shadowing variables.md b/Shadowing variables.md index ce10d66..6ff1d58 100644 --- a/Shadowing variables.md +++ b/Shadowing variables.md @@ -1,5 +1,3 @@ -[[Rust]] - It is basically redeclaring the same variable, but it can be redeclared with a **different type**. A immutable variable can also be shadowed. Shadowing is undone when the scope ends, for example in a closure I can shadow a variable from the parent scope, but in the parent scope after the child scope ends we have the original value not the one from the child scope. diff --git a/Spec Testing.md b/Spec Testing.md new file mode 100644 index 0000000..5728aeb --- /dev/null +++ b/Spec Testing.md @@ -0,0 +1,41 @@ +[[Puppet]] +[Rspec Puppet](https://rspec-puppet.com/) + +--- + +```ruby +require 'spec_helper' + +describe '' do + # Your tests go in here +end +``` + +--- + +`is_expected.to` or `is_expected.to_not` + +defined types need a title: `let(:title) { 'title' }` +parameters: `let(:params) { { 'a' => 'b' } }` + +`contain_class('name')` or `contain_name` + +`contain_` < can be suffixed with anything, ie `contain_file`, `contain_exec`, `contain_class` or just `contain_apache__params` for defined types. +`::` in `apache::params` -> `apache__params` of a defined type. + +To test parameters chain `.with()` which contains a hash of expected paremeters. With can also be suffixed with the name of the param, ie `.with_ensure()`. + +`only_with` for ensuring that a argument is the only argument being set on given resource. + +--- + +> If a class is an fully qualified class reference (start with`::`) then in the test **do not** include the double colon to reference the class only use its name. + +```puppet +// manifest +class { '::tempest': } + +// test +is_expected.to contain_class('tempest') <- valid +is_expected.to contain_class('::tempest') <- invalid +``` \ No newline at end of file diff --git a/Static class functions are called associated functions.md b/Static class functions are called associated functions.md index dc4c195..f6421b0 100644 --- a/Static class functions are called associated functions.md +++ b/Static class functions are called associated functions.md @@ -1,6 +1,3 @@ -[[Rust]] - ---- An `associated function` is what in other OOP languages like PHP would be considered a static function on a class. So it's callable directly from on type rather than an object. An example in Rust is `String::new()`. It is indicated by the double colon `::`. \ No newline at end of file diff --git a/Systemd input output redirection.md b/Systemd input output redirection.md new file mode 100644 index 0000000..5cc75ca --- /dev/null +++ b/Systemd input output redirection.md @@ -0,0 +1,24 @@ +[[Systemd]] +[Upstream documentation](https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html#Logging%20and%20Standard%20Input/Output) + +`StandardOutput=` +`DefaultStandardError=inherit` +`StandardError=DefaultStandardError` + +`StandardInput=` +`StandardInputText=` +`StandardInputData=` + +##### Outputs +- `inherit` +- `null` +- `tty` +- `journal` +- `kmsg` +- `journal+console` +- `kmsg+console` +- `file:path` (overwrites file) +- `append:path` +- `truncate:path` +- `socket` +- `fd:name` \ No newline at end of file diff --git a/TTL and Expiration.md b/TTL and Expiration.md new file mode 100644 index 0000000..dcea95f --- /dev/null +++ b/TTL and Expiration.md @@ -0,0 +1,8 @@ +[Doc](https://www.rabbitmq.com/docs/ttl) + +--- + +Message TTL: when a lingering msg should die +Queue TTL: when a lingering queue should die + +**We set a 30 min queue TTL on our queues.** \ No newline at end of file diff --git a/The option enum.md b/The option enum.md new file mode 100644 index 0000000..3534ea0 --- /dev/null +++ b/The option enum.md @@ -0,0 +1,21 @@ +Is in the prelude, so always available. Used where we can return something or none, instead of null. + +```rust +enum Option { + None + Some(T) +} +``` + +This enables the compiler to check whether we handle both cases. Why? +```rust +fn do_something(int: i32, nope: bool) -> Option { + if (nope) { + return None + } + + return Some(int * 2) +} +``` + +The concrete return type is either `None` or `Some`: so if the called would for example do `1 + do_something(2, false);` would not compile because the return type is not an i32. Unlike for example PHP where it's `?int` so either `null` or `int` the compiler can't check this. \ No newline at end of file diff --git a/Trigger a service refresh with Puppet.md b/Trigger a service refresh with Puppet.md index 9ac7f23..7bbaebe 100644 --- a/Trigger a service refresh with Puppet.md +++ b/Trigger a service refresh with Puppet.md @@ -2,6 +2,9 @@ tags: - puppet --- +[[Puppet]] + + ``` service { 'goba': ensure => running, diff --git a/Unlike integers floats do not have an architecture dependent size.md b/Unlike integers floats do not have an architecture dependent size.md deleted file mode 100644 index f6b962f..0000000 --- a/Unlike integers floats do not have an architecture dependent size.md +++ /dev/null @@ -1,5 +0,0 @@ -[[Rust]] - -Integers come in many sizes with the smallest being 8-bit and the largest 128-bit. However there is also `usize or isize` which specifies that the size is dependent on the CPU architecture. - -In contrast, floating points only have two sizes: f32 and f64. There is no fsize. \ No newline at end of file diff --git a/Untitled.md b/Untitled.md deleted file mode 100644 index e69de29..0000000 diff --git a/Why it is good to learn rust.md b/Why it is good to learn rust.md index c60bbc6..a982883 100644 --- a/Why it is good to learn rust.md +++ b/Why it is good to learn rust.md @@ -1,5 +1,2 @@ -[[Rust]] - ---- I want to do game engine development and game development in my spare time I can use it for systems programming too \ No newline at end of file -- cgit v1.2.3