blog

Archive for the ‘how to’ Category

Keep up with Yet Another Related Posts Plugin with RSS!

土曜日, 10 月 4th, 2008

As more and more people have been using my Yet Another Related Posts Plugin for WordPress, I thought it would be nice to have an RSS feed for users to stay on top of the latest releases.

Clicking on a version’s permalink will let you download the plugin. Subscribe now and be the first to find out when the upcoming version 2.1 is released!

I decided to semi-automate this RSS-producing process as well. As a plugin developer using wordpress.org’s plugin hosting, I sync a local copy of the plugin to their server using SVN. I wrote a PHP script to get the modification date information directly from the local files, parse the version log in the read me, and produce the RSS feed. If there’s an interest, perhaps I’ll release this code in the future.

Doing your Taiwan Fulbright taxes

月曜日, 7 月 14th, 2008

So you received a Fulbright fellowship to teach English in Taiwan. Congratulations! And they’re even going to pay you! Great! But if they’re paying you, you’ll have to pay taxes… so here’s my guide to doing your Taiwan Fulbright English Teaching Assistant taxes.

Note: Many of the considerations here are specific to Fulbright English Teaching Assistants (ETA’s) in Taiwan. If this exact grant doesn’t apply to you, you may be better off simply taking a look at the IRS’s guide for Fulbrighters and also the Tax Guide for U.S. Citizens and Resident Aliens Abroad. I am not a Certified Public Accountant, tax advisor, nor Enrolled Agent1 so your mileage may vary. Consider yourself warned.

(more…)


  1. Highest (coolness of title)/(actual coolness of the job) ratio ever. 

My new scale

火曜日, 6 月 24th, 2008

ANA has draconian baggage restrictions (checked: 20kg total, US$10/kg thereafter) and I don’t own a scale. Problem solved!

Verdict: suitcase 18kg, guitar 6kg. I think I’ll make one more box to send at the post office tomorrow morning.

I feel like a caveman. THAT IS ALL.

St. Patrick’s Day Pilaf, brought to you by Sufjan Stevens

土曜日, 3 月 15th, 2008

St. Patrick’s Day for many means a wholesale celebration of faux-Irishness through Guinness and everything green. While I’m not a fan of beer, I decided to put something green together to eat today. One of my favorite food writers Mark Bittman of the New York Times made a chicken with salsa verde but since I can’t find half of those ingredients in this country, I made a simpler non-Irish dish: a green pilaf, based on Bittman’s own recipe. Why not try a simple green vegetarian dish for St. Patrick’s Day?

As an added bonus, I set this recipe to Sufjan Stevens’ Illinoise. I was just in a Chicago-missing mood and listening to it while cooking, and it seemed to work so well.

Time: 45 minutes (mostly waiting, though)
2 tablespoons extra virgin olive oil
1 medium onion, chopped
2 cloves garlic, chopped
Salt and pepper
1 1/2 cups (400cc) chicken stock (I used a bouillon cube—雞湯塊)
1 medium head of broccoli, just the flowers, in small chunks (maybe 3/4-1 cup)
1 cup (250cc) short grain white rice
1/2 cup (130cc) chopped parsley, optional

  1. Track 1: “Concerning the UFO Sighting Near Highland, Illinois.” Put oil in a pan on medium heat. Add the garlic, onion, and a pinch of salt and stir occasionally until the onion is translucent or until you hear the piano riff on track 3, “Come On! Feel the Illinoise!” In the down time, you can make sure your chicken broth is heated up in a pot.
  2. Track 3: “Come On! Feel the Illinoise!” Add rice to the onion pan and stir occasionally until they get clear and start to brown, sometime during the second half of track 3, “Come On! Feel the Illinoise! Pt. II: Carl Sandburg Visits Me In a Dream.” Throw the broccolli in the broth to let cook for the last minute of “Carl Sandburg.”
  3. Track 4: “John Wayne Gacy, Jr.” Add the stock/broccolli to the rice/onion pan. Heat to a boil and then let cook for the rest of the track. Stir occasionally. Compare yourself to a serial killer as you watch the bubbles.
  4. Track 5: “Jacksonville.” Cover and cook until the end of track 9, “Chicago.”
  5. Track 10: “Casimir Pulaski Day.” Enjoy my favorite song on the CD. Turn heat off and let sit, uncover, stir gently, cover again, and let sit on the burner until track 15, “The Predatory Wasp of the Palisades Is Out to Get Us.” Optionally mix in chopped parsley for additional green. Serve.

Happy St. Patrick’s Day!

Display your Last.fm rankings using PHP 4’s XSLT support

金曜日, 2 月 1st, 2008

With all the exciting recent news about Last.fm, I thought I would document a simple bit of code I added to my site the other day.

Last.fm offers a number of Flash-based widgets you can add to your website. Unfortunately, this doesn’t give you much flexibility and, of course, requires Flash. But you, dear friend, have a site written in PHP, and the rankings are just XML files. There is a better way.

Looking around on the web, there are some good instructions and recommendations for using PHP 5’s object-oriented XML support. But, as we know, not everyone is using PHP 5. Here’s what I did on my PHP install, which includes the DOM/XML and DOM/XSLT extensions.1

Write your XSL Transformation

The first step is to write your XSL Transformation, or XSLT, a special XML “program” which takes an XML file and reformats it into another XML file. Remember when you learned in Algebra class what a function was? An XSLT defines a function from XML to XML. In our case, we need to take a special proprietary XML file like the this one for my weekly top artists and return some solid XHTML.

Let’s take a look at the XSLT I used: (it helps to take a look at the original XML file at the same time.)

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="weeklyartistchart">
<ol>
<xsl:apply-templates select="artist[position() &lt; 6]"/>
</ol>
</xsl:template>
<xsl:template match="artist">
<li><a><xsl:attribute name="href"><xsl:value-of select="./url"/></xsl:attribute><xsl:value-of select="./name"/></a><span><xsl:value-of select="./artist"/></span>: <xsl:value-of select="./playcount"/></li>
</xsl:template>
</xsl:stylesheet>

The full spec description will give you all the juicy details, but you really only need a few basic details (or you can just steal my code). First, we note the <xsl:template match="weeklyartistchart"> and <xsl:template match="artist"> items. Each of these code blocks describe what to do to each <weeklyartistchart> and <artist> nodes, respectively, in the input XML. In the code above, when a <weeklyartistchart> is found, an ordered list is opened and the artist template is applied to the first five (position() &lt; 6) <artist> nodes. In the artist template (<xsl:template match="artist">), the script takes each <artist> and prints a list item with the name of the artist, with a link to the url given in the original <artist>’s <url> subnode.

Process the XML with your XSLT

Once your XSLT is written, save it to a file, like last.fm.xml. Now we’ll use the DOM/XSLT extension and apply this XSLT file to the live weekly artist chart XML file from last.fm. Here’s the code I used:

$chartxml = domxml_open_file("/weeklyartistchart.xml");
$xslt = domxml_xslt_stylesheet_file("last.fm.xsl");
$charthtml = $xslt->process($chartxml);
echo $charthtml->dump_mem();

The code is pretty self explanatory—just four lines: 1. open the remote XML file using domxml_open_file, 2. open the stylesheet (XSL transformation), 3. apply the stylesheet to the remote XML file, and 4. echo the output.

That’s it! You can see the results here on my music page.


  1. To see if these instructions will work for you, check your phpinfo for the lines “DOM/XML enabled” and “DOM/XSLT enabled”. If the items aren’t even showing up, you’re out of luck. :( There are, however, other comparable methods to process XML and XSLT in PHP 4.
    dom/xml check 

Survival Tips for Visiting Taiwan

金曜日, 11 月 16th, 2007

As my family and Bailey are coming to visit me soon, I decided to write up some basic survival tips for visiting Taiwan. While most aspects of living in Taiwan are very similar to the US or Japan, here are some things to keep in mind:

  1. Don’t flush the toilet paper in the toilets. For this reason, almost every bathroom here has a trash basket. Also, keep some tissue paper on you as most public restrooms do not provide paper.

  2. Don’t drink the tap water. I don’t know what happens if you do, as I haven’t tried, but I’m not planning on it. The good news is that most public buildings and many other establishments have drinking water machines. Bring a good water bottle.1

  3. If you’re visiting northern Taiwan in the winter, bring some raingear. Sure, you’ll probably buy a few umbrellas (I’m on number three), but rain coats are pretty useful too. You can also be really Taiwanese by wearing your raincoat backwards.2

  4. Taiwan is big on recycling. Luckily, though, in most places there’s just a trash can (垃圾桶, pronounced lèsètǒng as opposed to the Mainland lājītǒng) and a recycling bin… in general, most paper and plastic containers that don’t have food waste can be recycled. Plastic bags and wrapping cannot be.

  5. Keep all your receipts. Taiwan has a receipt lottery (formally the Uniform-Invoice Prize). While you can claim it as a foreign visitor with a valid visa, as the winning numbers are released about a couple months after each time period ends, you’ll probably just want to give the receipts to me. ^^
    IMG_9844

  6. Oh, and cold tea is sweetened by default. This freaked me out when I first tried some. Just a warning.

Of course, if you’re not planning to visit me yet but have time between late-January and mid-February (my Chinese New Year break), let me know. Let’s talk.


  1. I love my Nalgene

  2. This most likely comes from everyone riding scooters. 

Updating your zenphoto theme for zenphoto 1.1

日曜日, 11 月 4th, 2007

I use zenphoto as the backend to my photos section with a custom theme to hook into my site’s navigation and such. I chose zenphoto for my website a year ago based on it’s main strength: simplicity. It does much less than the competition, but it does what I need it to do—for the most part. It’s a fantastic bare-bones mysql/php photo gallery option.

Since then, though, I (along with many others) have been slightly disappointed by the lack of development in the promising project, without having the time or energy to pitch in myself. Such is life. But now the wait is over: Zenphoto 1.1 is out.

Zenphoto 1.1, I believe, does a good job balancing this tradition of simplicity with some popular new features. Highlights include (there are many) tagging, subalbums, chronological archives, RSS feeds, EXIF support, Google Maps, search, and preliminary video support. Exciting stuff.

As I maintain my own theme, though, some of these new features of course require me to update my theme. Below is my rough guide to editing your theme to take maximum advantage of zenphoto 1.1.

(more…)


© 2006-2008 mitcho (Michael 芳貴 Erlewine).
Proudly powered by WordPress.
Entries (RSS) and Comments (RSS).
The views expressed on these pages are mine alone and do not
reflect those of my employers and clients, past and present.