17 Posts for September 2007


Efficient Window-Switching in Emacs

Posted September 30, 2007

I had a totally awesome post 80% written when I updated Gutsy... and X crashed. That’s not supposed to happen, but it’s what I get for running on the cutting edge. Anyway, I no longer store half-written blogs in /tmp, and I have a shorter post for you instead.

This is just a cool little Emacs customization I came up with.

I tend to use a lot of windows. For non-Emacsers (or Emacsers who have yet to discover this wonderful feature), in Emacs parlance, a “window” is not the same as the things that float around on your desktop and provide a frontend for programs. An Emacs window is a division of the “frame”, which is the same as the things that float around on your desktop.

Each window is a view into another “buffer”, which is the Emacs term for a document you’re editing1. Thus, you can have multiple frames open editing more than one document at a time.

School Begins

Posted September 25, 2007

Tomorrow, September twenty-sixth, the first classes of the University of Washington’s Autumn Quarter will be taught. I will be attending four of those classes. I will be recieving homework from the instructors of those classes. Homework that I will be obligated to complete in a timely manner.

Yes, summer is gone. With it, unfortunately, goes most of my free time. As much as I love working on my various projects, I also love keeping up my GPA.

That’s not to say, of course, that I won’t be continuing to work on Haml and make_resourceful. I’ll just have less time to devote to them.

Fun With the Y Combinator in Ruby

Posted September 23, 2007

A while back, I was playing around with anonymous recursive functions. I ended up creating an anonymously recursive lambda function, which I called reclambda, in Ruby. At the time this blog was yet to be created, so Hampton Catlin wrote it up instead.

I didn’t really understand it, though. The code was mostly ported from a Scheme example I found somewhere. I always felt kinda bad about that.

Recently, I decided to remedy my ignorance. I bought and worked through The Little Schemer1.

Although the whole book is fascinating, What really made it for me was the chapter on the Y combinator. After reading that, I felt for the first time that I actually understood how it worked. Feeling renewed confidence, I set out to remake it – by hand – in Ruby.

Overriding find for Cleaner Code

Posted September 19, 2007

When I first added search capabilities to this blog, I did it by overriding the current_objects method in the controller.

For those who haven’t yet discovered the joys of make_resourceful, current_objects is a special method used by to retrieve a collection of models that the index action will display. By default it looks (sort of) like this:

def current_objects
  @current_objects ||= Post.find(:all)

If you override it, everything that acts on the collection object uses whatever your function returns. The rule of thumb is: if you want to change the collection, redefine current_objects. So I did.



Posted September 18, 2007

Last night, I added the ability to tag posts to my blog engine. The mechanics of it are pretty simple; you can filter /posts by a tag by giving it a tag parameter. Check out the “Tags” links in the sidebar.

For example, I write a fair number of posts about my blog. To just look at these posts, you’d click “Blog” on the left, which would send you to /posts?tag=blog. Try it; there’s always a back button.

You may also notice little feed icons next to the tag links: Little Feed Icon. These link to a feed that only includes posts with the given tag.

Emacs, Lisp

Make Your Own Keymap

Posted September 17, 2007

Yesterday I was playing around with my .emacs. Spurred by a sudden need to use IRC, I was setting up ERC at the suggestion of Will Farrington.

One thing I noticed after starting up ERC a few times is that M-x erc requires a lot of repetitive user interaction. It asks for the IRC server, IRC port, and your nickname, none of which ever change1. So, being a good Emacser, I decided to make a custom function that filled it in for me:

(defun ??? ()
  "Open an ERC client with my credentials" 
  (let ((passwd (read-passwd "Password: ")))
    (erc :server "irc.freenode.net" :port "6667" :nick "nex3" :password passwd :full-name "Nathan Weizenbaum")))

I wasn’t sure of the name, though. I wanted it to be something short, easy to type via M-x, and descriptive. erc was taken. my-erc was non-descriptive and took too long to type.

I Hate GTK Tabs

Posted September 15, 2007

I’m a big fan of GTK. It’s generally a very nice-looking GUI toolkit, with good, consistent UI. It’s a total blast to program in, especially after doing Windows GUI programming at Microsoft (shudder). I’m in awe that it’s managed to create a full-fledged object system in C of all languages.

That said, there are some things that bother my about GTK, as there are about everything I use. Everyone knows about the annoying default size of the file-opening dialog, and everyone wishes it were compositor-aware. I’m pretty sure the powers that hack are working on these at the moment anyway.

The one thing that bugs me more than either of these, though, seems to have gone mostly unnoticed by everyone else. I hate GTK tabs. They are gargantuan, hideous, unusable monstrosities.

Terminal Syntax Highlighting

Posted September 12, 2007

I know, I keep going on about syntax highlighting. I promise I’ll stop (at least for a while) after this post.

My latest highlighty adventure should be of more general interest than the last few, though. See, this time it’s not about highlighting code on some website. It’s about highlighting code in the place programmers spend the second-most amount of time: the terminal1.

Even though I use Emacs, I haven’t gotten the hang of the built-in shell. It’s cool and reasonably functional, but it chokes on stuff like colored output and cursor positioning. So I tend to switch between Emacs and gnome-terminal.

When I’m using the terminal, I occasionally want to examine files or diffs or whatever. For this, I use less. less is in general an excellent little pager, but I’ve always been a little miffed that it didn’t have any way of highlighting syntax.

make_resourceful: Publish Extras

Posted September 11, 2007

I think we’ve established that publish is pretty darn cool. It’s pretty sweet to be able to generate a representation of any model in XML, YAML, or JSON, with any attributes or associations included or excluded. It’s especially sweet to be able to do so with no more effort than declaring the essential information.

But it wouldn’t be make_resourceful if that were it.

No, like everything else in m_r, publish is built upon several layers of support. Each of these layers has plenty of utility outside of its original purpose, and each can be accessed and customized by the programmer.

The layer immediately underlying publish is a method called serialize. This method is defined for ActiveRecord::Base models and for Arrays. It takes the same parameters as publish. But where publish publishes the data as an action, serialize just returns a string.

make_resourceful: The Basics of Publish

Posted September 10, 2007

make_resourceful has been coming along nicely, especially since I’ve left Microsoft and have had time to devote to it. I imagine we might be making an 0.2.0 release within the week. By the end of September at latest.

When it comes out, I’ll be sure to do a full writeup of it, like I did for 0.1.0. For now, though, I’d like to go over one of the most-anticipated and coolest features that you’ll see: publish.

Hampton actually talked about publish in his original m_r presentation. At the time, though, it wasn’t really in working condition. Because it required a fair amount of supporting code (and because I was off at Microsoft), it remained that way until recently.

Thanks to the help of James Golick, though, we’ve built up the necessary support and publish is up and running. And it’s very, very cool.

Opening my Engine

Posted September 7, 2007

At the request of Will Farrington, I’m open-sourcing the engine that runs this blog.

To be honest, I’m a little skeptical that anyone will want to use it. There are plenty of other Rails-based blogs out there, and to the best of my knowledge, my engine doesn’t offer anything that they don’t.

Nevertheless, Will insists that he wants to use it, so I suppose it’s not that much of a stretch that some other folks might want to as well. As such, I’m releasing it as the “Nex3 Blogging Engine.” You can get the source at svn://nex-3.com/nex3/trunk.


New Blog URL

Posted September 6, 2007

My blog has moved1 to a new location! The URL is now shorter, snappier, and easier to remember: nex-3.com.

Why “nex-3”? Well, mostly because nex3.com was taken. And nex3.net. And nex3.org.

At the moment I’m posting this, both the old nex3.leeweiz.net site end the new nex-3.com site are up. I’m going to try to set up automatic redirection between them soon.

A CodeRay Scanner for Lisp

Posted September 5, 2007

After I got syntax highlighting working, I went through all my old posts and retroactively set up syntax highlighting. Bringing color to a world that had only known black and white. It was pretty cool.

Except for my post about my Emacs blog client. All the code in that post is in Emacs Lisp, and sadly there does not exist a CodeRay scanner (and thus highlighter) for Lisp.

This was kind of a bummer. I didn’t like having unhighlit code. Since I plan on doing more posts about Emacs, I also didn’t like the idea that I would have to continue writing unhighlit code.

A Solution to the Syntax Highlighting Problem

Posted September 4, 2007

I have good news and bad news.

Bad news first. There is no pre-existing way of integrating syntax highlighting and RedCloth. Jeff Hardy and Evgeny suggested a few Javascript-based solutions, but I’d rather keep this server-side and Ruby-licious. So no luck there.

Now for the good news. It turns out to be really easy to hack something up that does just that. RedCloth is reasonably extensible, and for those cases where it’s not a little Patch Adams does the trick.

Syntax Highlighting and Redcloth

Posted September 4, 2007

I’ve been blogging a lot lately. I dunno what’s gotten into me. I just have a lot to say, I guess.

When I’m blogging, I tend to like using code snippets. Unfortunately, at the moment I lack any sort of syntax highlighting for these snippets. That kinda sucks.

Now, I use Textile, and thus RedCloth, for my post formatting. This works out reasonably well, except that it doesn’t have any support for syntax highlighting.

Goodbye, Microsoft

Posted September 3, 2007

As of Friday, August 31st, my internship with Microsoft is over.

It’s certainly been an interesting twelve weeks. I’ve learned a lot about what happens at a real software company (at least, at one real software company), and a fair bit about various technologies I probably wouldn’t have been exposed to otherwise.

Unfortunately, I can’t really talk about what I’ve been working on. I can say that it’s under the auspices of Office Shared Services, which as I understand it encompases everything Office-related that’s not an acutal office app. I can also say that I actually worked on several different projects while I was there.

Spam Makes Children Cry

Posted September 1, 2007

I’ve been getting spam comments. This kinda sucks. They’re unsightly, and a pain to clean up.

I want to add some functionality to mitigate the issue, or ideally stop it entirely. The problem is that I’m not sure what I should use.

Bayesian filtering is probably the most accurate, but pure-Ruby filters are slow and it’s a pain to install C extensions on my server. On top of that I don’t really want to bother training the filter.