Skip to content

Instantly share code, notes, and snippets.

@0x0dea
Last active October 1, 2015 20:10
Show Gist options
  • Save 0x0dea/f86200e2c12a9f30f93e to your computer and use it in GitHub Desktop.
Save 0x0dea/f86200e2c12a9f30f93e to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
#/ Usage: mnemo [filename]
#/
#/ Options:
#/ -h, --help Show this help message
#/ -v, --version Show application version
VERSION = "1.0.1"
LETTER_MAP = {
"A" => %w"A a @ 4", "B" => %w"B b 8 }",
"C" => %w"C c < ( [ {", "D" => %w"D d )",
"E" => %w"E e 3 {", "F" => %w"F f",
"G" => %w"G g 9 6", "H" => %w"H h #",
"I" => %w"I i ! ; : | 1", "J" => %w"J j ;",
"K" => %w"K k", "L" => %w"L l | 1",
"M" => %w"M m", "N" => %w"N n ^ ~",
"O" => %w"O o 0 .", "P" => %w"P p ?",
"Q" => %w"Q q 9", "R" => %w"R r",
"S" => %w"S s $ 5", "T" => %w"T t 7 + %",
"U" => %w"U u V v", "V" => %w"V v U u /",
"W" => %w"W w", "X" => %w"X x, *",
"Y" => %w"Y y /", "Z" => %w"Z z 2 %"
}
LETTER_MAP.default_proc = -> h, k { k }
WORD_MAP = {
"FOR" => "4", "YOU" => "U",
"WHY" => "Y", "SEE" => "C",
"OK" => "K", "TO " => "2",
"TOO" => "2", "ARE" => "R",
"ATE" => "8", "STAR" => "*",
"THE" => "D", "AND" => "N",
}
nums = %w"ZERO ONE TWO THREE FOUR FIVE SIX SEVEN EIGHT NINE"
WORD_MAP.update nums.zip(?0..?9).to_h
WORD_MAP.default_proc = -> h, k { k }
def slangify(sentence)
sentence.gsub(/\w+/, WORD_MAP)
end
def to_acronym(sentence)
sentence.scan(/\b\w/).join
end
def generate(acronym)
leet = LETTER_MAP.values_at *acronym.chars
leet.shift.product(*leet).map(&:join)
end
#==================================
# Main
#==================================
def usage(stream = $stderr, status = 0)
stream.puts File.readlines(__FILE__).
grep(/^#\//).map { |line| line.sub(/^#. ?/, '') }
exit status
end
def version(status = 0)
puts VERSION
exit status
end
sentence = ''
if ARGV.include?("-h") or ARGV.include?("--help")
usage
elsif ARGV.include?("-v") or ARGV.include?("--version")
version
elsif file = ARGV.shift
sentence = File.read(file)
else
usage
end
acronym = to_acronym(sentence.upcase)
s = generate(acronym)
puts s
slang = slangify(sentence.upcase)
leet = to_acronym(slang)
t = generate(leet)
puts t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment