Skip to content

Instantly share code, notes, and snippets.

@loneaggie
Created March 28, 2014 18:42
Show Gist options
  • Save loneaggie/9840016 to your computer and use it in GitHub Desktop.
Save loneaggie/9840016 to your computer and use it in GitHub Desktop.
Generates a Random String and deposits in a DB. Assumes columns of id,code with code having a unique index.
require 'sequel'
require 'pg'
class Grunt
def initialize(count,connpath)
@pool = (2..9).to_a + ('A'..'H').to_a
@choices = @pool.shuffle
@db = Sequel.connect(connpath)
@codes = @db[:codes]
@last_id = 0
end
def make_code()
code = Array.new(8){@choices.shuffle.sample}.join
return code
end
def insert_code(code)
begin
id = @codes.insert(code:code)
@last_id = id unless id.nil?
print "[#{@last_id || 'NIL'}]" if ((id % 1000 == 0) && (id != 0))
return @last_id
rescue Exception => e
print '[-D]'
end
end
def boom()
this_code = make_code()
return insert_code(this_code)
end
def get_count()
return @codes.count
end
def rumble()
puts "\nOrc SMASH!!\n-----------------------------\n"
while 1 do
result = self.boom()
if result && !result.nil? && result > 1800000
puts "\n\n--- ALL DONE!!! ----\n"
break
end
end
end
end
g = Grunt.new(500,'postgres://user:password@localhost:5432/randoms')
g.rumble()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment