Last active
October 14, 2016 16:44
-
-
Save pabloav/8553319 to your computer and use it in GitHub Desktop.
Readable QR codes in Terminal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# as of rqrcode 10.0 (Feb 2016), it can natively render ANSI making my code irrelevant: | |
require 'rubygems' | |
require 'rqrcode' | |
puts RQRCode::QRCode.new("http://www.example.com/").as_ansi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# By: Pablo Averbuj - 2014/01/21 - Public Domain | |
require 'rubygems' | |
require 'rqrcode' # install this gem | |
require 'colorize' # install this gem | |
b = " ".colorize(:background => :black) | |
w = " ".colorize(:background => :white) | |
url = "http://www.google.com/" | |
# you may have to increase the :size parameter (and the w * 51 correspondingly) depending of the content you're encoding | |
qr = RQRCode::QRCode.new(url, :size => 8) | |
puts w * 51; qr.to_s(:true => b, :false => w).split("\n").each{|l| puts w + l + w } ; puts w * 51 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# By: Pablo Averbuj - 2016/08/03 - Public Domain | |
# Modification with autosizing for URL | |
require 'rubygems' | |
require 'rqrcode' # install this gem | |
require 'colorize' # install this gem | |
def drawQR (url) | |
b = " ".colorize(:background => :black) | |
w = " ".colorize(:background => :white) | |
qr=nil | |
size=1 | |
while qr.nil? do | |
size += 1 | |
begin | |
qr = RQRCode::QRCode.new(url, :size => size) | |
puts w * (19+size*4); qr.to_s(:true => b, :false => w).split("\n").each{|l| puts w + l + w } ; puts w * (19+size*4) | |
rescue RQRCode::QRCodeRunTimeError | |
end | |
end | |
end | |
drawQR("http://www.google.com") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment