AmigoSecreto.rb
Using part of our research time
, Victor and I developed a very small script to play the “Amigo Secreto” (Secret Friend) game here at the PLEIAD Lab. Following is the Ruby code (we used this snippet for the email-sending function).
require 'net/smtp' def send_email(from, from_alias, to, to_alias, subject, message) msg = <<end_OF_MESSAGE From: #{from_alias} <#{from}> To: #{to_alias} <#{to}> Subject: #{subject} #{message} END_OF_MESSAGE Net::SMTP.start('dcc.uchile.cl') do |smtp| smtp.send_message(msg, from, to) end end def randomize(hash) k = hash.keys hash.keys.each_index{ |idx| pos = idx + (rand() * (k.length - idx - 1)).ceil; tmp = k[idx] k[idx] = k[pos] k[pos] = tmp } rhash = {} hash.keys.each_index{ |idx| rhash[k[idx]] = hash[hash.keys[idx]]; } rhash end users = { "vramiro@dcc.NOSPAM.uchile.cl" => "Victor", "rtoledo@dcc.NOSPAM.uchile.cl" => "Rodolfo", "etanter@dcc.NOSPAM.uchile.cl" => "Eric", "gpothier@dcc.NOSPAM.uchile.cl" => "Guillaume", "pleger@dcc.NOSPAM.uchile.cl" => "Paul", "cvairett@dcc.NOSPAM.uchile.cl" => "Carla", "jfabry@dcc.NOSPAM.uchile.cl" => "Johan"} randomize(users).each_pair{ |mail,name| msg = <<end_OF_MESSAGE Tu super amig@ secret@ es: #{name} END_OF_MESSAGE send_email("pleiad@dcc.uchile.cl","PLEIAD Lab", mail,"", "[PLEIAD] Amigo Secreto", msg) }
4 Comments so far
Leave a reply
Remeber to obscure the emails!
Woot, I will cetrnaily put this to good use!
Is it alright to insert part of this in my personal site if I submit a reference to this web site?
Sure, use all the information you need!