So, last week I attended our monthly Atlanta PHP meet and had a good time. At the end of the session some prizes were awarded “randomly”. Why “randomly”? Because a member of the group wrote down two names on a piece of paper and started asking the other members for a number. The two to get the numbers correct won an award. Now, this was a quick last minute thing for fun, so I am definitely over engineering this – but hey, that’s what makes programming fun!

The problems were:

  • (and I apologize for my honesty in case any member that attended the event reads this) I could see the persons hand movement while writing down the numbers so I already knew one of the numbers before starting. 
  • The paper was lifted at some point before he started calling out for numbers and I could see the second number written on the paper.
  • It’s not truly random

After the event I went home inspired to create something. I wanted to create something that would be fun (don’t we all) and something that might be used. If I create something knowing it won’t get any use, I’ll lose interest fast and not finish. I started thinking about the event and the part that could be improved was the awarding of prizes so I decided to create something that would be more fair, truly random, and automated.

We use meetup.com to schedule events and RSVP for them. Our Atlanta PHP group at meetup.com has a calendar and I assume everyone else who uses their services has a calendar as well. Events are found in the calendar page with a link to the actual event page. In the event page (example of event for atlanta php), you can see the members who attended the event. Here is my assumption because I haven’t actually tested my theory yet. I assume that once the event starts, the list of RSVP and none attending members goes away and only the list of attending members stays.

Assuming my theory is correct, I can create a php page that will take in an event url as a parameter, gets the html for that page, searches for all members in that page, and spits out the list. Then I can pass another parameter for the number of prizes that need to be awarded from the list of members. The end result would be a list of all members who attended with another list of the random winners. This would solve the problems mentioned above and would be easy to use. Pass in an event url from the calendar page at the end of the meeting with a number of prizes and there you have your winners.

So after a few hours the page is done and here it is with a couple different uses:

http://www.joeyrivera.com/atlantaphp/prize.php

http://www.joeyrivera.com/atlantaphp/prize.php?event=http://www.meetup.com/atlantaphp/calendar/9110295/

http://www.joeyrivera.com/atlantaphp/prize.php?event=http://www.meetup.com/atlantaphp/calendar/9110295/&prizes=3

The first link loads all members of atlanta php in meetup.com. The second link loads the atlanta php members that attended the event defined by the event parameter. The last link does the same as the second link but shows a list of the 3 prize winners as well. At the bottom of each page you can click on download to get all the code. If anyone is interested in a technical explanation of what the page is doing feel free to ask here and I’ll write some more or add comments to the code. Maybe this will get me some comments!