Created
September 21, 2013 00:47
-
-
Save pythonesque/6645817 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
require 'uri' | |
require 'set' | |
urls = Set.new() | |
STDIN.each_line do|line| | |
begin | |
url = URI.parse(line.downcase).host | |
unless urls.member?(url) | |
[url, "www.#{url}"].each do |url| | |
urls.add(url) | |
STDOUT.puts (url) | |
end | |
end | |
rescue URI::InvalidURIError | |
STDERR.puts "Invalid URI: #{line}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment