Skip to content

Instantly share code, notes, and snippets.

@darwin
Created September 27, 2010 19:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darwin/599631 to your computer and use it in GitHub Desktop.
Save darwin/599631 to your computer and use it in GitHub Desktop.
The first crash reports lottery for TotalFinder
#!/usr/bin/env ruby
# http://blog.binaryage.com/winners-crash-reports-lottery
require 'rubygems'
require 'gmail'
unless ENV["GMAIL_PASSWORD"] then
puts "setenv GMAIL_PASSWORD pls!"
exit 1
end
srand 8887 # http://twitter.com/blubalu/status/25711610348
$count = 0
$winners = Hash.new
def draw(box, file, num)
total = box.count
while $count < num do
choice = rand(total)
person = box.emails[choice].from.to_s
if $winners[person] then
puts "ah, picked #{person.strip} again, skipping..."
next
end
# correctly I should remove the item from the pool,
# but I cannot do that with gmail because I don't want to delete the email or move it,
# I think this setup is ok for our case of drawing 64 from 11k+ items
$count += 1
$winners[person] = true
# anonymize display email
name, server = person.split('@')
parts = server.split('.')
domain = parts.pop
server = parts.join('.')
name.gsub!(/./, "*")
server.gsub!(/./, "*") if server!='gmail' and server!="googlemail" and server!="yahoomail" and server!="hotmail" and server!="mac"
# for blog post
puts "#{sprintf("%02d", $count)}. ##{sprintf("%05d", choice)} #{name}@#{server}.#{domain}"
# for gmail message
file << person + ", "
end
end
File.open("winners.txt", "w") do |file|
# I needed to split connection to gmail into two runs, there is a bug in the ruby-gmail library and gmail rejects connection after 50 requests
Gmail.new("antonin.hildebrand", ENV["GMAIL_PASSWORD"]) do |gmail|
crashbox = gmail.mailbox('Crashes')
puts "#{`ruby --version`.chop}"
puts "total #{crashbox.count} crash reports (#{`date -u`.chop})"
puts "-----"
draw(crashbox, file, 32)
end
Gmail.new("antonin.hildebrand", ENV["GMAIL_PASSWORD"]) do |gmail|
crashbox = gmail.mailbox('Crashes')
draw(crashbox, file, 64)
end
end
# just a sanity check...
puts "-----"
puts "cat winners.txt | wc -w"
system("cat winners.txt | wc -w")
ruby 1.8.7 (2010-06-23 patchlevel 299) [i686-darwin10]
total 11380 crash reports (Mon Sep 27 19:05:40 UTC 2010)
-----
01. #04470 ****@******.us
02. #05941 ****@**********.com
03. #10773 ********@gmail.com
04. #07946 *******@******.com
05. #04688 ******@*********.nl
06. #03893 ******@******.ru
07. #00374 *************@gmail.com
08. #00337 ********@gmail.com
09. #04914 ***@******************.com
10. #09905 ************@gmail.com
11. #02243 *******@gmail.com
12. #08299 *******@**********.com
13. #07856 **********@*****.it
14. #01727 ****************@googlemail.com
15. #07299 ****************@***********.ch
16. #01846 ***********@***.de
17. #10692 *********@*****.com
18. #08631 *******@gmail.com
19. #11209 *******@hotmail.com
20. #01635 ******@**********.com
21. #07795 ******@***********.nl
22. #09360 **********@gmail.com
23. #11022 *******@gmail.com
24. #02362 *********@**.com
25. #08778 ***************@**.com
26. #08112 **********@gmail.com
27. #07326 *********@****.dk
28. #04991 ****@*******.com
29. #07439 **********@*******.nl
30. #05867 ***@*****.com
31. #07939 ********@*******.net
32. #09680 *****@*******.net
33. #03914 ************@gmail.com
34. #08030 *******@gmail.com
35. #02222 ********@*****************.at
36. #09093 ************@gmail.com
37. #04656 **************@**.com
38. #02429 *******@*******.de
39. #04854 *******@***********.br
40. #06507 ***@*****.com
41. #01739 ********@gmail.com
42. #10809 ***********@*******************.com
43. #09357 ********@gmail.com
44. #09974 *****@***.de
45. #03681 ************@**.com
46. #07989 *********@*********.net
47. #08420 *****@mac.com
48. #06056 ****@******************.com
49. #10050 ********@mac.com
50. #00533 *****************@gmail.com
51. #05393 ***********@gmail.com
52. #08885 *******@*********.com
53. #09179 *******@*******.edu
54. #05683 ****@**********.com
55. #04868 ****************@gmail.com
56. #04550 *******@****************.com
57. #04911 ***************@**********.net
58. #04404 **********@**.com
59. #02574 *****@*****.com
60. #04021 ***********@gmail.com
61. #10956 **********@gmail.com
62. #08801 ***********@*******.com
63. #01210 **********@*****.com
64. #11244 ****@*************.au
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment