Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'json'
require 'securerandom'
require 'couchbase'
couchbase = Couchbase.connect(:bucket => "users",:hostname => "localhost")
def generate_offers
offers = ['324-567-343','888-756-343','343-645-121','691-809-507','192-343-572','298-897-673']
number_of_offers = rand(1..3)
selected_offers = []
number_of_offers.times do
offer = rand(0..5)
selected_offers.push(offers[offer])
end
selected_offers
end
def generate_user
countries = ['USA','GB','FR','ES','PO','BR','RU']
now = Time.now
a_week_ago = now - 60 * 60 * 24 * 7
random_time = rand(a_week_ago..now)
user = {
"id" => SecureRandom.urlsafe_base64(16),
"doc_type" => "user",
"join_date" => random_time.utc,
"last_active" => rand(random_time..now),
"number_of_visits" => rand(1..5000),
"origin" => countries.sample,
"offers" => generate_offers
}
end
1000.times do
user = generate_user
id = user["id"]
couchbase.set(id,user)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.