commit a3ab6f615b162c1e40730402ac0410aa1220e9ca from: Omar Polo date: Tue Sep 22 09:29:59 2020 UTC noise commit: fix code blocks put the programming language name in every code block. While there, I fixed a typo or two. commit - 67f8544b5b7db1f589d2e9d7d6283b27df690a2b commit + a3ab6f615b162c1e40730402ac0410aa1220e9ca blob - 9ff575e190d7b94f42b35c3ab037f8b19f0eb291 blob + 167e37691750c175ec26dd552619911aff3caa17 --- resources/posts/abbreviations-vi.md +++ resources/posts/abbreviations-vi.md @@ -11,5 +11,7 @@ has them too. Now my `~/.nexrc` is more rich: - ab #d #define - ab #i #include +```vi +ab #d #define +ab #i #include +``` blob - 2e8f81f88f8e68bd8e8703cd8d84bba709c2987a blob + a29a4fecd7372fd1bfa72296b86ab3c576181d30 --- resources/posts/cgit-gitolite.md +++ resources/posts/cgit-gitolite.md @@ -35,7 +35,7 @@ httpd and slowcgi already in base.) For reference, my configuration file is `/usr/local/etc/cgit-op.conf` and contains: -``` +```conf css=/mine.css logo=/logo.png @@ -96,11 +96,11 @@ scan-path=/home/git/repositories ``` The important bits of all of these are only: -``` +```conf enable-git-config=1 ``` and -``` +```conf scan-path=/home/git/repositories ``` @@ -121,7 +121,7 @@ changing the default path for the repositories, I didn I'm still not sure if this is the best way to handle things, but I made fcgiwrap use the `git` user with -``` +```conf fcgiwrap_user="git" ``` in `/etc/rc.conf` plus a manual `chown(8)` on the socket. Now cgit @@ -142,7 +142,7 @@ If you set `enable-git-config` in cgit configuration f control some cgit per-repo options via `~git/repositories/$REPO/config`. You can create a section that looks like this: -``` +```conf [cgit] ignore = 1 ``` @@ -158,7 +158,7 @@ Fortunately, gitolite lets us set git configurations v `cgit.*` is enough, haven't tested tho). Now, in your `gitolite.conf` you can -``` +```conf repo gitolite-admin config cgit.ignore=1 ``` @@ -167,7 +167,7 @@ clone). But (there are too many 'but' in this section, hu?) we can do even better: -``` +```conf @hiddenrepos = gitolite-admin @hiddenrepos = private-stuff @hiddenrepos = next-gen-revolutionary-stuff blob - 4b6bd864ce2597598ba6952c77c100302a717e31 blob + 9e0fdb38e98b0d0ac776031d37facd2cee6f177e --- resources/posts/core-naming-on-linux.md +++ resources/posts/core-naming-on-linux.md @@ -27,12 +27,17 @@ daemon and *somethingsomething*-ctl to manage 'em. I cores in the directory I'm in. Bonus points if they are called like I'm used. -```echo %e.core | sudo tee /proc/sys/kernel/core_pattern``` +```sh +echo %e.core | sudo tee /proc/sys/kernel/core_pattern +``` `%e` is replaced with the program name. -However, on my machine, the core files are called `$prgname.core.$pid`. To disable the `.pid` at the end +However, on my machine, the core files are called +`$prgname.core.$pid`. To disable the `.pid` at the end -```echo 0 | sudo tee /proc/sys/kernel/core_uses_pid``` +```sh +echo 0 | sudo tee /proc/sys/kernel/core_uses_pid +``` -And that's all! \ No newline at end of file +And that's all! blob - 130779350554c45707c8b1f4b9daccf96c6b9069 blob + 7e5ef5cb901454d703bd2355a82f52bc5bf85f64 --- resources/posts/cpp-css.md +++ resources/posts/cpp-css.md @@ -20,7 +20,7 @@ least), and it's included in the base system installat If you have never used it, here's a quick howto. You can define constants with -``` +```c #define PI 3.141592653589793238462643383279502884197169 ``` and use them whenever you like, for instance @@ -36,15 +36,19 @@ manage a couple of CSS variables. Now, let's see how this applies to CSS. Given a file with the following content - #define BASE1 #221635 - - body { - background-color: BASE1; - } +```css +#define BASE1 #221635 +body { + background-color: BASE1; +} +``` + we can *compile* it with - $ cpp -P file.css > a.css +```sh +$ cpp -P file.css > a.css +``` and obtain a valid CSS file `a.css`. blob - 491dad90e822db97e65d069277237e88142f8fc0 blob + 731617e00257f78d7253213aa3622a905e82df21 --- resources/posts/css-sprites-awk-imagemagick.md +++ resources/posts/css-sprites-awk-imagemagick.md @@ -19,45 +19,47 @@ come along with imagemagick. Here's the script - #!/bin/sh +```sh +#!/bin/sh - convert sprites/* -append img/sprites.png +convert sprites/* -append img/sprites.png - for i in sprites/*; do - identify -format '%W %H %f\n' $i - done | awk ' - function fname(path) { - sub (".png", "", path) - return path - } +for i in sprites/*; do + identify -format '%W %H %f\n' $i +done | awk ' +function fname(path) { + sub (".png", "", path) + return path +} - BEGIN { - y = 0 +BEGIN { + y = 0 - print "%sprite-base {" - print " background-image: url(/img/sprites.png);" - print " background-repeat: no-repeat;" - print "}" - print "" - } + print "%sprite-base {" + print " background-image: url(/img/sprites.png);" + print " background-repeat: no-repeat;" + print "}" + print "" +} - { - width = $1 - height = $2 - class = fname($3) +{ + width = $1 + height = $2 + class = fname($3) - print "%sprite-" class " {" - print " @extend %sprite-base;" - if (y == 0) - print " background-position: 0 0;" - else - print " background-position: 0 -" y "px;" - print "}" - print "" + print "%sprite-" class " {" + print " @extend %sprite-base;" + if (y == 0) + print " background-position: 0 0;" + else + print " background-position: 0 -" y "px;" + print "}" + print "" - y += height; - } - ' > scss/_sprites.scss + y += height; +} +' > scss/_sprites.scss +``` Assuming that the images are within `sprites/` and all of them are png files, this script will generate the sprite in `img/sprites.png` and a blob - 58015fb69d5985ad7c69e211a956a305ae304308 blob + 32bbe7b139d9981650d711380ba568fa42b4fffb --- resources/posts/emms.md +++ resources/posts/emms.md @@ -58,7 +58,7 @@ code is what I ended up with. (emms-playlist-mode-center-current)))))) ``` -![emms selectrum](/img/emms-selectrum.png) +![emms selectrum](/img/emms-selectrum.png "Selecting a song from the current playlist with selectrum") Should be pretty easy to adapt it to use the standard `completing-read`. @@ -74,7 +74,7 @@ basically a mini-popup-ui for music controls. (in add recently discovered the hydra package, and I couldn't find an excuse not to build a hydra for EMMS). -![emms hydra](/img/emms-hydra.png) +![emms hydra](/img/emms-hydra.png "An Hydra for EMMS") I'm still pretty new to hydra, and I'm not 100% happy about how I'm doing the interpolation, but anyway, here's the code. blob - 75f4385dd2ef7302e0a4aa747320c068f43b56c7 blob + e1b753dd1fb1c0b991e6e3406d53600ee2ad191c --- resources/posts/enjoying-cdpath.md +++ resources/posts/enjoying-cdpath.md @@ -29,8 +29,10 @@ that I know respect `$CDPATH`, and how they behave. Just as I showed you up there. When you `cd` into a directory inside your `$CDPATH` it will print your new current working directory: - $ cd games/godot - /usr/ports/games/godot +```sh +$ cd games/godot +/usr/ports/games/godot +``` It will not, however, autocomplete. @@ -47,7 +49,9 @@ It will behave just like ksh. 9ports rc does not seem to inherit `$CDPATH`, but you can set it (unsurprisingly) with - cdpath=(. /usr/ports) +```rc +cdpath=(. /usr/ports) +``` in your `~/lib/profile`. Other versions of `rc` (I'm talking about the one you get with the `rc` package on FreeBSD) do inherit it, so double @@ -56,18 +60,22 @@ check! Additionally, `rc` prints the `pwd` only if you're `cd`-ing into something that's not within `.` (the current directory). So: - % pwd - /home/op - % echo $cdpath - . /usr/ports - % cd bin # won't print /home/op/bin - % cd games - /usr/ports/games - % +```rc +% pwd +/home/op +% echo $cdpath +. /usr/ports +% cd bin # won't print /home/op/bin +% cd games +/usr/ports/games +% +``` ### csh & tcsh - set cdpath = (. /usr/ports) +```csh +set cdpath = (. /usr/ports) +``` for the rest, behaves exactly like `rc`. I don't really use csh, nor tcsh, so I can't make further comments. blob - 1464b0aec0cfc41c600bc4bd441499131abb34fa blob + 848695a1afd67918057e1df21b9f3adc644c9369 --- resources/posts/finite-automata-godot.md +++ resources/posts/finite-automata-godot.md @@ -125,7 +125,7 @@ implementation of the states. All my states inherits node, so all that machinery with `has_method` isn't needed. The implementation of the superclass `State` is as follow: -``` +```gdscript # State.gd extends Node class_name State @@ -185,13 +185,13 @@ func process(delta : float) -> void: ``` with a scene tree as follows: -``` +```tree Enemy (KinematicBody2D in my case) |- ... - \- StateMachine + `- StateMachine |- WanderingState |- ChasingState - \- FleeingState + `- FleeingState ``` (the `get_node("../..")` is used to get the `Enemy` from the states, @@ -260,7 +260,7 @@ function. Then, if `C` wants to backtrack it can simp `backtrack()`, otherwise if it wants to change to another state, say `B`, it can do so with: -``` +```gdscript state_machine.pop() state_machine.change_to("B") ``` blob - 1d266c2d9083fe473982d238f40759cd8b078e15 blob + eca10e05c9b52a5f784201eb2f287a0494be26d3 --- resources/posts/fstar-openbsd.md +++ resources/posts/fstar-openbsd.md @@ -18,7 +18,9 @@ We'll need both `git` and GNU `make` from ports, and a build F* and run F* programs), opam (the ocaml package manager), ocaml-camlp4 and python 3 (to build `z3`, a theorem prover). - $ pkg_add git gmake ocaml ocaml-camlp4 opam python +```sh +$ pkg_add git gmake ocaml ocaml-camlp4 opam python +``` *Note* I've installed camlp4 from the ports instead of through opam because I was getting an error. I don't have much experience with @@ -32,12 +34,14 @@ z3 is the engine that powers the verification system o source. Even though is a project that came from Microsoft, it seems to run on OpenBSD just fine. Building it is also straightforward: - $ git clone https://github.com/Z3Prover/z3 - $ cd z3 - $ CXX=clang++ python3 script/mk_make.py - $ cd build - $ make - $ cp z3 $SOMEWHERE_IN_PATH # (maybe?) +```sh +$ git clone https://github.com/Z3Prover/z3 +$ cd z3 +$ CXX=clang++ python3 script/mk_make.py +$ cd build +$ make +$ cp z3 $SOMEWHERE_IN_PATH # (maybe?) +``` *Note* by default `script/mk_make.py` will try to use base g++ and the build will fail. The version of g++ is too ancient and doesn't support @@ -49,22 +53,30 @@ First of all, we need some ocaml dependencies, so make initialize opam (see `opam init`) and add the suggested stuff to your shell init file. - $ opam install ocamlfind batteries stdint zarith ppx_deriving ppx_deriving_yojson ocaml-migrate-parsetree process - +```sh +$ opam install ocamlfind batteries stdint zarith ppx_deriving ppx_deriving_yojson ocaml-migrate-parsetree process +``` + We can now build the F* compiler from the ocaml output present in the repo. You can also build the ocaml output by yourself, but I've skip this step. - $ gmake -j9 -C src/ocaml-output +```sh +$ gmake -j9 -C src/ocaml-output +``` The last step is to build the library. While the docs describes this as an optional step, I wasn't able to compile F* programs without it. - $ gmake -j9 -C ulib/ml +```sh +$ gmake -j9 -C ulib/ml +``` This was all. Let's try the hello world now! - $ gmake -C examples/hello hello +```sh +$ gmake -C examples/hello hello +``` It should take a decent amount of time to compile, output a *lot* of text and, finally, at the end, a beautiful "Hello World". blob - 8c90fd2d1bd919e59a05d10114194af6612b5280 blob + b46e0d4175346f35e192dc118216a71dfe2e4016 --- resources/posts/home-as-git-repo.md +++ resources/posts/home-as-git-repo.md @@ -8,7 +8,7 @@ I've done a bit of research on the internet and I've f of that post suggest to use your whole $HOME as a git repository, with a one-byte `.gitignore`: -``` +```gitignore * ``` @@ -19,9 +19,9 @@ except files that you add with `-f`. So far so good. --- **edit**: the part that follows is mostly wrong. The problem I had -was due to this piece of my global git conifg: +was due to this piece of my global git config: -``` +```git [core] excludesfile = ~/.gitignore ``` @@ -49,7 +49,7 @@ something else (git should stop at filesystem boundari this isn't my case. Fortunately there is a simple solution: -``` +```sh $ cd $ mv .gitignore .git/info/exclude ``` blob - f872610ac2409587e04b7e0f422801ba9f38ec44 blob + 06ae864ef2a5ea88bf7f22fbee76f5cc40987ed9 --- resources/posts/logstash-jdbc-role-does-not-exists.md +++ resources/posts/logstash-jdbc-role-does-not-exists.md @@ -4,7 +4,7 @@ However... I've got an error trying to synchronize elasticsearch and postgresql using logstash. My configurations was along the lines of -```yml +```logstash input { jdbc { jdbc_connection_string => "jdbc:postgresql://192.168.2.156:5432/chiaki" blob - 7c4b4a4a231063ba57b4c61466baa9df944ad606 blob + f316c219c4f6fd2e43b0bf3f6b740f4b8e2fb097 --- resources/posts/openbsd-tethering.md +++ resources/posts/openbsd-tethering.md @@ -1,7 +1,9 @@ These days, for various reason, I'm using USB tethering very often. Enabling it it's not difficult at all, it as simple as - doas dhclient urndis0 +```sh +doas dhclient urndis0 +``` But it's tedious. Especially if you need to do it multiple times per day. I needed something to save me from filling my shell history of @@ -50,9 +52,11 @@ esac Remember to make the script executable and to enable `hotplugd(8)`: - # chmod +x /etc/hotplug/attach - # rcctl enable hotplugd - # rcctl start hotplugd +```sh +# chmod +x /etc/hotplug/attach +# rcctl enable hotplugd +# rcctl start hotplugd +``` Every time you enable the tethering on your phone your computer will automatically connect to it. In theory the same principle can also be blob - 9aa2763075e4865de58066a111fe5ed03c8d677d blob + 18a67dd42dcb79451bb134cf2a306fb88af07318 --- resources/posts/poor-mans-unbound-dashboard.md +++ resources/posts/poor-mans-unbound-dashboard.md @@ -28,11 +28,13 @@ The result is this ## The flow - .- - / various -------> multiple - unbound stats ------- fifos -------> ttyplot - \ -------> per tmux pane - `- +```asciiart + .- + / various -------> multiple +unbound stats ------- fifos -------> ttyplot + \ -------> per tmux pane + `- +``` The idea is to run `unbound-control stats` every once in a while, multiplexing its output and draw each (interesting) stats with ttyplot blob - 386074e5398d9811831020524d519f2bd8a52554 blob + 490048367564b453ac6c943325e5be06e2c2866a --- resources/posts/sh-multiplexing-data.md +++ resources/posts/sh-multiplexing-data.md @@ -7,7 +7,9 @@ a piece of data from a pipeline and send it to two dif The canonical way to do this is `tee(1)`, and it's what I've used it the linked article: - something | tee >(cmd) | something-else +```sh +something | tee >(cmd) | something-else +``` (the `>(cmd)` construct is bash, and zsh I think, specific: it executes `cmd` in a subshell and execute `tee` with something like `/dev/fd/63` @@ -21,12 +23,14 @@ and the cons. That is: - something | tee a-file | something-else - cmd < a-file - - # and then, probably - rm a-file +```sh +something | tee a-file | something-else +cmd < a-file +# and then, probably +rm a-file +``` + (or even better with `mktemp(1)`) This is the most simple approach I can think of. The obvious disadvantage @@ -41,9 +45,11 @@ An almost similar approach is to use fifo. A fifo, ak is a special file that you can write to and read from, in a FIFO fashion. - mkfifo a-fifo - something | tee a-fifo | something-else - while read line < a-fifo; do echo $line; done | cmd +```sh +mkfifo a-fifo +something | tee a-fifo | something-else +while read line < a-fifo; do echo $line; done | cmd +``` This is especially useful if you need to have a long-running script that needs to duplicate a stream from one source. You create the fifos at the @@ -69,19 +75,23 @@ different processes pulling out those stats from the f The code was like - unbound-control stats \ - | tee >(grep something > a-fifo) \ - | tee >(grep something-else > b-fifo) \ - | ... +```sh +unbound-control stats \ +| tee >(grep something > a-fifo) \ +| tee >(grep something-else > b-fifo) \ +| ... +``` Well, that can be rewritten as - unbound-control stats \ - | sed 's/something/&/w a-fifo' \ - | sed 's/something-else/&/w b-fifo \ - | ... +```sh +unbound-control stats \ +| sed 's/something/&/w a-fifo' \ +| sed 's/something-else/&/w b-fifo \ +| ... +``` -by leveraging some sed behaviours: +by leveraging some sed behaviors: 1. every line read is printed to stdout (eventually transformed) 2. after the `s` command you can use `w` to write the transformed lines @@ -104,7 +114,6 @@ perform commands only on lines that match a regular ex ----- - I find this last technique pretty, even prettier than the `>(grep ... >)` idiom I used previously since it avoids the subshell to do the filtering and because it does not make assumption on the shell used -- it only blob - 5563d222ae0d6a900b7d46a4a30e39f45ce3b35a blob + f15ecca9bae2d98b6ce89425919b401e70558fa9 --- resources/posts/spell-checking-vi.md +++ resources/posts/spell-checking-vi.md @@ -5,7 +5,9 @@ some feature: but here's where the *composition* shine It's stupid and dead-simple actually, but I haven't thought about it until some weeks ago. With a simple - map « :w^M:!aspell -c %^M:e!^M^M +```vi +map « :w^M:!aspell -c %^M:e!^M^M +``` in your `~/.nexrc` it's simple to do spell checking in `vi`. @@ -15,9 +17,10 @@ with `C-v ENTER` or `C-v C-m`. I've also the following binding in my `~/.nexrc` to spell check Italian text: - map » :w^M:!aspell --lang=it -c %^M:e!^M^M +```vi +map » :w^M:!aspell --lang=it -c %^M:e!^M^M +``` - ### What's that gibberish? OK, it may be non-obvious what that that mapping does, so let's split blob - 677cb47265fdcf4c467991d5999db282f18ddf17 blob + 294641311b1450776cfb40b31d22361929a9c49c --- resources/posts/upgrading-ssh-key-ed25519.md +++ resources/posts/upgrading-ssh-key-ed25519.md @@ -21,24 +21,28 @@ the configuration. So, to keep it short, what I did was as simple as - ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 +```sh +ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 +``` and then adding the new public key to some servers. You can check with `ssh -v foo@bar` that ssh attempt to use various keys - ; ssh -v foo@bar - OpenSSH_8.3, LibreSSL 3.2.0 - debug1: Reading configuration data /home/op/.ssh/config - [...] - debug1: Offering public key: /home/op/.ssh/id_rsa RSA SHA256:... - debug1: Authentications that can continue: ... - debug1: Trying private key: /home/op/.ssh/id_dsa - debug1: Trying private key: /home/op/.ssh/id_ecdsa - debug1: Trying private key: /home/op/.ssh/id_ecdsa_sk - debug1: Offering public key: /home/op/.ssh/id_ed25519 ED25519 SHA256:... - debug1: Server accepts key: /home/op/.ssh/id_ed25519 ED25519 SHA256:... - debug1: Authentication succeeded (publickey). - [...] +```sh +; ssh -v foo@bar +OpenSSH_8.3, LibreSSL 3.2.0 +debug1: Reading configuration data /home/op/.ssh/config +[...] +debug1: Offering public key: /home/op/.ssh/id_rsa RSA SHA256:... +debug1: Authentications that can continue: ... +debug1: Trying private key: /home/op/.ssh/id_dsa +debug1: Trying private key: /home/op/.ssh/id_ecdsa +debug1: Trying private key: /home/op/.ssh/id_ecdsa_sk +debug1: Offering public key: /home/op/.ssh/id_ed25519 ED25519 SHA256:... +debug1: Server accepts key: /home/op/.ssh/id_ed25519 ED25519 SHA256:... +debug1: Authentication succeeded (publickey). +[...] +``` (lines elided to keep them short and readable)