/til — Things I Learn
Things I have learned and want to remember, or that I think others might find useful. Some of these are links to articles from my postroll, while others are blog posts.
/postroll
Home row mods
www.youtube.com
I've heard Chris Hartjes talk about home row mods a few times, but thought you needed a special keyboard for them. However, it turns out that there are a number of system programs you can use to enable them, including kanata (which I've installed on my machine). Still getting used to them, but the ability to stay in the home row for common things like navigating between workspaces on linux is definitely amazing!
The linked video walks you through what they are and how to set them up with Kanata, and links you to a github repo with the configuration, as well as the system services you will need to setup to enable them.
/postroll
You can use text-wrap: balance; on icons
shkspr.mobi
The CSS directive text-wrap: balance
can be used to ensure that when lines are wrapped, you don't end up with an absurdly short trailing line. (This was something I used to do manually in a past life when I did book and catalog layout at a small publisher.) Even better: it will work even if there are inline objects in the line, allowing you to wrap lines of icons.
/postroll
Bash Strict Mode
redsymbol.net
I've known about the flags to make Bash behavior more strict or predictable, but this one adds an extra dimension for making iteration over strings more predictable as well. In a nutshell, strict mode is:
set -euo pipefail
IFS=$'\n\t'
Read the post for an excellent write-up of why each of these is important, and what each accomplishes.
From the blog
Posted 2024-10-25
Collapsing the Vivaldi Tab Sidebar
tl;dr: In Vivaldi, middle clicking the separator between the tab sidebar and the web page will either collapse or expand the sidebar; when collapsed, it shows just the tab favicons, and the workspace selector icon.
If you want to know how I got to that point, read on.
/postroll
Object Oriented Programming in Lua Using Annotations
betterprogramming.pub
Fantastic guide to creating class definitions in Lua, which turns out to be a prototype language similar to JavaScript. Demonstrates using annotations to specify visibility, and links to resources for annotations.
From the blog
Posted 2024-10-18
Escaping Regex Characters in Lua
Quick little note mainly for myself: Lua regex is different than PCRE. The big place it differs is in where you escape pattern matching characters (e.g. .
, ?
, +
, etc.). In PCRE, you escape these with a leading backslash (e.g., \.
, \?
, \+
). However, with Lua, you use the %
character: %.
, %?
, %+
.
From the blog
Posted 2024-10-10
Diagnosing Vivaldi resource usage
I recently noticed my CPU usage was high, and it was due to my open Vivaldi browser. I wasn't sure what tab was causing the issue, so I searched to see if Vivaldi had any tools for reporting this.
It turns out that Shift-Esc
will open a task manager, and you can sort on any of:
- Task (a string representing high level things like the browser as a whole, GPU process, worker tabs, and more)
- Memory footprint
- CPU (this was what I was interested in!)
- Network usage
- Process ID
You can select any task to end its process.
I was able to quickly track down the issue to a background worker running for a PWA window I'd closed earlier, and ended the process.
/postroll
Luacheck list of warnings
luacheck.readthedocs.io
I have Luacheck configured with coc.nvim, and started paying attention to warnings it is emitting. In some cases, I've realized that while the warning is valid, I might need to ignore it. You can do this by adding a comment of the form -- luacheck: ignore {pattern}
. The pattern is most succinct when you can use the Luacheck warning code... and this link lists all of them.
/postroll
Changing port maps in Docker Compose
akrabat.com
Rob details how to override and remove values in a Docker compose file when using a compose.override.yml
or extending a value/service.
To just override it:
- ports: !override
- "8081:80"
This is necessary, as otherwise if the value is already present in the original, the two settings get merged.
To remove:
- ports: !reset []
From the blog
Posted 2024-09-25
Do you know the preferred Docker compose file name?
I've been using Docker for... a long time now. So having a docker-compose.yml
file in a project is pretty natural and common for me.
Today I learned that the preferred file is now compose.yaml
(though compose.yml
is also allowed), and that the docker-compose
naming is only supported for backwards compatibility. (See the Compose file documentation if you don't believe me!)
Funny enough, the compose tooling doesn't call this out, even though it now calls out the fact you don't need to use the version
setting any more.
/postroll
Magento Cron via systemd timers | bitExpert
blog.bitexpert.de
Debian and Ubuntu are no longer shipping cron by default, and instead recommending setting up systemd timers. Stephan details how this is done, which requires both a systemd service file, and a systemd timer file.
The service file looks like this:
### Goes into /etc/systemd/system as a file with a .service extension
[Unit]
Description=Description of the service here
Wants=service-name.timer
[Service]
Type=oneshot
ExecStart=/path/to/executable/to/run/here
User=user-to-run-as
Group=group-to-run-as
[Install]
WantedBy=multi-user.target
You then create a timer, which is a systemd service defining a Timer section with an interval specified:
### Goes into /etc/systemd/system as a file with a .timer extension
[Unit]
Description=Executes every minute
Requires=service-name.service
[Timer]
Unit=service-name.service
OnCalendar=minutely
[Install]
WatnedBy=multi-user.target
The OnCalendar
property can use "natural language" shortcuts like "minutely" or "hourly", or you can define date/time-based interval such as *-*-* *:*:00
.
Once done, you need to start the service and enable the timer (usually as root):
systemctl start service-name.service
systemctl enable service-name.timer
and trigger it manually any time using:
systemctl start service-name.service
/postroll
Prevent the Docker container from taking 10 seconds to stop
akrabat.com
Rob Allen details how the exec form of a Docker CMD is the better form to use. The reason the string form invokes bash first, and thus bash gets PID 1, which is what Docker will terminate when the container is terminated. The problem is that bash doesn't then send a termination signal to the actual process invoked, forcing the Docker host to wait 10 seconds before force killing all processes in the container.
From the blog
Posted 2024-09-23
Fixing Generation of wl-clipboard Transient Windows When Used with Neovim
I have been plagued recently with issues stemming from neovim's interaction with the system clipboard. Every time I would copy text in nvim, I'd get a transient wl-clipboard window. Inside nvim, paste would work fine, but outside it, the system clipboard seemed not to get the contents.
I finally tracked it down to how Wezterm is interacting with Wayland.
And the culprit appears to be... the muxer.
From the blog
Posted 2024-09-20
Using CloudFlare to Validate DNS For An ACM Certificate
I recently received a notification from AWS indicating that ACM certificates I had in place for some S3 buckets I expose for websites could not renew due to an inability to validate via DNS.
Figuring out how to make it work was non-trivial, so I'm writing it up so I can remember in the future, and maybe save somebody else some trouble, as everything I found had to do with auto-provisioning via Terraform.
From the blog
Posted 2024-09-20
Copy A File From A Docker Container to the Host
Occasionally, I want to get a file from a Docker container back to the host system.
First, you need to get the container ID; you can do this using docker ps
.
Once you have that, use, docker cp
as follows:
docker cp <containerId>:/path/to/file/in/container path/on/host
From the blog
Posted 2024-09-20
Miscellaneous Postgres Commands
I switched over from SQLite to Postgres to power my site some months ago, and have found myself having to learn some new usage when interacting with the database. These are likely very old hat for anybody familiar with Postgres, but I find myself having to remind myself what they are.
/postroll
Chesterton’s Fence: A Lesson in Thinking
fs.blog
There is an adage attributed to G.K. Chesterton called "Chesterton's Fence" that can be abbreviated to this:
Do not remove a fence until you know why it was up in the first place.
I've read this article after a number of recent articles decrying the idea of "Founder's Mode" and other crappy entrepreneurial beliefs, and it struck a note with me. So many "disruptors" do not stop to understand why things operate as they currently do: what does having a taxi license solve for the community? what do environmental regulations solve for ecosystems? what additional regulations do hotels and other commercial lodgings need to abide by to protect consumers and employees? etc.
From the blog
Posted 2024-08-27
Configuring PHP.INI settings in a PHP-FPM pool
I consume PHP via Docker primarily, and to keep it manageable, I generally use a PHP-FPM container, with a web server sitting in front of it. I learned something new about PHP configuration recently that (a) made my day, and (b) kept me humble, as I should have known this all along.
/postroll
gron
github.com
gron
is a tool for working with JSON. It chunks things into key-value pairs where the key is a dot-separated hierarchy. This allows you then to use grep
or ack
to search for strings of interest.
It can also reassemble these back into JSON. This can be useful for adding or removing portions of a JSON structure. It becomes really interesting then when you pair it with jq
in order to retrieve data back out.
As an example, I can get the list of development requirements from a composer.json
with the following:
gron composer.json | ack "require-dev" | gron -u | jq '."require-dev" | keys[]'
(They'll still be in quotes, but that's easier to deal with than JSON keys!)
/postroll
Wezterm Quick Select Mode
wezfurlong.org
Quick select mode in Wezterm allows you to identify patterns in the current visible screen; Wezterm then highlights each and provides a key to each allowing you to copy and/or paste the associated value. Activate it with Ctrl-Shift-Space
.
As examples:
- It matches sha1 and md5 values. Use these to match a git ref in a log so you can then inspect it.
- It matches Docker container identifiers; use these to match a container identifier so you can run a command in it or copy a file from or to it.
- It matches URLs; use it to identify a URL to pass to HTTPie.
- It matches paths; use it to match a path to perform a file operation on.