Skip to content

Instantly share code, notes, and snippets.

@joeyrobert
Created December 15, 2010 01:45
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 joeyrobert/741506 to your computer and use it in GitHub Desktop.
Save joeyrobert/741506 to your computer and use it in GitHub Desktop.
spam.rb
# spam.rb - Creates spam logfiles from an example. Rates are approximate.
if ARGV[2] !~ /^\d+$/ || !File.exists?(ARGV[0])
puts "USAGE: ruby #{__FILE__} [source] [dest.] [rate in mb/s]"
puts "i.e.: ruby #{__FILE__} example.log spam.log 3"
exit
end
trap("INT") { exit }
source = ARGV[0]
destination = ARGV[1]
size = File.size(source)
rate = ARGV[2].to_i*1024*1024 # n kb/s
delay = size.to_f/rate
loop do
start_time = Time.now.usec
`cat #{source} >> #{destination}`
end_time = Time.now.usec
deduct = (end_time - start_time)/1000000.0
sleep(delay - deduct) if deduct < delay && deduct > 0.0
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment