PHP: Get date for nth occurrence of weekday

I looked quickly and did not see any code out there to determine the nth occurrence of a specific day of the week in a month.  For example Thanksgiving is the 4th Thursday in November.  So I designed the following

<?php
$year = 2012;
//Pick your year
$interval = 4;
//Week number, in this case the 4th week
$dayofweek = 4;
//Day of week 0=Sun, 1=Mon. . .
$month = 11;
//Month 1=Jan, 2=Feb

$firstday = jddayofweek(gregoriantojd($month, 1, $year), 0);
if($firstday <= $dayofweek){
  $date = (($interval * 7)-6) + ($dayofweek - $firstday);
}else{
  $date = (($interval * 7)-1) + (6 - $firstday);
}
echo date("n/j/Y", mktime(0, 0, 0, $month, $date, $year));
?>

It looks a little messy, but it works perfectly.

 

UPDATE:

So apparently as bad as this looks it works too:

Continue reading

Posted in Programming | Leave a comment

Integrating Google Talk with Roundcube

Sorry I don’t have much time at the moment to write up a whole entry about this, but I am very excited about this.

I am a big fan of roundcube but I have always wanted the ability to integrate some instant messaging into it.  Well google finally released a gtalk gadget that allows you to integrate gtalk/gchat into any page you want.  Although, google has done a very poor job of announcing this and I don’t think most people know about it.

Anyways, it is a very simple single line <iframe> code.  I just quickly added it to the roundcube template and made a few changes to the CSS code and it works perfectly.

Click the image above to see a larger screen shot.  I will write up the code for this later when I have some free time.

Posted in Programming | 1 Comment

How to Resurrect Procmail and Spamassassin on Dreamhost

Admittedly I have been very annoyed with Dreamhost since they announced that users would no longer be able to use procmail.

How to get procmail Back

After reading the most recent entry I realized that it is possible to still use both procmail and spamassassin.  However, this solution is not elegant.

Currently Dreamhost has a rudimentary Mail Filter system that is accessible by all mail users.  This system is due to be upgraded soon.  Dreamhost also allows regular shell users to access and run procmail as well as spamassassin.  In fact, shell users can install their own custom install of spamassassin.  Lastly, shell users can also receive email, although there is no imap or pop service for this mail.

Continue reading

Posted in Programming | 3 Comments

Bug in BlackBerry Repeat Rule, MONTH_OF_YEAR Deincrements 1 Month

I have noticed a bug in javax.microedition.pim.RepeatRule, when I tried to set a an event to repeat every second sunday of may I would get an event that repeated every second sunday of april. I determined that this was being caused by MONTH_OF_YEAR being deincremented by 1 month after the event was committed.

I worked around the problem by setting the value one month forward. However obviously, this does not work for december. I tried increasing the value of the MONTH_OF_YEAR setting, however java balks at any unknown value. Currently I am unable to set an event to occur on the second sunday in december. If anyone figures out a work around I would be greatful.

RIM has recognized that this is a bug, but who knows when the bug will be fixed. I attached a copy of the email I received from RIM:

Continue reading

Posted in Blackberry, Programming | Leave a comment

Improved Funambol Blackberry Plugin

As promised I made significant improvements to the Funambol Blackberry Client, while the improvements are geared towards better functionality with ScheduleWorld.com, they should benefit individuals who use other SyncML servers as well.

The Improvements in 3.0.8.4 include:

  • Ignore milliseconds in date, fixes duplication on
    slowsync
  • Properly display entities such as quotes and ampersands
  • Allday events now show up on week and month view
  • Multiday Allday events are no longer short one day
  • All day events no longer duplicate on SlowSync
  • Accept basic ISO 8061 dates
  • Fixed error message that popped up whenever sending an email
  • Removed configuration section relating to email since Schedule World does not support email
  • Altered default settings in configuration to match Schedule World settings
  • Added AutoSync Feature - The client will query the server for changes every X hours.

Continue reading

Posted in Blackberry, Programming | 5 Comments

Fix for Sending Email with Funambol and Schedule World

Those of us without a Blackberry Enterprise Server cannot automatically synchronize our calendar and contacts with our PC without directly pluging the Blackberry directly into the PC with a USB cable. This is where Funambol and ScheduleWorld come in. ScheduleWorld is a SyncML server, basically a Calendar and Contacts server. Funambol is an open source SyncML client for the blackberry. By using both of these programs you can sync your calendar and contacts to your PC over the air, without directly connecting your Blackberry to your PC. There are numerous tutorials for how to set this sytem up so I won’t waste your time discussing it here.

However, the Funambol ScheduleWorld setup has had one main issue for over a year. The problem stems from the fact that Funambol also allows for the synchronization of email while ScheduleWorld does not. Funambol allows users to unselect mail from synchronization. But even with mail unchecked Funambol still does some check of the mail which causes an error. Currently users will get the following error when sending an email:

Sorry you can't synchronize "mail", because the name of the Remote Mail in the Funambol configuration panel mismatches the corresponding name on the server.

Users then had to select "resend" to force their email to send. Needless to say the whole process was very annoying. Funambol is an open source project so I decided to take a look.

Continue reading

Posted in Blackberry, Programming | 1 Comment

Blackberry IMAP Proxy – Working Sent and Trash Folders

RIM has never fully supported IMAP servers in their Blackberry Internet Service(BIS) formerly Blackberry Web Client(BWC). Notably BIS does not recognize the NAMESPACE command from IMAP servers. The vast majority of IMAP servers place all user folders in a single parent folder(usually INBOX) therefore the Sent and Trash folders are actually INBOX.Sent and INBOX.Trash. Unfortunately BIS only recognizes Sent and Trash in the base directory.

This script sits between the BIS and your IMAP server. The proxy then makes INBOX.Sent and INBOX.Trash appear to be Sent and Trash. This enables BIS to save a copy of your sent emails into INBOX.Sent properly and a copy of deleted emails into INBOX.Trash properly.

Additionally this script allows you to use a non standard folder as your inbox as well.

Continue reading

Posted in Blackberry, Programming | 10 Comments

TiVo Central for Mobile Devices

TiVo Central Online is pretty cool, it allows you to program your TiVo to record an upcoming show or season pass from the interent. I wanted to be able to access TiVo Central anywhere I went, unfortunately TiVo Central is not available for Mobile devices. So I decided to whip up a quick PHP script to parse TCO and repaginate it into a mobile friendly html site. This is all accomplished in 480 lines of php code. The script allows for searching of upcoming shows by title, description, or cast members. After searching you can select the specific showing and record it using a one time or season pass recording. Additionally the script allows access to all advanced recording options and will send you an email to confirm the recording.
Continue reading

Posted in Programming, TiVo | Leave a comment

Gallery2 Picasa XML Import Hack

I have always been a fan of the Gallery program. You can see my pictures here

. I have also sporadically used Picasa2 from Google. While I thought Picasa2 was a nice free product, I never really had much use for it. However recently a few new features in Picasa2 have gotten my attention.

Notably Picasa2 allows for an XML export of an album, this export can even be directly uploaded by FTP to a web server. (Tools->Expiremental->Publish via FTP . . . then select XML as the page type). Then I found out that one of the modules available for gallery2 allows for a direct import of Picasa2 XML pages. Picasa Module. I tried it out and it worked as promised.

However, I found one error. If you do not enter a caption Picassa will automatically copy the
itemName into the itemCaption field. Personally if I don’t enter a
caption on a photo, I would prefer it remain un-captioned. So I hacked the module to fix this issue.

Continue reading

Posted in Programming | 1 Comment

Patio Plant Watering System

I want to have plants on my balcony, but I knew I would be incapable of watering the plants everyday. Clearly I needed an automatic watering system, however, I live on the 5th floor and have no access to water on my patio.

I saw an automatic watering system like this. But it was just too much money and it didn’t hold nearly enough water. So, I decided to make my own watering system that could hold a lot more water. I was able to make a 5 gallon system for less than $30.

Continue reading

Posted in Constructing | Leave a comment