How to burn š„ time as an engineer or how to transfer basic data using QR š±
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.
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"
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 āļø