Skip to content

Instantly share code, notes, and snippets.

@crux
Created July 12, 2012 08:13
Show Gist options
  • Select an option

  • Save crux/3096614 to your computer and use it in GitHub Desktop.

Select an option

Save crux/3096614 to your computer and use it in GitHub Desktop.

Revisions

  1. crux created this gist Jul 12, 2012.
    47 changes: 47 additions & 0 deletions hostnamr.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    #!/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