Yesterday I Learned

Yesterday I learned that when my 2001 Ford Mustang is running, the key fob is disabled and will not let you lock or more importantly unlock the car doors. I started up the car in order to warm up the cabin, took the key fob off my keyring, and then locked the door behind me. I was only going to be a few car lengths away from it but I didn’t want anyone hopping in it and stealing it. This turned out to be a huge mistake. One call to AAA and 45 minutes of car idling later, they showed up to jimmy a door open for me so I could turn it off. 🙁

Interestingly my dad’s Ford Explorer, which is only a few years newer than my car and shares many common Ford parts, doesn’t do the same thing. It’s key fob works perfectly fine with the engine running. Hmm.

How To Create Custom WordPress Cron Intervals

This is mostly a reminder for myself so I can stop tracking it down every time I forget, but here’s how to have WordPress code execute on a different schedule than the default intervals of hourly, twicedaily, and daily. This specific example is for weekly execution.

[code lang=”php”]<?php

// Add a new interval of a week
// See http://codex.wordpress.org/Plugin_API/Filter_Reference/cron_schedules
add_filter( ‘cron_schedules’, ‘myprefix_add_weekly_cron_schedule’ );
function myprefix_add_weekly_cron_schedule( $schedules ) {
$schedules[‘weekly’] = array(
‘interval’ => 604800, // 1 week in seconds
‘display’ => __( ‘Once Weekly’ ),
);

return $schedules;
}

// Schedule an action if it’s not already scheduled
if ( ! wp_next_scheduled( ‘myprefix_my_cron_action’ ) ) {
wp_schedule_event( time(), ‘weekly’, ‘myprefix_my_cron_action’ );
}

// Hook into that action that’ll fire weekly
add_action( ‘myprefix_my_cron_action’, ‘myprefix_function_to_run’ );
function myprefix_function_to_run() {
// Add some code here
}

?>[/code]

On a side note, I believe this must go in a plugin and not your theme’s functions.php which I hear loads too late.

Help Me Name My Latest Plugin

I’m having trouble coming up with a good name for my latest WordPress plugin so I thought I’d crowd source it. 🙂

My other WordPress-powered site, FinalGear.com, receives very large traffic spikes. I used to just run WP Super Cache to prevent the site from going down but Apache would still actually die under the load even though it was just serving static content. Since the site has no comments or other often changing content, the easiest solution at the time was just to throw a reverse proxy called Varnish in front it with a decent cache time (5-10 minutes per page). I’ve since switched from Apache to nginx which solves that issue but it’s still easiest to just leave Varnish there.

Varnish is set up to ignore cookies on the front end of the site. That means I get served the exact same version of the site that you (a guest) sees — no admin bar, no post edit links, and so forth. Getting to the admin area is easy thanks to an absolutely positioned hidden link in the bottom left of the site (hover over it, you’ll find it) so lack of an admin bar is no problem for me.

What is a problem though is the lack of easy way to edit a post. I currently have to go into the admin area and then browse to the post in order to edit it. So I wrote a plugin that outputs the edit post link even for people who aren’t logged in. However the link is hidden using CSS and then re-shown using Javascript only if you have a logged in cookie.

It works perfect but what to call it? My working title was “Javascript Edit Links” but that seems so bland and locks me a bit into a corner. What if I someday want to add other features to the plugin, such as even showing the full admin bar? Do you have any better ideas?

New SSD Drives

Two Intel 320 series 160GB SSD drives that will be going into my PC this weekend in RAID 0 to replace my two existing Western Digital 640GB Black series drives in RAID 0. Should be quite the speed improvement!

I got them on sale for $155 each instead of the regular price of $285 each. Gotta love Cyber Monday weekend deals.

UPDATE: These things are amazingly fast!

My new SSD RAID:

For comparison, here is my old RAID:

Lastly, a normal Western Digital 2TB Green (energy saving) drive that is very commonly used for cheap (not fast) storage:

Crazy, huh?

Two Handy Sublime Text 2 Plugins

After using EditPlus for the better part of a decade, I made the switch to the totally awesome Sublime Text 2 text editor a few weeks back. One of the great things about Sublime is it’s support for plugins.

Two such plugins I’d like to recommend are SublimeBrackets and SublimeTagmatcher. Both improve how the highlighting of opening and closing items are handled.

By default, Sublime just underlines paired brackets. When you have a ton of code, this can be really hard to see. SublimeBrackets changes this to something more apparent:

Much better, right? I personally use the solid background green style.

SublimeTagmatcher does something similar but for HTML tags. When you have your cursor inside of an HTML tag, it will highlight both the current tag and it’s opening or closing counterpart. This is helpful for making sure you have the correct number of opening and closing tags.

New Computer Table From IKEA

Among the many things I bought from IKEA over the weekend was a new computer table. With some help from my dad who dropped by this evening, we assembled it and moved over my monitors and stuff. I think it looks quite good and it’s very sturdy. 🙂

Next up is a proper mouse pad to avoid wearing out the table (using a sheet of printer paper meanwhile) and a proper computer chair, probably a Herman Miller Aeron or something.

Translating Strings In WordPress Containing Multiple Placeholders

I really often see a common mistake made when translating strings in WordPress so I thought I’d write a blog post in order to shed more light on the issue.

But first, here’s a quick refresher on how to internationalize code in WordPress:

[php light=”true”]<?php _e( ‘Welcome to my blog!’, ‘my-plugin-text-domain’ ); ?>[/php]

For dynamic strings, it’d be something like this:

[php light=”true”]<?php printf(
__( ‘Welcome to my blog, %s!’, ‘my-plugin-text-domain’ ),
$name
); ?>[/php]

But what about when you have multiple variables to use in your string? A common mistake is to do something like this:

[php light=”true”]<?php printf(
__( ‘Welcome to my blog, %s! Today\’s date is %s.’, ‘my-plugin-text-domain’ ),
$name,
$date
); ?>[/php]

The issue with this is that you’re requiring the person’s name to always come before the date. If for internationalization reasons it needs to be in a different order, then it won’t work. You’ll end up with something like Today's date is Alex. Welcome to my blog, November 2nd!.

The solution is to use standard sprintf() argument swapping parameters:

[php light=”true”]<?php printf(
__( ‘Welcome to my blog, %1$s! Today\’s date is %2$s.’, ‘my-plugin-text-domain’ ),
$name,
$date
); ?>[/php]

Now translators are free to re-order the string to whatever makes the most sense for the language in question without having to worry the order of the variables.

For a more in-depth review of this, check out the WordPress Codex where many real world examples can be found.

Go Kart Racing In Budapest

I was in Budapest last week for the Automattic company meetup and during that meetup a bunch of us went out go karting. I took my GoPro HD Hero 1 with me and mounted it onto my go kart using a suction cup. The videos turned out pretty cool (although lighting was an issue) so I thought I’d post two of them here. 🙂

The Opening Race

I had gone to this place a few days before so I already knew the track and the karts but most of the people I was racing against where new to the track and karts, hence the speed differences.

The Championship Race

The people who posted the top 7 best lap times were put into a starting grid and had a final race off. The track’s narrow width made it nearly impossible to pass but it was still quite fun!

The final lap (starting at about 8:20) was a victory lap which is why I was goofing around and trying to powerslide. 🙂