Skip to content

Instantly share code, notes, and snippets.

@l1x
Created February 2, 2011 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save l1x/808530 to your computer and use it in GitHub Desktop.
Save l1x/808530 to your computer and use it in GitHub Desktop.
generating test.yml
require 'rubygems'
require 'bcrypt'
require 'digest/md5'
require 'yaml'
#todo
# load schema.rb
# t.string "username", :limit => 30
# t.string "email"
# t.string "password_hash"
# t.string "password_salt"
# t.string "reset_password_token"
# t.string "signature"
# t.boolean "active", :default => true
# t.integer "karma", :default => 0
# t.integer "sign_in_count", :default => 0
# t.integer "sign_in_failed", :default => 0
# t.string "last_sign_in_ip"
# t.datetime "created_at"
# t.datetime "updated_at"
class NohupYamlWriter
def write(filename, hash)
File.open(filename, "w") do |f|
f.write(hash.to_yaml)
end
end
def gen_data(size)
hash = {}
(1..size).each { |i|
salt = BCrypt::Engine.generate_salt
pass = BCrypt::Engine.hash_secret("miez", salt)
user = Digest::MD5.hexdigest(i.to_s)
hash[i] = {
:username => user,
:email => "cigany@vagy.ok",
:password_salt => salt,
:password_hash => pass,
:reset_password_token => "asd",
:signature => "I am generated by a script",
:active => true,
:karma => 5,
:sign_in_count => 2,
:sign_in_failed => 2,
:last_sign_in_ip => "127.0.0.1",
:created_at => Time.now,
:updated_at => Time.now
}
}
return hash
end
end
begin
nyw=NohupYamlWriter.new
nyw.write("test.yml", nyw.gen_data(10))
rescue => e
p "We fucked up, Huston" + e.inspect
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment