Skip to content

Instantly share code, notes, and snippets.

@pabloav
Last active October 14, 2016 16:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pabloav/8553319 to your computer and use it in GitHub Desktop.
Save pabloav/8553319 to your computer and use it in GitHub Desktop.
Readable QR codes in Terminal
# 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
# 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
# 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