Skip to content

Instantly share code, notes, and snippets.

@jphastings
Created September 4, 2018 17:18
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 jphastings/9cdf994e9bc713a8f0f1274b386631eb to your computer and use it in GitHub Desktop.
Save jphastings/9cdf994e9bc713a8f0f1274b386631eb to your computer and use it in GitHub Desktop.
Need a port number for your service that's unlikely to clash with other services and easy to remember? Try mkport!
#!/usr/bin/env ruby
port = ARGV[0].downcase.split(//).reduce(0) do |sum, char|
sum * 10 + case char
when *%w[a b c] then 2
when *%w[d e f] then 3
when *%w[g h i] then 4
when *%w[j k l] then 5
when *%w[m n o] then 6
when *%w[p q r s] then 7
when *%w[t u v] then 8
when *%w[w x y z] then 9
end
end
while port < 1024
port *= 10
end
abort "Try a shorter string" if port > 65535
puts port
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment