Adding a QR Code Scanner to your Website

Barcode and QR code have become common in our day to day shopping and searching experience. Almost everyone has a QR Code Scanner installed in their phones as separate app or as a part of the camera.

You might want to add QRCode scanning as a part of your website. This simple addition opens up a world of possiblities - potentially improving the user experience of your users by leaps and bounds. Below you will learn how to add a simple QR Code Scanner to your Website.

You don’t need a native app to be able to scan QR codes - simple javascript can do the trick. We will use a npm package react-qr-reader. Add the following code to your javascript to get the QR Code scanner working:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import React, { Component } from 'react'
import QrReader from 'react-qr-reader'

class Test extends Component {
state = {
result: 'No result'
}

handleScan = data => {
if (data) {
this.setState({
result: data
})
}
}
handleError = err => {
console.error(err)
}
render() {
return (
<div>
<QrReader
delay={300}
onError={this.handleError}
onScan={this.handleScan}
style={{ width: '100%' }}
/>
<p>{this.state.result}</p>
</div>
)
}
}

After this, add the component <Test> to the page where you want the QR Code scanner and handle the data scanned in the handleScan function in the code above.

Scanning Website URLs and Opening them on an iframe

This technique can also be used to scan a URL and open it in a iframe rendered as a react component. There are a few things to remember in this approach:

  1. Most website today have X-Frame-Options header set to SAMEORIGIN. This blocks the website from loading in an iframe. You can only open URLs that have the X-Frame-Options header is set to ALLOW-FROM https://<your-website-url>
  2. OR Website from the same domain name as your iframe. Here is a MDN article explaining the same.

In case you aren’t able to load the website in your frame, and you have access to the website’s code, try adding the X-Frame-Options header to fix the issue.

Keep Docker Running

Many times we need dockers containers to keep running after they are started started either by using a docker run / docker exec / docker-compose command or while running as a kubernetes pod.

Read more

Rooting One Plus One

  1. Install TWRP recovery steps
  2. Install Lineage OS 14.1 based on Android 7 and GApps using the “Install” option on TWRP via sd card. Link to the guide.

A few lessons learnt along the way

  • Ensure the USB wire being used can also transfer data
  • Useful commands:
    1
    2
    3
    4
    5
    6
    adb devices -l
    fastboot devices
    fastboot oem unlock
    fastboot flash recovery /path/on/laptop/recovery.img
    adb push /path/on/laptop/supersu-v2.82.zip /sdcard/
    adb devices -l

Everything About Yaml And Invision

Everything there is to know about yaml condensed in a great blog post here

Also, I was facing an issue in Ubuntu of not being able to copy by Alt + Dragging objects. This post saved my day.

Pressing the Super (windows) key along with Alt while dragging items prevents the default window drag in Ubuntu.

Typing Unicode Characters in Ubuntu

Ever since I decided that ` was the best means to toggle Yakuake (which has been my lifeline for an integral part of the way I work for a long time now), typing ` whenever I needed it has been hell.

Read more

Live long and prosper - Spock

Spock is the new kid in town in the crowded world of testing frameworks.

Here is an article on Spock where the author tries to vent out years in frustration over JUnit in a very professionally demeanor.

What he was really trying to say is:

Read more

Good Git!

Most used (but yet unremembered) git commands

TLDR;

1
2
3
gl #git log --oneline --decorate --graph --all
gll #git log --graph --pretty='%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --all
tig #A commandline git history viewer
Read more