Category Archives: Code Snippet

Archiving Sent Mail with imapfilter

My “sent” folders are a morass. I think that’s true of most folks. I wrote a little script in my imapfilter config.lua to duplicate some handy functionality from the venerable pine. I’m sure it could be cleaned up a bit, but it does the job for me. On the first of the month, it creates a folder called “Sent-Monthname-Year”, and moves everything from sent that’s older than a day to it.

function moveSentMessages()
  -- On the first of the month  --
  -- move all older messages to --
  -- a date marked sent folder  --

  theDate ="*t")

  months = {

  if (theDate["day"] == 1) then
    dateString = "Sent-" .. months[theDate["month"] - 1] .. "-" .. theDate["year"]
    messages = personal["Sent"]:is_older(1) + personal["Sent Messages"]:is_older(1)

Editing the hosts file on Windows

I have to Google this once a week. It doesn’t stick. At least this way, maybe I’ll find my own site when I Google. The easiest thing to do is create a shortcut on the desktop. It should point to

notepad.exe C:\Windows\System32\drivers\etc\hosts

Then run this shortcut as an administrator whenever you need to add a new host.

Use DNS prefetching to speed up web font loading

Poking around in a framework today, I saw they’d suggested using the new dns-prefetching feature in HTML5 to speed up resolving some foreign domains. Further digging showed folks are prefetching the domains from which Google serve their web fonts. It’s a great idea, given that web fonts are one of the biggest contributors to page weight on a largely text web site.

To include prefetching of the Google web fonts domains in your page, add the following code to your head:

<link rel="dns-prefetch" href="//">
<link rel="dns-prefetch" href="//">

Convert .webloc files to a Markdown list

I have a bunch of bookmarks I was keeping in folders on my Mac as .webloc files. I still want the bookmarks, but I don’t want all these tiny files cluttering up my drive, so I wrote a quick script called webloc2md. The script takes a single argument, the target directory, and outputs the links as an unordered list formatted with Markdown. The list is output directly, you can pipe it into the file of your choice.

One caveat: the .webloc files must be in XML format. If not, the script will skip them, and output a warning as the last list item. You can use the program plutil to do the conversion. To convert all the .webloc files in the current directly, type plutil -convert xml1 *.webloc.

You can grab the script from my GitHub account.