How to trim screenshots via the commandline

I just had to trim a bunch of screenshots that had some black borders around them. I didn’t want to do this manually or via a GUI, but ideally batch-able via the commandline. Thankfully, that’s one of the many things that ImageMagick can do for you. I put all my screenshot PNGs into a folder, and then in that folder ran this mogrify command: magick mogrify -trim -define trim:percent-background=0% -background black -path output/ *.png I found that I had to add the -define trim:percent-background=0% option to get rid of all black borders, as otherwise on some of the images a very slim one ended up remaining. I also specified the background color with -background black to make sure that it really only trimmed the black borders. ...

February 9, 2023 · 1 min

How to quickly generate a QR Code with transparent background

For an upcoming presentation I wanted to quickly generate a QR Code of my web site’s URL to include on the final slide. Since my slide theme has a green gradient background with white text, I wanted the QR Code to be white on a transparent background, as a PNG. Enter node-qrcode which runs easily via npx1: npx qrcode -o output.png -d FFFF -l 0000 -w 500 "https://foosel.net" -o output.png sets the output file -d FFFF sets the dark color (usually black) to white with 100% opacity -l 0000 sets the light color (usually white) to black with 0% opacity - fully transparent -w 500 sets the size to 500px For further options like error correction or QR code version, or how to use it as a library or in the browser, see node-qrcode’s repo linked above. ...

February 6, 2023 · 1 min

How to use jq to extract new posts from a JSON Feed

I’m currently looking into ways to automate some stuff around new posts on this page (be it blog or TIL post) directly during the page build on GitHub Actions. For this, I first need to be able to reliably detect new posts, from a bash run step. So here’s how to do that with jq. The idea is to get the current feed.json prior to publishing the page, and then compare it to the one that was just generated during the build. If there are any differences, we know that there are new posts and can trigger further actions from there. ...

February 2, 2023 · 2 min

How to grep a log for multiline errors

I just found myself in the position to have to grep an OctoPrint log file for error log entries with attached Python stack traces. I wanted to not only get the starting line where the exception log output starts, but the full stack trace up until the next regular log line. The format of the lines in octoprint.log is a simple %(asctime)s - %(name)s - %(levelname)s - %(message)s, so a log with an error and attached exception looks like this: ...

February 1, 2023 · 5 min

How to run Playwright on GitHub Actions

Running Playwright on GitHub Actions is fairly straightforward at first glance, however it becomes a bit more tricky when you don’t want to download the whole browser binary zoo on every single CI build. Looking around a bit on how to go about caching these, I came across various approaches listed in this GitHub issue on the Playwright repo. Below is the result of reading through most of them and figuring out what works best for me and my use case (OctoPrint’s E2E tests, npm based test project). ...

January 31, 2023 · 2 min

How to add JSON Feed support to Hugo

In order to add JSON Feed 1.1 support to Hugo you need to first add a new jsonfeed output format in config.yaml: mediaTypes: application/feed+json: suffixes: - json outputFormats: jsonfeed: mediaType: application/feed+json baseName: feed rel: alternate isPlainText: true This adds a new media type application/feed+json with the extension json and creates a new output format jsonfeed rendering into that media type with a base name of feed (so feed.json as recommended by the JSON Feed spec). This then needs to be added to the outputs it should be generated for - on this page I’ve only added it to sections. Again, in config.yaml: ...

January 29, 2023 · 3 min

How to view the page source on Firefox and Chrome mobile

Viewing the page source on Firefox and Chrome mobile is as easy as prepending view-source: to the URL. Example: https://foosel.net becomes view-source:https://foosel.net.

January 28, 2023 · 1 min

How to detect Termux in a script

If you need to detect whether you are running in Termux from a bash script, check if $PREFIX contains the string com.termux: echo $PREFIX | grep -o "com.termux" This can also be used to set a variable in a Taskfile: vars: TERMUX: '{{and .PREFIX (contains "com.termux" .PREFIX)}}' Source

January 23, 2023 · 1 min

How to open a file from Tasker in Markor

In order to open a file from Tasker in Markor (e.g. to edit a newly created blog post), create a “Send Intent” step with: Action: android.intent.action.SEND Cat: None Mime Type: text/plain Data: content://net.dinglisch.android.taskerm.fileprovider/external_files/path/to/the/file (be sure to replace /path/to/the/file with the absolute path to the file you want to open) Package: net.gsantner.markor Class: net.gsantner.markor.activity.DocumentActivity Source

January 21, 2023 · 1 min

How to edit an STL file in FreeCAD

Create a new file “File” > “Import”, import the STL Select the Part workbench Select the imported model “Part” > “Create shape from mesh”. A tesselation distance of 0.10 should work. Delete or hide import. “Part” > “Convert to solid” Source

September 30, 2022 · 1 min
Mastodon