How to burn šŸ”„ time as an engineer or how to transfer basic data using QR šŸ“±

Marius Merkevičius
3 min readMay 18, 2021

--

Do you get into a situation, that you think, ā€” ā€œOnce i get this working, Iā€™ll be able to use it all the timeā€? Instead of doing it simply, I tend to go on a long journey of creating a tool that (most probably) no one needs or uses that often.

Oh well, apparently this was one of these times šŸ¤·ā€ā™‚ļø. And hereā€™s a story of it. Hopefully this will be a lesson for me. Or someone else, for that matter. But you can be sure, it will definitely sound like a random rant. Enjoy.

Building software tools (Photo by Dmitriy Demidov on Unsplash)

How it starts

Itā€™s Friday and as it appears to be, Iā€™m working on this app (Iā€™m an app developer). Now, I donā€™t have many test mobile devices at hand. And those that I use for this purpose are wiped clean. So that means, no google account, no google play (Huawei šŸ¤¦).

I get into situation where I need to paste a very long link on the device, but canā€™t figure out how to pass it in easily.

Soon after, I get a bright idea, why I donā€™t try passing it, by using QR code šŸ’”. Actually, the app I was working on, it is closely related with QR codes as well, and I wonder how I get these bright ideas.

The idea seemed simple. Just open a browser, paste the link, generate the QR, open the camera, boom šŸ’„, you have the link in test device.

How it gets down the hill

From now on, this goes down the hill. Once I got this so easily, Iā€™m thinking ā€” ā€œThis is so smart, why not make it a toolā€. Surely, there, is already a tool for that.

Well there is. The tool is called qrencode, and is available on MacOS or Linux systems through package managers. Just do a brew install qrencode (MacOS) or sudo apt install qrencode(Ubuntu), whichever oneā€™s your cup of tea šŸµ.

However, after installing it, it has a few drawbacks. Itā€™s not a one liner and yet, not so convenient. Looks like I may need a wrap into a script. So hereā€™s a sample script for MacOS.

#!/bin/bash
INPUT=$1
if [[ $# -eq 0 ]] ; then
echo "Paste in QR to generate"
exit 1
fi

echo "-- Generating QR..."
echo "$INPUT" | qrencode -t PNG -o /tmp/qrencode.png
LAST_CMD_STATUS=$?
if [[ $LAST_CMD_STATUS -ne 0 ]] ; then
echo "Error: Could not generate QR code: ${LAST_CMD_STATUS}"
exit $LAST_CMD_STATUS
fi
open /tmp/qrencode.png
  • Save it to qrcode.sh
  • Make the file executable by chmod +x qrcode.sh
  • Generate QR code by ./qrcode.sh "Hello world"
Using the tool

Something similar should work on any Linux as well, may just need little modification here and there. At least on the last part, with command open, as this opens an image on preferred image viewer, and may not work on Linux.

Finish off assembly

Now the only thing that is missing, is putting it at your quickest disposal. There are truly a lot of approaches whichever work, but hereā€™s my set-up on MacOS.

I use a terminal for almost everything, so opening it is just a press of a shortcut. Actually even two shortcuts, from each side of the keyboard, so you can do it by both hands when necessary. You can do this yourself on MacOS using iTerm.

Another life-hack, is to have the newly written script at disposal near. The easiest way to get this, just save your newly made script in your home directory ~/scripts and add script path to your PATH.

Now, whenever you need to generate a new QR, just press F12 (open terminal), type in qrcode.sh 'cool link' and it automatically opens the newly generated QR.

Personally I take this a bit further, by storing all these kind of convenience scripts into Dropbox, so the scripts would persist even after reinstall or across the similar OSes.

As Iā€™ve mentioned in the beginning. It is not something you would use that often, or is that useful, but hell, it was sure fun exploring and assembling everything together.

Cheers āœŒļø

--

--

Marius Merkevičius
Marius Merkevičius

No responses yet