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.

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 ✌️

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store