Skip to content

Instantly share code, notes, and snippets.

@anvyst
Last active August 29, 2015 13:57
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 anvyst/9637022 to your computer and use it in GitHub Desktop.
Save anvyst/9637022 to your computer and use it in GitHub Desktop.
A quick script for fast conversion of punycode from/to ascii and unicode
#!/usr/bin/env ruby -w
require 'simpleidn'
require 'getoptlong'
opts = GetoptLong.new(
[ '--help', '-h', GetoptLong::NO_ARGUMENT ],
[ '--unicode', '-u', GetoptLong::REQUIRED_ARGUMENT ],
[ '--ascii', '-a', GetoptLong::REQUIRED_ARGUMENT ]
)
opts.each do |opt, arg|
case opt
when '--help'
puts "For converting to punycode use --ascii [parameter]"
puts "For converting to unicode use --unicode [parameter]"
puts "Example: punycode --ascii пипец.рф"
when '--unicode'
puts "Result: #{SimpleIDN.to_unicode(arg)}"
when '--ascii'
puts "Result: #{SimpleIDN.to_ascii(arg)}"
else
puts "Call up for --help, you're getting crazy!"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment