06 Dec

Secret Santa Project

It’s the holiday season and that means you are buying a lot of gifts and probably along the way doing at least one gift exchange. Probably the most well known of these (at least here in the US) is Secret Santa.

My family does Secret Santa amongst ourselves and this year I decided to modernize it by writing a simple php script that would shuffle the names and emails and send an email to each person telling them who they had.

It all worked really well except for the emailing part, they kept going into the spam folder. So that was a bust.

Last night however I had some free time and I took that script and updated it into a quite nice and simple web app (and no longer do emails go into the spam folder).

You can try the code out at http://secret.yostivanich.com/ or download the whole package here.

Included in this package is unmodified versions of Blueprint CSS Framework and PHPMailer. The rest of code there is all mine and is under a href=”http://www.opensource.org/licenses/mit-license.php”>MIT License, essentially do whatever you want with my code.

I’ll work on a a couple of tutorials to walk though what I what did over the next few posts, till then have fun.

27 Jan

The Complex Made Simple

For work, I had a piece of code that needed to calculate if a certain date fell in between two other days. So I started out writing out this big long function to calculate if a date fell first within the same year as either of the two dates, and if so within the two months, and within the two days. It was ugly, inaccurate, complex and just plain stupid of me to do it that way.

I knew there had to be an easier way so off to PHP.net I went and sure enough there is strtotime. Strtotime converts a string into a Unix timestamp. Turning my function into this:

function in_between_two_dates($first_date, $second_date, $third_date)
if(strtotime($first_date) >= strtotime($second_date) && strtotime($first_date) <= strtotime($third_date) )
{ return true; }
else return false;

Remember when in doubt: KISS (Keep it simple stupid).