Skip to content

Instantly share code, notes, and snippets.

@peterc
Last active February 27, 2019 13:03
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/bf495244dd098cdd7ddca241dab33446 to your computer and use it in GitHub Desktop.
Save peterc/bf495244dd098cdd7ddca241dab33446 to your computer and use it in GitHub Desktop.
Turns a11y-style text back into English. Or tries to, anyway.
# ruby s4d.rb "h3o w3d" 5
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
@peterc
Copy link
Author

peterc commented Feb 27, 2019

c1n y1u t2l w2t t2s s2s?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment