Created
August 22, 2010 04:17
-
-
Save chaserx/543296 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/local/bin/ruby -wKU | |
# R. Chase Southard | |
# chase [dot] southard [at-thang] gmail [dot] com | |
# @southard | |
# 8.21.10 | |
# from Code for America binary-art posters and shirt; http://codeforamerica.org/binary-art/ | |
# Donate to Code for America at http://codeforamerica.org/donate or http://codeforamerica.org/gear | |
# 01000011 01101111 01100100 01100101 00100000 01100110 01101111 01110010 00100000 01000001 01101101 01100101 01110010 01101001 01100011 01100001 | |
madison = "01010111 01100101 00100000 01110100 01101000 01100101 | |
00100000 01010000 01100101 01101111 01110000 01101100 | |
01100101 00100000 01101111 01100110 00100000 01110100 | |
01101000 01100101 00100000 01010101 01101110 01101001 | |
01110100 01100101 01100100 00100000 01010011 01110100 | |
01100001 01110100 01100101 01110011 00101100 00100000 | |
01101001 01101110 00100000 01001111 01110010 01100100 | |
01100101 01110010 00100000 01110100 01101111 00100000 | |
01100110 01101111 01110010 01101101 00100000 01100001 | |
00100000 01101101 01101111 01110010 01100101 00100000 | |
01110000 01100101 01110010 01100110 01100101 01100011 | |
01110100 00100000 01010101 01101110 01101001 01101111 01101110" | |
tj = "01010111 01100101 00100000 01101000 01101111 01101100 | |
01100100 00100000 01110100 01101000 01100101 01110011 | |
01100101 00100000 01110100 01110010 01110101 01110100 | |
01101000 01110011 00100000 01110100 01101111 00100000 | |
01100010 01100101 00100000 01110011 01100101 01101100 | |
01100110 00101101 01100101 01110110 01101001 01100100 01100101 | |
01101110 01110100 00101100 00100000 01110100 01101000 | |
01100001 01110100 00100000 01100001 01101100 01101100 | |
00100000 01101101 01100101 01101110 00100000 01100001 | |
01110010 01100101 00100000 01100011 01110010 01100101 | |
01100001 01110100 01100101 01100100 00100000 01100101 | |
01110001 01110101 01100001 01101100 00101110 00101110 00101110" | |
mlk = "01001000 01110101 01101101 01100001 01101110 00100000 01110000 01110010 01101111 01100111 01110010 | |
01100101 01110011 01110011 00100000 01101001 01110011 00100000 01101110 01100101 01101001 01110100 | |
01101000 01100101 01110010 00100000 01100001 01110101 01110100 01101111 01101101 01100001 01110100 | |
01101001 01100011 00100000 01101110 01101111 01110010 00100000 01101001 01101110 01100101 01110110 | |
01101001 01110100 01100001 01100010 01101100 01100101 00101110 00101110 00101110 00100000 01000101 | |
01110110 01100101 01110010 01111001 00100000 01110011 01110100 01100101 01110000 00100000 01110100 | |
01101111 01110111 01100001 01110010 01100100 00100000 01110100 01101000 01100101 00100000 01100111 | |
01101111 01100001 01101100 00100000 01101111 01100110 00100000 01101010 01110101 01110011 01110100 | |
01101001 01100011 01100101 00100000 01110010 01100101 01110001 01110101 01101001 01110010 01100101 | |
01110011 00100000 01110011 01100001 01100011 01110010 01101001 01100110 01101001 01100011 01100101 | |
00101100 00100000 01110011 01110101 01100110 01100110 01100101 01110010 01101001 01101110 01100111 | |
00101100 00100000 01100001 01101110 01100100 00100000 01110011 01110100 01110010 01110101 01100111 | |
01100111 01101100 01100101 00111011 00100000 01110100 01101000 01100101 00100000 01110100 01101001 | |
01110010 01100101 01101100 01100101 01110011 01110011 00100000 01100101 01111000 01100101 01110010 | |
01110100 01101001 01101111 01101110 01110011 00100000 01100001 01101110 01100100 00100000 01110000 | |
01100001 01110011 01110011 01101001 01101111 01101110 01100001 01110100 01100101 00100000 01100011 | |
01101111 01101110 01100011 01100101 01110010 01101110 00100000 01101111 01100110 00100000 01100100 | |
01100101 01100100 01101001 01100011 01100001 01110100 01100101 01100100 00100000 01101001 | |
01101110 01100100 01101001 01110110 01101001 01100100 01110101 01100001 01101100 01110011 00101110" | |
# should be made into an additional binary-art poster / shirt | |
obama = "00101110 00101110 00101110 01001001 01110100 00100000 01101000 01100001 01110011 00100000 01100010 01100101 01100101 01101110 00100000 01110100 01101000 01100101 00100000 01110010 01101001 01110011 01101011 00101101 01110100 01100001 01101011 01100101 01110010 01110011 00101100 00100000 01110100 01101000 01100101 00100000 01100100 01101111 01100101 01110010 01110011 00101100 00100000 01110100 01101000 01100101 00100000 01101101 01100001 01101011 01100101 01110010 01110011 00100000 01101111 01100110 00100000 01110100 01101000 01101001 01101110 01100111 01110011 00100000 00101101 00100000 01110011 01101111 01101101 01100101 00100000 01100011 01100101 01101100 01100101 01100010 01110010 01100001 01110100 01100101 01100100 00100000 01100010 01110101 01110100 00100000 01101101 01101111 01110010 01100101 00100000 01101111 01100110 01110100 01100101 01101110 00100000 01101101 01100101 01101110 00100000 01100001 01101110 01100100 00100000 01110111 01101111 01101101 01100101 01101110 00100000 01101111 01100010 01110011 01100011 01110101 01110010 01100101 00100000 01101001 01101110 00100000 01110100 01101000 01100101 01101001 01110010 00100000 01101100 01100001 01100010 01101111 01110010 00101100 00100000 01110111 01101000 01101111 00100000 01101000 01100001 01110110 01100101 00100000 01100011 01100001 01110010 01110010 01101001 01100101 01100100 00100000 01110101 01110011 00100000 01110101 01110000 00100000 01110100 01101000 01100101 00100000 01101100 01101111 01101110 01100111 00101100 00100000 01110010 01110101 01100111 01100111 01100101 01100100 00100000 01110000 01100001 01110100 01101000 00100000 01110100 01101111 01110111 01100001 01110010 01100100 01110011 00100000 01110000 01110010 01101111 01110011 01110000 01100101 01110010 01101001 01110100 01111001 00100000 01100001 01101110 01100100 00100000 01100110 01110010 01100101 01100101 01100100 01101111 01101101 00101110" | |
module Ascii_Binary | |
# PREVIOUS ITERATION | |
#def to_ascii(binary_str) | |
# binary_str.gsub(/\s/,'').gsub(/([01]{8})/) { |b| b.to_i(2).chr } | |
#end | |
#def to_binary(ascii_str) | |
#ascii_str.unpack('B*').first.to_s.split(/([01]{8})/).each { |e| out_str += " #{e}" } | |
# ascii_str.unpack('B*').to_s.split(/([01]{8})/).join(' ').gsub(/\s\s/, " ").gsub(/\A(\s)/,"") | |
#end | |
######## | |
# Ascii_Binary.to_ascii | |
# => String.to_ascii | |
# takes a string of bytes similar to http://codeforamerica.org/binary-art/ | |
# and transforms it into an ascii string. | |
# to_ascii code from http://snippets.dzone.com/posts/show/6897 | |
def to_ascii | |
self.gsub(/\s/,'').gsub(/([01]{8})/) { |b| b.to_i(2).chr } | |
end | |
# Ascii_Binary.to_binary | |
# => String.to_binary | |
# takes an ascii string and creates a string of bytes in the style of http://codeforamerica.org/binary-art/ | |
def to_binary | |
# ugh. WTF! this is ugly, but it fixes the whitespace formatting issue. | |
# unpack('B*') => extract bits from each character (msb first) for all in string #=> anArray | |
# make array a String. Split string by 8-bit bytes. Join by spaces. | |
# Remove duplicate spacing inside string. Remove duplicate spacing at beginning of line | |
self.unpack('B*').to_s.split(/([01]{8})/).join(' ').gsub(/\s\s/, " ").gsub(/\A(\s)/,"") | |
end | |
end | |
class String | |
# Mixin Ascii_Binary into String | |
include Ascii_Binary | |
end | |
# translate my shirt | |
puts madison.to_ascii | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment