Skip to content

Instantly share code, notes, and snippets.

@zorn
Created April 11, 2013 03:48
Show Gist options
  • Save zorn/5360589 to your computer and use it in GitHub Desktop.
Save zorn/5360589 to your computer and use it in GitHub Desktop.
Short ruby script to generate a random expenses csv file for demo.
require 'csv'
# Our sample categories
categories = []
categories << 'Advertising'
categories << 'Bank Fees'
categories << 'Computer Hardware'
categories << 'Computer Software'
categories << 'Conferences'
categories << 'Hosting'
categories << 'Legal and Prof. Services'
categories << 'Licenses'
categories << 'Mags/Pubs/Manuals'
categories << 'Office Space'
categories << 'Office Supplies'
categories << 'Phone'
categories << 'Travel'
# To help with random time
def time_rand from = 0.0, to = Time.now
Time.at(from + rand * (to.to_f - from.to_f))
end
# generate random expenses csv file
CSV.open("random-expenses.csv", "w") do |csv|
csv << ["Date","Cost", "Category"]
100.times do
random_category = categories.sample
random_date = time_rand Time.local(2012, 1, 1), Time.local(2012, 12, 31)
random_date_string = random_date.strftime "%Y-%m-%d"
random_cost = 1 + rand(10000)
csv << [random_date_string, random_cost.to_f/100, random_category]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment