Sporkmonger

purveyor of fabulously ambiguous eating utensils

Sake Is Pretty Awesome

Posted by sporkmonger
Written March 1st, 2008

So, I happened upon this entry earlier today. I hadn’t previously seen sake and I’ve got to say, it’s really quite handy. Having a global set of rake tasks is just super-useful. Thanks Chris! (And thanks Brian because I wouldn’t have noticed it otherwise!)

Trust me, you want to:

sudo gem install sake

FeedTools 0.2.27

Posted by sporkmonger
Written January 31st, 2008

It’s been a long time coming I guess. Haven’t really had much time to work on it, and when I have, I really haven’t wanted to. Of all the software I’ve ever written, I consider FeedTools to be the most embarrassingly bad. Ironically, it’s probably also the most popular piece of software I’ve ever written.

Anyways, it’s been so long since I made some of the changes that I have listed in the CHANGELOG that I don’t even remember making them. They probably really did happen. Everything finally green-bars in any case. I ditched HTree and replaced it with html5lib. I was surprised by how easy the transition was, but it’s definitely slower for it. I fixed the issues with resolving relative URIs. Got rid of some ugly hacks, added a few more. The schema for the cache changed slightly. On balance, it’s better than 0.2.26, but in keeping with tradition, it’s also a little slower. If you need speed, you’ve come to the wrong place. That hasn’t changed at all.

I’ve learned a lot in the time (What has it been now? 3 years?) since I originally set out to write this parser. Certainly the most important lesson I learned was, “If you build on a lousy foundation, the entire thing’s going to be unstable. At best.” I’m not sure why I didn’t realize much earlier on that REXML was a mistake. Once I was far enough in that I couldn’t easily turn back, I started trying very hard not to make the original mistake in other areas. Incidentally, that’s how Addressable came into existence. It became clear to me that Ruby’s built-in URI parser was terrible, so I stopped using it and wrote a replacement. A replacement that I now swear by. If FeedTools is my greatest embarrassment, Addressable is (for the moment) my pride and joy. (Actually, that might be a bit much. It’s still just a URI parser.)

Also, while I was at it, I put the API up again.

Hopefully I won’t have to touch FeedTools again for a very long time.

Tip: Require password to restart OS X

Posted by sporkmonger
Written January 16th, 2008

So, last week I was running this ridiculous database migration for importing WordNet into MySQL via ActiveRecord. (I would like to file a complaint by the way. If a migration takes 8 days to finish, you need to use something other than ActiveRecord to get stuff into the database. Seriously.)

A family member decided they would like to watch a TV show on my laptop. Fairly normal. Unfortunately, my PowerBook decided to act up and wouldn’t play any sound. Still not sure what the deal is with that, it’s happening off and on. Only thing that fixes it is a reboot. Well, the family member in question took it upon themselves to reboot while my migration was in progress and about 98% done. For those of you reading this in horror, don’t worry, I hacked on the migration code for about 20 minutes and got it to resume where it left off.

That said, I decided I didn’t want that ever happening again. The obvious solution was to check off the little checkbox in System Preferences -> Security for “Require password to shutdown or reboot”. Except that it doesn’t exist. Apple? Are you listening? I’d like to be able to remind users of my computer that they really need to ask me before rebooting my computer. Anyways. Here’s how to do it without the handy checkbox:

Create a new user on your machine. Regular old user, no admin access. Name it “Lockdown”. Give it a lightning bolt icon or something. Enable fast user switching. Log in to your account as normal, then once you’re logged in, switch to the Lockdown account. Sign it in, leave it running, then switch back. Now OS X will require a password before rebooting.

It’s a hack, and there’s no really good reason to leave it running all the time, but it’s a good idea if you’ve got an important process going that you really don’t want getting killed off accidentally by well-meaning family members. And yes, they could still hit the power button or pull the battery on the laptop, but that’s a lot harder to do accidentally.

Sass TextMate Bundle

Posted by sporkmonger
Written December 24th, 2007

I went a googling, looking for a Sass TextMate bundle. There didn’t seem to be one, so I sat down and threw one together. Hopefully, this should make writing Syntactically Awesome StyleSheets a little easier for TextMate users.

Read the rest of this entry…

Addressable Now One Point Oh

Posted by sporkmonger
Written November 3rd, 2007

I just released version 1.0.0 of my Addressable library. The most useful change is the addition of a new heuristic parsing method, similar to how most browsers handle URIs entered through their address bars. Passing “example.com” to the heuristic_parse method will end up returning a URI that is equivalent to “http://example.com”. The URI can then be further normalized as necessary.

In addition, there are several minor changes that might cause compatibility issues (although probably not). The path component of a URI is now guaranteed to never equal nil. The code in the parse method for handling the feed pseudo-protocol has been removed and placed within the heuristic_parse method where it belonged in the first place. The to_h method has been renamed to to_hash so that coercion will work. There were also a couple of small bug fixes, mostly related to routing.

All of that stuff is great of course, but the main reason I’m slapping the “One Point Oh” sticker on this thing and calling it “done” is that now, in addition to having 100% code coverage, Addressable can now manage to go through the heckling process with no surviving code mutations. That’s a pretty high bar to get over, so I think it’s fair to call this thing finished.

Insomnia: The Good, the Bad, and the Ugly

Posted by sporkmonger
Written September 19th, 2007
  • The Good: Plenty of time to hatch brilliant ideas.
  • The Bad: Brilliant ideas do not help you fall asleep.
  • The Ugly: In the morning, you’re too tired to implement anything.

Introducing Addressable

Posted by sporkmonger
Written September 5th, 2007

So, after 3 months, I’m back from my excursion to Africa. Don’t worry, I’m not coming back empty-handed.

I thought my fellow rubyists might benefit from the URI implementation I’ve been using in various projects, so I’ve extracted it out into its own library. In the process, I improved a few things here and there, added support for URI Templates, and fleshed out the specifications a bit more.

I introduce to you the Addressable library.

It has about a 2:1 spec to code ratio, 100.0% code coverage, and it has gone through plenty of code heckling. It ought to be pretty reliable.

Hope you like it. Let me know how it works.

Update:

I’ve added URI Template variable extraction and I updated the documentation. The extract_mapping method should be useful for template-based routing systems for frameworks.

Now Available In Tanzania

Posted by sporkmonger
Written July 6th, 2007

Maasailand

For those of you who are interested, I’ve been in Tanzania at the Cradle of Love baby home near Arusha for the past two weeks and change. It’s been interesting for sure, lots of holding and feeding babies, playing with toddlers, trying to get through the day with as little snot and spit on me as possible. There’s a few spitters who make this difficult, but they make up for it by being excessively adorable. I try not to play favorites, but Neema ends up riding my shoulders quite a bit. I haven’t taken a lot of pictures around the baby home itself, but on the various excursions we’ve taken outside, the camera has come out with a fair degree of regularity. There’s also some new kite aerial photography shots from the trip to the bush to visit the Maasai. If you have a Pro Flickr account, the high-resolution panorama shot from the kite is pretty neat. I suspect that through August at least, my Flickr photo stream will be much more interesting to subscribe to than my blog’s feed will be. Consider adjusting accordingly.

Only In Kenya

Posted by sporkmonger
Written May 17th, 2007

As a few of you are probably aware by now, I will be taking a break from Ruby, and computing in general for a couple of months. I am getting on a plane headed for Nairobi on May 20th. I won’t be back until August 26th. I’m not taking a computer with me, though I will have limited access through internet cafes, so email should work, but don’t expect quick replies.

For those who are curious, the intent of the trip is humanitarian in nature. There will be trips to Uganda and Tanzania, and some volcano climbing. I’ll be sure to take lots of photos, which will no doubt end up on Flickr.

Update:

In London. About to fall asleep.

Update:

In Kenya. Amazingly still awake.

Bad Spammers! Go Away!

Posted by sporkmonger
Written May 5th, 2007

I finally got annoyed enough by all the comment spam. (Probably upwards of 100 comment spams a day.) To absolutely no one’s surprise, my IP blacklist wasn’t helping much. I’ve now customized the comment submission system in Mephisto to include a CAPTCHA of sorts. Well, really more like a test for an actual Javascript-capable browser. Sadly, the technique requires Javascript to be on, and I was a little too lazy to accommodate people who have it off. If you have Javascript off, and you really, truly can’t turn it on, well, I suppose you can always email me? The rest of site works perfectly fine with Javascript off, and I apologize in advance for letting you become a casualty of the War on Spam. If anyone has trouble commenting, email me, I haven’t tested this thing very well—it was a five minute change.

Update:

I rather like how well this has worked out thus far. Went from 100+ spam comments per day to zero since the code was deployed, with effectively zero chance of false positives. I can live with that.

Relaunched, Realigned

Posted by sporkmonger
Written April 2nd, 2007

If you can see this, apparently everything is working.

Update:

Ok, so there were some bugs. Incorrect permissions and such, not-quite-right Apache settings. But it’s likely to be more functional now.

After several weeks of work on the site, I’ve finally gotten everything moved off Typo, redesigned, and generally just looking a thousand times better than before. I also hosed out all of the accumulated spam. It wasn’t easy.

At Aristotle’s request, I made sure to modify the Typo conversion script (as well as Mephisto itself) to allow the feed entry GUIDs to remain the same. I wasn’t particularly pleased to discover that Mephisto doesn’t actually store its entry GUIDs in the database—it generates them each time the feed is requested, which in my humble opinion is a terrible idea, since the information it uses to generate the IDs might change. The change I made added a “guid” column to the database and uses UUIDTools to generate unique ids instead.

I also deleted a bunch of entries that I no longer felt were relevant to the site. I know a lot of people in the pro-standards crowd don’t like it when people do this, but I did anyways. I also tried to set up redirects for all of the old resources to the equivalent URIs in Mephisto, but I’m sure I missed a couple. If you bump into a 404 that you think is a mistake on my part, I’ll try to get it fixed as quickly as possible.

In addition to the switch to Mephisto, obviously I also took the time to redesign the site. I figured I should construct the design entirely from scratch this time instead of simply altering the default Typo theme. I gotta say, I really, really, really like the new look. I haven’t bothered testing and seeing how it looks in Internet Explorer. I really just don’t care that much about IE anymore. But I didn’t do anything particularly tricky with the design either, so it’ll probably look mostly OK. If you’re reading this in IE, stop, go install some other browser (preferably Firefox), and then come back. Web developers everywhere will thank you for it. And you’ll feel better about yourself. I promise.

I released a new library the other day called Squish. Admittedly, in its current state, it’s really effectively useless. I’ve never been particularly good at optimizing for performance, and while I did manage to improve the speed of the library (with the help of people in #ruby-lang) by at least an order of magnitude, it’s still way too slow to be useful. In retrospect, I’m not really sure why I even tried to write it in Ruby—I really should have known that a compression-based text classifier would need to be written in C. But hey, at least I know the basic idea works now.

Oh, and you may also notice that the site is faster and less error-prone now. You can thank Slicehost for that. I can’t recommend them highly enough if you’re in the market for a Rails-friendly VPS host.

Random Numbers in UUIDTools

Posted by sporkmonger
Written March 16th, 2007

I wrote the random number generator for UUIDTools awhile ago, but strangely, I’m only just now getting around to verifying that the numbers it generates really are decently random. Previously, I’d just been “eyeballing” it.

Read the rest of this entry…

Instance variables, class variables, and inheritance in Ruby

Posted by sporkmonger
Written February 18th, 2007

I’m seeing a lot of code that indicates to me that people don’t have a complete grasp of when to use class variables in Ruby.

Here’s a quick example script that should give people a better idea of what’s going on:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

class ExampleClass
  @variable = "foo"
  @@variable = "bar"
  
  def initialize
    @variable = "baz"
  end
  
  def self.test
    puts @variable
  end
  
  def test
    self.class.test
    puts @@variable
    puts @variable
  end
end

class ExampleSubclass < ExampleClass
  @variable = "1"
  @@variable = "2"
  
  def initialize
    @variable = "3"
  end
end

first_example = ExampleClass.new
first_example.test

puts "---"

second_example = ExampleSubclass.new
second_example.test

Output:

foo
2
baz
---
1
2
3

Essentially, when you declare a class variable in a base class, it’s shared with all subclasses. Changing its value in a subclass will affect the base class and all of its subclasses all the way down the inheritance tree. This behavior is often exactly what’s desired. But equally often, this behavior is not what was intended by the programmer, and it leads to bugs, especially if the programmer did not originally expect for the class to be subclassed by someone else.

I strongly encourage Ruby developers to sit down and think about how they want their classes to behave if subclassed by someone else. Be careful about using class variables, because often what you actually wanted was an instance variable on the class object.

Script Generate

Posted by sporkmonger
Written January 17th, 2007

Well, here’s an interesting mistake I just made. Went to generate a model for a Rails application I’m working on, but I made a typo. Instead of entering:

script/generate model ListedParts

I accidentally typed:

script generate model ListedParts

That of course, didn’t work. It just came back with:

Script started, output file is generate

Sadly, I was unaware of the functionality of script, so of course the first thing I did after that was:

cat generate

3 seconds later, my Powerbook was locked hard, and I had a 200 MB file in my directory.

Oops.

Blog Migration

Posted by sporkmonger
Written January 12th, 2007

Alright, that’s it. I’ve had it. Just got hit with another hundred or so spammy trackbacks.

I’m sick of Typo. Too much trackback spam, and no good way of defeating it with Typo. Typo doesn’t even let you disable trackbacks. It has an option for disabling it, but it doesn’t seem to actually do anything. Plus regular expressions and simple string blacklists that don’t match against the poster’s name, email address, or uri simply aren’t enough. It’s time to migrate to Mephisto. I’d been planning on sticking with Typo until GentleCMS was done and then rolling my own setup, but this is much too frustrating. So yeah, I’m starting the work required to switch over as of right now. Might take me a couple days because I have customizations to the Typo codebase, but if you have trouble leaving comments or if the site goes down entirely, you’ve probably just caught me in the middle of trying something. And apologies if any comments get lost in the fray.

I’ll probably end up implementing something similar to what Sam Ruby has going because a) it’s simple and b) seems to work.

Update: Now that I think about it, I might “reboot” the design while I’m at it. I found my missing spork the other day, so it’ll likely make a reappearance in the header image for the new design.

Update: It’s going to take longer than I thought to get the blog migrated. In the meantime, I’ve rather forcibly mangled Typo’s trackback support by rerouting trackbacks to the homepage. Didn’t feel like wading through Typo’s code when a one line patch to routes.rb would work. I’ll get everything working again later. The blog conversion has been largely delayed by TextDrive not answering support requests (grr) and by myself being preoccupied with work for a client. Some cool stuff that I can’t wait to show off.