Skip to content

Instantly share code, notes, and snippets.

@yantene
Created September 30, 2018 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yantene/e12459f89c0d397186cd69b956544858 to your computer and use it in GitHub Desktop.
Save yantene/e12459f89c0d397186cd69b956544858 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
braille = <<~EOS
⠀⠁⠂⠃⠄⠅⠆⠇⡀⡁⡂⡃⡄⡅⡆⡇⠈⠉⠊⠋⠌⠍⠎⠏⡈⡉⡊⡋⡌⡍⡎⡏
⠐⠑⠒⠓⠔⠕⠖⠗⡐⡑⡒⡓⡔⡕⡖⡗⠘⠙⠚⠛⠜⠝⠞⠟⡘⡙⡚⡛⡜⡝⡞⡟
⠠⠡⠢⠣⠤⠥⠦⠧⡠⡡⡢⡣⡤⡥⡦⡧⠨⠩⠪⠫⠬⠭⠮⠯⡨⡩⡪⡫⡬⡭⡮⡯
⠰⠱⠲⠳⠴⠵⠶⠷⡰⡱⡲⡳⡴⡵⡶⡷⠸⠹⠺⠻⠼⠽⠾⠿⡸⡹⡺⡻⡼⡽⡾⡿
⢀⢁⢂⢃⢄⢅⢆⢇⣀⣁⣂⣃⣄⣅⣆⣇⢈⢉⢊⢋⢌⢍⢎⢏⣈⣉⣊⣋⣌⣍⣎⣏
⢐⢑⢒⢓⢔⢕⢖⢗⣐⣑⣒⣓⣔⣕⣖⣗⢘⢙⢚⢛⢜⢝⢞⢟⣘⣙⣚⣛⣜⣝⣞⣟
⢠⢡⢢⢣⢤⢥⢦⢧⣠⣡⣢⣣⣤⣥⣦⣧⢨⢩⢪⢫⢬⢭⢮⢯⣨⣩⣪⣫⣬⣭⣮⣯
⢰⢱⢲⢳⢴⢵⢶⢷⣰⣱⣲⣳⣴⣵⣶⣷⢸⢹⢺⢻⢼⢽⢾⢿⣸⣹⣺⣻⣼⣽⣾⣿
EOS
braille.gsub!("\n", '')
txt = `qrencode -t ASCII '#{STDIN.read}'`.lines.map { |line| line.chomp.chars.map { |c| c == ' ' ? 0 : 1 } }
unstripped_qr = txt.transpose.each_slice(2).map(&:first).transpose
margin_top = unstripped_qr.each.with_index { |content, ix| break ix unless content.uniq == [0] }
margin_bottom = unstripped_qr.reverse_each.with_index { |content, ix| break ix unless content.uniq == [0] }
margin_left = unstripped_qr.transpose.each.with_index { |content, ix| break ix unless content.uniq == [0] }
margin_right = unstripped_qr.transpose.reverse_each.with_index { |content, ix| break ix unless content.uniq == [0] }
qr = unstripped_qr[margin_top..-(margin_top + 1)].transpose[margin_left..-(margin_right + 1)].transpose
padded_qr = qr + [[0] * qr[0].size] * (4 - (qr.size % 4))
padded_qr.each_slice(4) do |rows|
rows.transpose.each_slice(2) do |block|
bnum = block.inject(:+).join.reverse.to_i(2)
print braille[bnum]
end
puts
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment