How to quickly create a header modifying reverse proxy with mitmproxy

I’m currently in the process of testing some changes on OctoPrint involving its automatic user login via request headers, and for that needed to quickly set up a reverse proxy that would modify the headers of the requests going to the development server for some quick testing. Specifically, I wanted a quick CLI tool that would allow me to set up a reverse proxy listening on port 5555, forwarding to http://localhost:5000 while also setting the headers X-Remote-User to remote and X-Remote-Host to localhost:5555....

March 12, 2024 · 1 min

How to print Deutsche Post stamps via the command line on a Brother QL label printer

Update from 2024-01-12: I’ve updated the scripts to support both 50mm and 62mm wide labels, and added some more whitespace trimming to the basic stamp. The post has been adjusted accordingly. I recently acquired a Brother QL-820NWB label printer to be able to quickly create labels for boxes and such, and ideally also print out Deutsche Post’s “print yourself” stamps with it. The Deutsche Post stamp shop allows me to download PDFs targeting the 62mm wide endless labels for that printer, for the two types of stamps I’m interested in (stamp, and address label with stamp)....

January 11, 2024 · Updated January 12, 2024 · 3 min

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/ *....

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....

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 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 determine an RPi kernel version and build without booting it

To figure out the kernel version and build without booting it, e.g. to install matching device drivers during an automated image build in something like CustoPiZer, use something like this: function version_and_build_for_kernelimg() { kernelimg=$1 # uncompressed kernel? output=$(strings $kernelimg | grep 'Linux version' || echo) if [ -z "$output" ]; then # compressed kernel, needs more work, see https://raspberrypi.stackexchange.com/a/108107 pos=$(LC_ALL=C grep -P -a -b -m 1 --only-matching '\x1f\x8b\x08' $kernelimg | cut -f 1 -d :) dd if=$kernelimg of=kernel....

June 16, 2022 · 1 min
Mastodon