Skip to content

Instantly share code, notes, and snippets.

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 scalabilitysolved/10593652 to your computer and use it in GitHub Desktop.
Save scalabilitysolved/10593652 to your computer and use it in GitHub Desktop.
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_location
lat = rand(-90.0...90.0)
lon = rand(-180.0...180.0)
location = []
location.push(lat.round(2))
location.push(lon.round(2))
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,
"location" => generate_location
}
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