Skip to content

Instantly share code, notes, and snippets.

@mjstrasser
Created July 6, 2014 05:28
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 mjstrasser/13d55c3d1ae3417887f5 to your computer and use it in GitHub Desktop.
Save mjstrasser/13d55c3d1ae3417887f5 to your computer and use it in GitHub Desktop.
Pimp it hard: Ruby script to pummel http://pimpmylight.catchpole.net/ a number of times, using random colour choice and random delays between messages.
# Run Pimp My Light for a while
require 'httparty'
COLOURS = [:red, :orange, :green]
PML_URL = 'http://pimpmylight.catchpole.net/?update=%s'
TOTAL = ARGV.length > 0 ? ARGV[0].to_i : 5
COUNTS = { red: 0, orange: 0, green: 0, except: 0 }
def pimp(colour)
HTTParty.get PML_URL % colour.to_s
rescue Exception => e
puts "Oops! #{e.message}"
COUNTS[:except] += 1
end
def pimp_away
puts "Pimping #{TOTAL} times"
1.upto(TOTAL) do |i|
delay = Random.rand(2.5)
colour = COLOURS.sample
COUNTS[colour] += 1
puts '%6d: %5.2fs, %s' % [i, delay, colour]
sleep(delay)
pimp colour
end
end
if $0 == __FILE__
pimp_away
puts "Pimped #{COUNTS[:red]} red, #{COUNTS[:orange]} orange, #{COUNTS[:green]} green & #{COUNTS[:except]} exceptions"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment