Blogging Archives, page 3

Blogging about blogging, how meta.

Machine translation, semantic HTML, and embedded code, oh my!

It’s hard for me to believe that in the not so distant past I worked as a web producer for O’Reilly’s now defunct Online Publishing Group. Basically I was a sort of HTML jockey, shuttling articles through their content management system while ensuring that they all had consistent markup.

Since the articles O’Reilly published online dealt predominantly with programming, the vast majority contained code snippets and samples. Thus one of my primary roles was to ensure that the embedded code displayed properly on the web. Our HTML “style guide” dictated that all code be wrapped in <pre><code></code></pre> tags. I remember at the time thinking it a bit redundant—I occasionally embed code on my blog, but for simplicity’s sake, I use <pre> alone.

I discovered today another value to the semantic use of HTML: machine translation. I was looking through my referrer logs, and noticed someone had translated one of my posts with code samples. And sure enough, Google translated everything within the <pre> tags, mangling the code. Gah!

This made me think all the way back to my O’Reilly days, and I wondered what Google would do if I also wrapped the code block in <code> tags. Sure enough, they respected the semantic “intent” of the <code> tag and left it untranslated—BUT they also stripped out the newlines, collapsing multiple lines of code to a single line. So if anyone from the Google Translate team is reading, consider this a bug report.

Google Translate Test: before
Before Google Translate
Google Translate Test: after
After Google Translate

Note: Apparently Google will also avoid translating tags with class="notranslate".

Haloscan going the way of the dinosaur

Haloscan is getting upgraded to Echo:

Once presented with the upgrade message, Haloscan users will have 2 weeks to make a decision. You will have the following two options.

  1. Upgrade to Echo for $9.95/year – all your comment data will be transitioned over automatically
  2. Export your Haloscan comment data and turn off their service

This explains the recent interest in my Importing Haloscan comments into WordPress 2.3 from Blogger post (which is based on my original Importing Haloscan comments into WordPress from Blogger post from June 2005, back when I first moved from Blogger to WordPress).

It’s funny to think that in a small way I’ve helped countless users transition their Haloscan comments (usually embedded in Blogger posts) to WordPress over the past four and a half years, judging by the 203 comments that the two posts above have accumulated. Though it will be a bummer for the few users who are not able to make the transition, and thus lose their comments, I have to say it will be nice to have one less smidgen of code to support.

As an aside, I always get a chuckle out of the following image from Sam Ruby’s Rights vs Responsibilities post:

Since code costs essentially zero to distribute, my first thoughts are not on what rights I want to assert, but what obligations I wish to assume. If you look at software licenses, both commercial and open, this is something that they are careful to enumerate. In most cases, it essentially comes down to: “if it breaks, you get to keep both halves”.

Mise-en-abyme Halloween

Justin as as his halloween blog post on Justinsomnia.org

For Halloween this year I just dressed up as my blog post about what I dressed up as for Halloween this year. See also: Lost Wormhole.

OMG Boing Boing redesigns

After helping speed the demise of mainstream media and traditional publishing, Boing Boing has decided to add—wait for it—a masthead! How retro!

Boing Boing 2009 masthead

At least Ken Snider, FM Engineering’s Network Architect, gets a shout out.

How to intercept a WordPress page request

WordPress logoHave you ever wanted to write a plugin that sits between a request for a WordPress page (or post) and the fulfillment of that request? In order to do so, use the pre_get_posts action hook which passes a WP Query object as a parameter to your plugin function. This action is called early in the request flow, before any headers or content has been sent to the browser. So you can probe or modify the query object in order to create your own custom behavior.

As an example, I wanted to redirect all requests that come in for http://justinsomnia.org/random/ to a random post from my blog. Note the random link in my nav bar above. Here’s how you might do that:

<?php
/*
Plugin Name: Random Link
*/

add_action('pre_get_posts', 'random_link');

function random_link($query)
{
  if ($query->get('pagename') == 'random') {
    global $wpdb;

    $sql = "select $wpdb->posts.ID
            from $wpdb->posts
            where post_password = ''
            and post_type = 'post'
            and post_status = 'publish'
            order by rand()
            limit 1";

    $post_id = $wpdb->get_var($sql);
    $permalink = get_permalink($post_id);

    header("Location: " . $permalink, true, 302);
    exit;
  }
}

The result is a pretty serendipitous (and addictive) way to surf my archives.