Skip to content

Instantly share code, notes, and snippets.

@peterc
Created July 13, 2021 14:20
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 peterc/72c5759f903e8b2ce1fb08226c66f2d4 to your computer and use it in GitHub Desktop.
Save peterc/72c5759f903e8b2ce1fb08226c66f2d4 to your computer and use it in GitHub Desktop.
Convert abbreviated text like i18n and l11n to full text
text = ARGV.first || "y1u a5t p1l? j2t w4d to s1y hi"
times = (ARGV[1] || 1).to_i
words = File.readlines('/usr/share/dict/words')
.map(&:downcase)
.map(&:chomp)
times.times do
puts text.gsub(/\w+/) { |word|
words.select { |realword|
realword.start_with?(word[0]) &&
realword.end_with?(word[-1]) &&
realword.length == word[1..-2].to_i + 2
}.sample
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment