dotnet SmtpClient should not be used

I am very late to the party, but today I learned that the good old dotnet SmptClient is considered obsolete and should not be used. Quoting the documentation: We don’t recommend using the SmtpClient class for new development because SmtpClient doesn’t support many modern protocols. Use MailKit or other libraries instead. (source) Interestingly, Microsoft is recommending a third-party open-source library as an alternative. I hope we’ll see more of that in the future. ...

May 4, 2021

How to add an empty directory to a Git repository

How do you add an empty directory to a Git repository? It’s a classic, and yet, I have to look it up every single time. Git does not support this out of the box: Currently the design of the Git index (staging area) only permits files to be listed, and nobody competent enough to make the change to allow empty directories has cared enough about this situation to remedy it. Directories are added automatically when adding files inside them. That is, directories never have to be added to the repository, and are not tracked on their own. You can say git add <dir> and it will add the files in there. If you really need a directory to exist in checkouts you should create a file in it. .gitignore works well for this purpose; you can leave it empty or fill in the names of files you do not expect to show up in the directory. (source) ...

March 22, 2021

Battling with SSH, cron jobs, and macOS Keyring

So today, I was setting up a cronjob on my trusty MacBook Pro. The goal was to backup some folders from a remote Linux server via rsync. The script is simple. It goes something like this: rsync -avz -e "ssh -i ~/.ssh/my_rsa_keyfile" myuser@myserver:remotedir/ ~/localdir/ Launched by hand, it works seamlessly. Call it from a cron job via crontab, and I get a permission denied error. I then enabled ssh -v option to gather a little intel on what was actually going on. As it turns out, the exact error was: ...

March 17, 2021

How to Shrink a WSL2 Virtual Disk

I discovered you can use the “diskpart” tool to compact a VHDX. This allows you to shrink a WSL2 virtual disk file, reclaiming disk space. It appeared to work for me without any data corruption, taking the file size down from 100GB to 15GB. (source) I adore Parallels “reclaim disk space” feature. Just the other day, I got back 70GB off my Windows Guest in a breeze. I’m coming from VirtualBox, where reclaiming disk space is a significant pain. I would expect optimize-vhd to achieve the goal with WSL2, but it’s nice to know there are alternatives, like Stephen’s above ...

March 12, 2021

Cleaning Up Your Postgres Database

I am an application/backend developer who has to quibble with databases more often than desired. I can get my way around Postgres pretty well, but I can always use a hint or two, especially when it comes to fine-tuning and performance. I stumbled upon Cleaning Up Your Postgres Databases. It offers useful advice on spotting performance bottlenecks in your Postgres database. Take the cache and index hit queries, for example. The first thing you’re going to want to look at is your cache hit ratio and index hit ratio. Your cache hit ratio is going to give the percentage of time your data is served from within memory vs. having to go to disk. Generally serving data from memory vs. disk is going to orders of magnitude faster, thus the more you can serve from memory the better. For a typical web application making a lot of short requests I’m going to target > 99% here. ...

March 9, 2021

How to increase upload file size in ASP.NET Core

Today I learned the hard way that since ASP.NET Core 2.0, the request body has acquired a default size limit at 30MB (~28.6 MiB). If the request body size exceeds the configured max request body size limit, the call to Request.Body.ReadAsync will throw an IOException. If this exception is uncaught, Kestrel will respond with a 413 Payload Too Large response and HttpSys will respond with a generic 500 Internal Server Error response (source). ...

February 26, 2021