ChatGPT is the perfect Linux assistant

I spent the day doing remote maintenance on multiple Linux machines via ssh. The revelation is that ChatGPT is the bomb for these tasks: What does that command option do? I am trying to remember. What syntax is to install that peculiar and rarely used package on Debian? I am getting this locale configuration error; what was the fix again? All this stuff is answered much sooner than searching online, no matter the search engine....

March 29, 2024

SQLite foreign key constraints are disabled by default

Today, I learned that SQLite only enforces foreign-key constraints if explicitly instructed. I imagine this is well-known and trivial for the SQLite initiated, but we’re a Postgres shop; I have used SQLite sporadically, primarily for experiments like today’s, and this one amenity was certainly unexpected. Anyways. I had all my ON DELETE CASCADE constraints nicely configured, but related records in child tables were not being deleted when I deleted the parent....

February 22, 2024

Default ASP NET Core 8 port changed from 80 to 8080

Today, I learned the hard way that the default port for ASP.NET Core 8 container images has been updated from port 80 to 8080, quite a remarkable breaking change. We upgraded our web application from .NET 7 and let the CI pipeline do its work. Finally, we checked the application in the browser to ensure everything was okay, but unfortunately, we got a 502 Bad Gateway error. The Nginx logs revealed that the app was rejecting connections, which was unexpected because we didn’t make any changes there....

February 20, 2024

GitHub Wikis don't allow edits or pull requests

Today I learned that GitHub wikis are not editable online and do not support pull requests. You can clone and edit a wiki locally but not return your change to the original repository. I don’t use wikis in my projects; I prefer documentation to stay with the project, usually in a dedicated directory, and publish it on a dedicated site through GitHub Pages. But today was different as I opened a pull request for PaperMod, the Hugo theme I use on this website....

February 9, 2024

pg_dump and pg_restore can backup and restore single Postgres schemas

Today I learned that pg_dump can make a copy of a Postgres schema instead of the whole database. Likewise, if needed, pg_restore can restore the schema in either the original database or a different one. Backup of a Postgres schema: pg_dump -h host -d source_database -U user -n schema_name -F c -f schema_dump_file.dump Restore of a Postgres schema: pg_restore -h host -d dest_database -U user -n schema_name schema_dump_file.dump All primary and shared knowledge, I am sure....

January 30, 2024

Fixing the "Failed to create CoreCLR error 0x80070008" error when starting a .NET 8 docker container

Another day, another unexpected problem. Launching a .NET 8 app from a docker container, I got this error: Failed to create CoreCLR, HRESULT: 0x80070008. I was puzzled as the same container ran smoothly in our test environment but not in production. I ruled out resource problems (memory or disk full, maybe?) but then compared the Docker Engine versions we run in test and production. Both were old (20. xx when 25 is available), but interestingly, the production version was older....

January 26, 2024

How to fix the crontab error `rename: Operation not permitted`

Today, something unexpected happened while I was working on one of our Linux machines. I issued the crontab -e command to add a cron job to my user’s crontab file, modified and saved it, only to the following error: crontab: installing new crontab crontab: crontabs/<user>: rename: Operation not permitted crontab: edits left in /tmp/crontab.hgmsOH/crontab Puzzled, I checked whether my user permissions were all right, if the disk was full, and several other things....

January 25, 2024

How to implement a PKCE code challenge in C#

Today’s fun was implementing OAuth2’s RFC 7636’s PKCE (Proof Key for Code Exchange) in C#. It’s relatively straightforward, but I decided to share my implementation should it be helpful to someone else out there. PKCE is an extension to the Authorization Code flow to prevent CSRF and authorization code injection attacks. [..] It was originally designed to protect the authorization code flow in mobile apps, but its ability to prevent authorization code injection makes it useful for every type of OAuth client, even web apps that use client authentication (source)....

January 17, 2024

How to use bash to recursively search and replace a string in all directory files

Another achievement I unlocked with the recent website update is the newsletter switch from Substack to a fantastic and independent provider, Buttondown. That required updating all the “subscribe to my newsletter” links. We’re talking 5K posts, all saved as individual files in the same directory. The bash command that did that for me is: find content/post/*.md -type f -exec \ sed -i .bak 's|https://nicolaiarocci.substack.com|https://buttondown.email/nicolaiarocci|g' {} + It is pretty straightforward. find looks for all markdown files in the content/post/ directory....

January 6, 2024

How to use XmlWriter along with StringWriter to properly serialize a UTF-8 string

Today, I (re)learned how to serialize an XML to a UTF-8 string. Like all the other times I did this, I got backstabbed by StringWriter, which only supports UTF-16. A simple code snippet like this: await using var sw = new StringWriter(); await using var w = XmlWriter.Create(sw, new() { Async = true }); ... await w.FlushAsync(); return sw.ToString(); Will emit this output: <?xml version="1.0" encoding="utf-16"?><... There’s nothing inherently wrong with UTF-16, but XML is usually UTF-8, so one must do something about it....

November 9, 2023