Last active
August 29, 2015 14:01
-
-
Save abachman/1e6e11188fd2eb123734 to your computer and use it in GitHub Desktop.
Deacronym
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
#!/bin/env ruby | |
# Usage: | |
# | |
# $ deacronym ASDF | |
# Attracted Shrinking Development Finish | |
# | |
# You'll need your own copy of Seasoning of Wood by J.B. Wagner | |
# http://www.gutenberg.org/ebooks/26598 | |
# lexicon = File.read(File.join ENV['HOME'], '/Documents/seasoning_of_wood.txt'). | |
# OR Wizard People, Dear Reader | |
# http://www.erikkennedy.com/wizardpeopledearreaders.html | |
lexicon = File.read(File.join ENV['HOME'], '/Documents/wizard_people.txt'). | |
split(/[^a-zA-Z']/). | |
# get rid of non-word characters | |
map {|w| w.downcase.gsub(/[^a-z']/, '')}. | |
# get rid of short words, they are not interesting | |
reject {|w| w.size < 4}. | |
sort. | |
uniq | |
lexicon_hash = {} | |
lexicon.each {|word| | |
lexicon_hash[word[0]] ||= [] | |
lexicon_hash[word[0]] << word | |
} | |
(ARGV[1] || 4).to_i.times do | |
puts ARGV[0].split('').map {|l| lexicon_hash[l.downcase].sample.capitalize}.join ' ' | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There's a hashtag generator in here somewhere....