Better Parenting Time Exchanges with TRMNL

A couple of weeks ago I received my TRMNL order, and TRMNL promptly held a perfectly-timed hackathon for calendar-based plugins, lighting the proverbial fire under my behind to get me to write a plugin to show my kids how long until they go to their other parent’s house, and to give me a countdown until they’re back. While I didn’t win the hackathon, (check out the winners, they’re great), I continue to use and improve my little plugin with the goal of eventually turning it into a public recipe. I am certain there are plenty of parents out there in the same situation that I am, or who simply want to count down to other recurring calendar events.

A screenshot of the TRMNL device showing my private countdown plugin full screen.
This is what the full-screen version of my Calendar Countdown plugin looks like.

Things to Know When Coding for TRMNL

Debug JavaScript Right In Your Browser

TRMNL’s web-based coding environment is a bit weird, but it runs Javascript in the browser, which means that console.log statements appear in your browser’s dev tools.

Watch Out for the Time Zone!

When dealing with Date/Time in Javascript, the device’s timezone might not match your timezone. The user timezone data that supplied in the trmnl.user data should be used to set the appropriate timezone.

Events Not in Chronological Order

Sometimes calendar events don’t appear in chronological order in the data feed. I rectify this by running an Array.prototype.sort() on my array of interesting events once I have identified them.

Wishlist to make TRMNL Even Better

More Data Types for Settings

The ability to have a dictionary or object in settings, with a UI to set key-value pairs, would make it easier to have a list of events that are interesting to the plugin.

Improved Story for Local Development

While the online development system works, I would like a more robust system for local development. There is trmnlp, which is supposed to give a local development environment, but I was never able to get it up and running. I suspect that using trmnlp would allow me to put my Javascript into its own file, not have to copy the same Javascript into the HTML of all four of the layouts for my plugin.

A Great Inactivity Reminder

I was lucky enough to spend a good part of my summer vacation with my computer shut off, and my only internet connection on my phone, on Do Not Distrub mode. When I got back I had this E-mail from Rescuetime waiting for me.

A screenshot of the E-mail Rescuetime sent me when I was on vacation.

I love this part:

Hopefully, you were away from the computer having fantastic adventures! If not, then something might have gone wrong.

They didn’t immediately assume a problem, but left me a way to check on what’s going on in case I wasn’t “away from the computer having fantastic adventures.” It made me happy about my vacation, even after I was back and triaging E-mails.

The Apple App Store icon on my phone showing 71 updates available after my vacation.
Yes, seventy-one. There were more the next day.

Of course as soon as I got back on wi-fi this happened:, (do I have too many apps installed?):

Of course, there was also a lot of this:
A photo of a slightly smoky sunset over the ocean.

Show your Olympic Colours

I’ve turned johnbeales.com and @johnbeales red for the 2010 Olympic Games in Vancouver. Join me and do the same for your blog, Twitter profile, or both.

Look how awesome my twitter profile looks all decked out for the Vancouver games:
Vancouver 2010 Twitter theme

You can do the same. Here’s a ZIP file containing the PSD Source, and PNGs of both my Twitter background, (with the text), and the blog background, (without the text).

Go nuts, and let me know here or on Twitter about it!

Edit: Here are direct links to the backgrounds with text, and without text.

Endpoints: A little secret for URL manipulation in WordPress

Today I’ve been setting up WordPress as the News section of a website which loads its pages via AJAX requests whenever possible, but falls back on normal HTTP requests when the AJAX loads are not possible.

The when the AJAX requests are initiated from Javascript, /outputxml/ is added to the end of the URL. This gets translated, with some mod_rewrite magic, to a $_GET parameter called output. /outputxhtml is also possible but since that’s the default it doesn’t get used very much.

After, (mostly), building the WordPress theme I started testing, and as I expected I ran into some problems when /outputxml/ was added to the end of the WordPress URLs. I got 404 errors, which makes total sense. I thought I could get around this by simply doing a little extra mod_rewrite magic, however, it seems there’s not way to simply replace /outputxml somewhere in a url with an empty string using mod_rewrite alone. After some time, I stumbled upon an underdocumented WordPress function: WP_Rewrite::add_endpoint and its friend, add_rewrite_endpoint. These functions make it so that WordPress recognizes /category/post-name/trackback, and /category/post-name/outputxml. Excellent!

I just had to create a plugin, make sure that WordPress wouldn’t kill my $_GET[‘output’] variable, add 1 line to my .htaccess and I was good to go.

References:

And this is what my plugin looks like, (for educational purposes only. I am not distributing it):

function fourRS_outputxml_activate() {
    global $wp_rewrite;
    add_rewrite_endpoint('outputxml',array(EP_PERMALINK, EP_PAGES));
    add_rewrite_endpoint('outputxml',EP_ALL);       

    $wp_rewrite->flush_rules();
}
register_activation_hook( __FILE__, 'fourRS_outputxml_activate');


function fourRS_outputxml_deactivate() {
    global $wp_rewrite;
    $wp_rewrite->flush_rules();
}

register_deactivation_hook( __FILE__, 'fourRS_outputxml_deactivate');


/* Makes it so WP doesn't eat my nice $_GET variable */
function fourRS_parameter_queryvars( $qvars )
{
    $qvars[] = 'output';
    return $qvars;
}
add_filter('query_vars', 'fourRS_parameter_queryvars' );

Edit (August 25, 2009): Changed the attrbutes in the add_rewrite_endpoint() function.