Skip to content

Instantly share code, notes, and snippets.

@adrianpike
Created January 12, 2010 20:09
Show Gist options
  • Save adrianpike/275555 to your computer and use it in GitHub Desktop.
Save adrianpike/275555 to your computer and use it in GitHub Desktop.
#hat tip @bear454
require 'rubygems'
require 'uri'
require 'resolv'
def ip_to_color(ip,alpha = false)
segments = ip.split('.').collect{|s| s.to_i.to_s(16).rjust(2,'0') }
segments.pop unless alpha
segments.join('')
end
def host_to_color(host)
u = URI.parse(host)
ip_to_color(Resolv.getaddress(u.host))
end
p ip_to_color('127.0.0.1')
p host_to_color('http://google.com/')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment