I have put a bounty on this question, and a bunch of useful answers have popped up since I added the bounty.
Unfortunately the original asker doesn't seem to be checking out the new answers, and the nature of the question is such that the original asker has to try out the answers to see which one (if any) works. I can't try it out myself because you need more code than is given in the question.
If OP doesn't show back up, who should I award the bounty to? What are we supposed to do in this situation?