Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Wednesday, November 14, 2012

Days of a Month

Here's a little something that's useful. Just give me some credit for putting it together. Syntax is in Java, but it should be translatable to your favorite language.

Given the month number, m [1, 12], and the 4-digit year, this calculates the days of the month.

return m != 2 ? (((m < 8 && m % 2 != 0) || (m > 7 && m % 2 == 0)) ? 31 : 30) : (!(year % 400 == 0 || year % 100 != 0 && year % 4 == 0) ? 28 : 29);

Monday, October 18, 2010

Send email using Gmail as a free SMTP with Java Mail

This has bugged me forever. No more!



This can be simplified to be tested with a Linux sendmail server or Apache James on Windows. Just make sure you test this on a network that won't block your test calls otherwise you'll go crazy trying to debug and won't find a problem in your code or configuration. Also make sure to poke the right holes through your firewall.