Adding Emacs / PyBlosxom Support for a Custom Format

In PyBlosxom, blog entries are stored in regular files rather than in a database. This means that I can write my entries in emacs (hurrah). PyBlosxom can handle posts in any format it has a parser for.

The simplest parser removes the metadata from the beginning of the file and passes the remainder of the file directly to the output webpage. Ergo, in the most simple format, the entries should be written in html (with a basic text header). More complicated parsers could be used for formats like xml or wiki markup. PyBlosxom uses a file’s file extension to determine what format the entry file is in.

For some unusual reason PyBlosxom associates the simple pass-through parser with .txt files (wouldn’t it make more sense to use .html?). In any case, I decided that I wanted to add my own file extension, .blog, so that I could easily distinguish my blog posts from other text files and html files on my system and so that my editor could treat the files specially.

The first step was to make PyBlosxom recognize the files as entries which it knows how to parse (anything PyBlosxom doesn’t have a parser for will simply be ignored).

On line 79 in pyblosxom.py, is a block of code which I modified as follows:

# entryparser callback is run here first to allow other plugins
# register what file extensions can be used
data['extensions'] = tools.run_callback(”entryparser”,
                {’txt’: blosxom_entry_parser, ‘blog’: blosxom_entry_parser},
                mappingfunc=lambda x,y:y,
                defaultfunc=lambda x:x)

This is sufficient to make PyBlosxom treat .blog files just like .txt files.

The next step was to make the files easier for me to write. First off, emacs should open the files in html-mode. Adding the following bit of code to my .emacs file accomplishes this task:

(add-to-list 'auto-mode-alist '("\\.blog\\'" . html-mode))

The next step requires a tiny bit of background information on the format of PyBlosxom entries. The basic format of a PyBlosxom entry looks like this:

Title Of Entry
#metadata-1 value-1
#metadata-2 value-2
(...)
#metadata-N value-N

Post line 1.
Post line 2.
(...)
Post line N.

Note: the blank line is not required, but it makes the file more (human-) readable.

I always use the same two metadata lines: #postdate (from my metadate.py), and tags (from Joe Topjian’s tags.py). Because of this there are a few lines which are similar across all of my blog posts. Why not have my editor enter these automagically, including entering the current #postdate (in the format YYYY-MM-DD HH:MM)? How convenient that emacs provides a mechanism just for this purpose: skeletons.

I wrote the following code and added it to my .emacs file:

(define-skeleton blog-entry-skeleton
  "Inserts a PyBlosxom-style blog entry skeleton into the current buffer.
This only makes sense for empty buffers."
  "Title: "
  str | "Untitled Entry" \n
  "#postdate " (insert-date-and-time) \n
  "#tags " ("Enter a tag: " str ",") '(delete-backward-char 1) \n \n
  "<p>" _ "</p>")

When executed, this skeleton prompts the user for a title (if the user simply presses RET it defaults to Untitled Entry), repeatedly prompts the user for tags (keywords) (until the user simply presses RET), enters the current #postdate automatically, and the leaves the cursor inside a new <p>.

The final touch is to make the skeleton automatically execute when a new .blog file is created:

(eval-after-load "autoinsert"
  '(add-to-list 'auto-insert-alist '("\\.blog\\'" . blog-entry-skeleton)))

It’s like magic!

Uncategorized

Comments (0)

Permalink

metadate.py for PyBlosxom

Well, it just wouldn’t feel like Christmas without coding. =)

I recently started using pyblosxom for my blogging software needs. I’ll discuss the reasons for this choice in a later post.

One minor annoyance about pyblosxom is that since the entries are regular files, the developer chose to base entry post dates on file mtimes. While this is a really cool idea for the sake of simplicity of design, it gets rather old having post times change when correcting typos. I end up touch(1)ing posts constantly.

Many users simply wrap their post edits in a shell script which will replace the original mtime after editing, but I didn’t feel like settling for this solution.

In the end I decided to write a pyblosxom plugin to base the post time off a #postdate metadata line in the post file, if one is present.

The plugin can can be found here: metadate.py. Details are in the header of the script. I will be submitting it to the pyblosxom plugin registry soon.

Happy holidays, everyone.

Uncategorized

Comments (0)

Permalink

Firefox Tip: Creating Parent Directories on File Saves

I sometimes find that when I am saving files off the web in firefox, I have to go through multiple levels of folder creation. I click the “create new directory” button, type a name, hit return. Repeat.

I just learned (after my determination that it would be a very handy thing) that you can simply enter a directory hierarchy (e.g. images/wallpapers/hairless_cats/1024x768/) and firefox will create all of the parent directories and leave you in the deepest directory (“1024×768”). What a useful feature!

That’s good design. I do what intuitively seems right and I find exactly the feature I am looking for.

Uncategorized

Comments (0)

Permalink

How to Write an E-mail

I guess there are a lot of unspoken rules of netiquette which pertain to writing email. Perhaps it’s simply too much for many people to pick up in casual correspondence with their grandmother, but for those of us who use email regularly, our experience has lead to a set of guidelines for how emails should be formatted. My intention is to impart the most important of these rules to those who may not have yet discovered them.

These are not arbitrary whims of grumpy programmers, but rather the well-justified standards of professionals who have seen enough email to know what works and what does not. Complying with them will anger no one and can only gain you points in the tech world.

HTML-Email

In the beginning was the word and the word was content-type: text/plain.
 – jtanzler@yline.com (Johannes Tanzler), in
comp.emacs.xemacs

Your email client / webmail service can likely send email in two different formats: ‘plain-text’ and ‘HTML’. The basic difference is that HTML can contain mark-up like hyperlinks, (inline) images, and bold text.

If you need to use those features, then use HTML format. Otherwise use plain-text.

Justifications:

  • Capability — people read their email in a lot of different fashions. Some read it on cell phones, some on PDAs. Some read it on the web, and some of us read it from old-school text-based terminals. Plain-text works on all of these. HTML fails miserably on many.
  • Size — HTML email takes up vastly more space. Add to that the fact that most email clients tack on a plain-text version of the email for an attempt at compatibility. This takes up even more space.
  • Spam — HTML is for spammers. Plain and simple. Realize that the vast majority of spammers use HTML-format because it allows them to include links and image ads. Spam filtering is generally done by employing algorithms which look for similarities between known spam and differences from known ham (non-spam email). Using HTML-format makes your message more likely to be incorrectly marked as spam and never delivered to the intended recipient.
  • Annoyingness — HTML empowers people to do a lot of annoying things to my display which I simply don’t want them to do. Nobody wants that wood-grain email background or handwritten-signature image. Let us read our text in peace.

Wrapping

Wrap your plain-text at 70-80 columns. Period. Long lines of text are irritating and hard to follow. Too short and the page will get needlessly long. 72 columns is the approximate accepted standard. This avoids being too long or too short, and includes enough space for a couple replies without making the email too wide. Your email client or editor should be able to do this for you. If it can’t, get a new one.

The Subject Line is Your Friend

For the love of Pete, enter a descriptive subject line. The subject line is like a first impression—make a good one or they may not bother to look closer. Some people get a lot of spam, and telling the recipient what you are actually writing about is the best way for them to identify which messages have contents they actually want.

The subject line is also the primary piece of information your recipient will have to identify the email if they come back to look for it later. If you think people don’t care, let me point out that I actually edit emails I receive to give them worthwhile subject lines.

Don’t put an entire email in the subject line. Just don’t do it. It’s weird. It’s especially bad if the subject line is too long to fit on the screen in one line of text. Some email readers do not wrap subject lines, and some provide no way to scroll horizontally to read the cut off portion.

Bad subject lines I have received include: “stuff”, “file”, “file2”, “haha”, “yeah…”, “Cam can please take care of this I think the mailbox is too big and we should empty it, ok?”.

Good subject lines I have received: “SG Halloween pics!”, “AFS costume contest prize”, “Facebook used as a weapon against students”, and “Advanced Operating Systems call number changed”.

Top-Posting

Because it messes up the flow of reading.
> How come?
> > I prefer to reply inline.
> > > What do you do instead?
> > > > No.
> > > > > Do you like top-posting?

When replying, keeping a snippet of the original email in your message is a good way to remind your reader of the context of the reply. If you do this, however, put your response after the text it pertains to. Don’t respond to a question above the question. Lots of people do this. It’s annoying. Don’t do it.

Signature Lines

Including a signature line at the end of your email containing (at least) your name is generally a good practice to increase email readability. Your email client can probably include one automatically on your outgoing email.

If you do choose to use an email signature, you should offset it from the body of email with a line containing only “-- ” (two dashes and a space). If you follow this convention, many email clients can recognize your signature for what it is and take appropriate action (such as highlighting it in a different color, or removing it in replies).

Don’t put anything other than text in your signature. Don’t attach a “vcard.” It may seem neat to you, but we don’t want it.

Attachments

Don’t send .bmp files. Just don’t, they’re stupidly large. Convert it to a .jpeg or a .png.

And the final, most annoying habit that you should never, ever do: don’t place images inside .doc files before sending them! I see this all the time. Why do people do this?? Just send the images! Or put them in a .zip even! But don’t waste my space and make me open some slow word processing program I may not even have installed. And for what? If you figure it out, you tell me.

Uncategorized

Comments (0)

Permalink

USB Form-Factor

Whomever designed the physical shape of the USB (type a) connector clearly was not thinking.

You don’t make a plug which is symmetrical but yet can only be inserted one way. Half the time you try to plug a USB device in, you end of flipping it over because you had it backwards. Actually more than half the time since the plugs can be hard to slide in, so you think you have it backwards. In that case you end up flipping it at least twice.

Don’t people consider these things?

Uncategorized

Comments (0)

Permalink

Buddy Icons

Buddy icons are an interesting feature. I’ve never really bothered to question why they exist. But I guess there are two legitimate reasons: (1) personal expression (for the icon picker), and (2) rapid identification (for the icon viewer).

The first one is simple, the second just relates to the fact that humans can distinguish a variety of pictures more rapidly than they can discern text. So it makes sense, I suppose, to allow us to associate images with the people we choose to talk to.

But when picking buddy icons, most people don’t think about what the icon will actually be used for (hell, I’m not pointing fingers, I haven’t thought about it before now). This morning I was having a serious conversation over MSN messenger with an adult male whose icon was a baby. He has a decent reason to have a baby as his icon—it’s his newborn niece—but it’s disconcerting to have some damn baby staring at you as if (s)he were speaking the other person’s words!

Hackergotchis, small disembodied headshots commonly associated with aggregated blog entries, prove to be extremely useful in rapid identification of posts. But this is because Hackergotchis are images of something you (the reader) fundamentally associate with the author: their face.

I could give two shits about looking at some random icon that means nothing to me. And since this is my computer I care more about my usability experience than your extra bit of personal expression (hell, change your wallpaper if you want to express yourself). As of this morning I have disabled buddy icons in my IM client (gaim) because I am tired of looking at that damn baby.

But you know what would be really useful to me?—listen up software authors, there’s a UI lesson here—if I could set the icon that would display with an individual’s IMs. I’d slap some Hackergotchi-style faces up and then I’d actually have a reason to use buddy icons.

Uncategorized

Comments (0)

Permalink

Windows Vista: The Wave of the…Present

As all my GNU/Linux friends probably know, Windows Vista (formerly ‘Longhorn’) Beta 1 has been released. Many sites are posting screenshots of the new features. Some of the new things are cool: virtual folders, in-file searches, etc. I was a bit impressed at first, but then I realized that every new feature in Vista is available on Linux systems already, although many are not standardly deployed yet. So my respect for the new features was reduced to a respect for their ability to get these features out the door and widely available at a faster rate.

Then I stumbled upon the article I’m So Excited by Microsoft Vista. Not., which restored my perspective on the situation. Yeah, these tools are not available in a stock Linux distro yet, but Vista is at least a year off. Where will we be by then? Pssst…have you seen GNOME 2.12 yet?

Uncategorized

Comments (0)

Permalink

Language Pet Peeves #2

Wow. Since I actually managed to post about language without having my ass chewed off by anti-grammar guerrillas, I have to point out one more which irks me.

“out loud”

When I was a kid many of my teachers would tell us students to read “out loud”. Later I learned the word ‘aloud’ and almost immediately realized that “out loud” was a lazy, colloquial bastardization of the word ‘aloud’.

Now this one is a tougher fight than the others I have complained about because you can find some dictionary support for the incorrect version (namely Merriam-Webster, which is complete trendwhore of a dictionary, IMHO). But I’m a firm believer that we must hold the line on some aspects of language—not simply sanction whatever jibberish the masses spout (how many of you really want ‘nother’ in the dictionary because Midwesterners like to say “that’s a whole nother story”? How about ‘ain’t'?).

But I’m not without support on this one. Garner’s Modern American Usage (2003) says, “’Out loud’ is simply the colloquial equivalent of ‘aloud.’ Use ‘aloud’ in all but the most casual of settings.” So I’m not just crazy.

Yes, that means LOL is wrong. LA.

Uncategorized

Comments (0)

Permalink

Language Pet Peeves #1

I have to bitch about this because nearly everyone does this now and then—including many writing professionals—and it’s just sloppy.

“for free”

‘Free’ is an adjective or an adverb (or a verb under the other definition), but never a noun. That said, you can get something free, you can get something free of charge, you can get something gratis, you can get something for nothing, but you cannot get something for free.

Just drop the extra word, save some breath and say it right. It’s not a ‘buy one, get one for free’ sale, is it?

“some more”

No, you cannot get ‘some more’ ice cream (‘for free’, as it were). You can get some, or you can get more, but not both together. It’s redundant. Pick the word which expresses what you mean to say and then drop the other. If you’ve had some and you are asking for some yet again, then you are clearly asking for more. Alternately, if you are asking for more, then they know that you want some. You don’t need both words.

Say it slowly. Some more. It doesn’t even sound right. It only even sounds tolerable when you slur in into ‘suh-more’. And we know that’s not right.

We all slip up now and then, but I doubt that most people have even considered these errors.

Uncategorized

Comments (0)

Permalink

The Tamagotchi Dream

You guys remember the Tamagotchi (たまごっち), right? The Tamagotchi was a virtual pet you could feed, clean-up after, play with, etc. It sounds kind of lame, but the cool part is that the Tamagotchi has a persistent idea of state. It’s never really off, it “lives”, even when you are not playing with it. And it has some simple evolutionary capabilities.

This has really been interesting me for a while. I’m convinced something (the primary thing?) which really makes games fun is their ability to show us something new. We don’t want to feel like we are playing something deterministic, where we press a button, the game displays the built-in response back to us and that-is-that. There’s nothing like that “Woah! I didn’t know it could do that!” feeling. That’s what I play games for.

Most simply, games have a story, or levels, or something else that we haven’t forseen that we get to enjoy because it is new. But to me, the holy grail is games which make themselves. When the content of the game goes beyond what the designer had forseen, then we really have something.

In talks in Game Development class last semester, we had a discussion about the possibility of developing true (strong) AI. Someone claimed that real AI was a pipe dream because we cannot create anything greater than ourselves. My contention is not just that we can, but that I (like many others) already have.

For instance, my Game Focus Generator. Sure, I have preloaded the program with words and formulas to develop phrases, but the truth of the matter is that the output of that program contains things I would never have thought up. I used my abilities to develop something that reached beyond what I could/would have done on my own. For the people who know my personal programming projects of the past few years, you will notice that many of them serve this same goal. My genetic creature population sim (aka “flamesex”) is designed around this principle—I want to come back to it later and be surprised by the output. My graphical hacks, like my “growth” app, are in hopes of making some kind of image that I would never have thought of.

Anyway, this is something that really fascinates me.

I would love to make a state-full game which I could run on my pc, which I could play at will, and be surprised by.

But it has to be fun. The Tamagotchi is cool because it can surprise you to some degree, but it really can’t do enough to be all that staggering. It really needs to evolve more. The flipside of that is that you need for the player to still feel that they have some control—not just have it evolving out of control—otherwise they wont play. But if the game requires too much control, then it will be a pain because you have to be there messing with it all the time, and anything that forces you out of your normal life to maintain it is just a pain, and not a game. In general, the program needs to be stable. But it’s hard to make a stable game because risk is one of the things that makes games fun.

“The Sims” captures some of the basic elements, but for one the game was not intended to be played—or rather, not played—as I propose. Also, there is a limited amount of content. Nethack actually captures a lot of the things I like about gaming, partially by (psuedo-)evolving (random generation/placement of dungeons, stats, objects and enemies), and partially by its sheer complexity. Nethack has so much fabulous content that is not documented that you can discover. The game just sets forth a world, teaches you the basic rules, and lets you loose in an alien world. But there are actually things about the world to discover (I’m talking capabilities of the world, not story or locations), unlike most games.

Magic: the Gathering is also one of my favorite games of all time. Why? Because the game gives you a world—the cards—and says “go play it in”. You can combine cards in ways that no one ever thought of—including the game designers (might this be the same reason I am in love with emacs?). There are always, always, new things that you can discover (new card combos and such), and the things you discover make a serious difference in game. It’s like the card game Fluxx, but you actually have some control over the power(/madness).

This is my dream (or my goal, if you prefer). Now all I have to do is create it. Hmmm…

Uncategorized

Comments (0)

Permalink