Skip to content

Instantly share code, notes, and snippets.

@crux
Created July 12, 2012 08:13
Show Gist options
  • Save crux/3096614 to your computer and use it in GitHub Desktop.
Save crux/3096614 to your computer and use it in GitHub Desktop.
random concatenation of syllables to get speakable but senseless hostnames
#!/usr/bin/env ruby
Hiragana = %w{
a i u e o
ka ki ku ke ko
sa shi su se so
ta chi tsu te to
na ni nu ne no
ha hi hu he ho
ma mi mu me mo
ya yu yo
ra ri ru re ro
wa o
n
}
class Hash
# _why's hash implant with a twist: throws a NoMethodError instead
# returning nil for non-existing keys
def method_missing(m,*a)
if m.to_s =~ /=$/
self[$`.to_sym] = a[0]
elsif a.empty?
self[m]
else
raise NoMethodError, "#{m}"
end
end
end
Defaults = {:count => 3, :join => '-'}
def doit para = nil
para = Defaults.merge(para || {})
#puts "syllables count: #{para.count}"
(0..para[:count]-1).to_a.map {Hiragana[rand(Hiragana.length)]}.join(para.join)
end
def usage
puts "usage: #{$0} [ <syllable count> ]"
exit
end
if __FILE__ == $0
syllable_count = Integer(ARGV[0] && ARGV.shift.to_s || 3) rescue usage
join = ARGV.shift || Defaults.join
puts "#{doit :join => join, :count => syllable_count}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment