11
12
09

Hpricot – [BUG] Bus Error – Solution / Workaround

Problem:

You’re using Hpricot to parse web content, but it’s throwing an error like this that completely kills the process (probably crashing your app, or your background task, as the case may be):

/usr/local/lib/ruby/gems/1.8/gems/hpricot-0.8.2/lib/hpricot/parse.rb:33: [BUG] Bus Error
ruby 1.8.7 (2009-04-08 patchlevel 160) [i686-darwin8.11.1]
Abort trap

This resource suggests that the problem is that the content retrieved is precisely 16384 bytes long, however, that was not the problem in my case.

My problem is replicated in this gist. Examination of the URL it was trying to retrieve using curl with -i indicated that this was returning a 302 redirect:

HTTP/1.1 302 Found
Date: Thu, 12 Nov 2009 14:50:53 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
X-UA-Compatible: IE=EmulateIE7
Location: /
Set-Cookie: ASP.NET_SessionId=p2s0dljru11tiwer3e01jfq2; path=/; HttpOnly
Set-Cookie: Forum2backURL=/tm.aspx?m=1859288#1859354; path=/
Set-Cookie: Forum2preURL=; path=/
Cache-Control: private
Expires: Wed, 11 Nov 2009 13:50:53 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 120

I am not sure why Ruby’s OpenURI open method was not capable of parsing / following this redirect. However, I determined that the file returned by open() had a size of zero bytes, and this was causing Hpricot to blow up.

My workaround is just to check the size of the file returned by open() and only try to parse it if it is greater than 0:

f = open(file_or_uri)
if f.size > 0
doc = Hpricot(f)
else
raise "Could not retrieve content due to zero-sized file, possibly due to site redirect."
end

11
09
09

Thoughts on O, 2

Oliver is two years and three months old. He’s an amazing little man. He seems to get cuter every day, an impossible feat. He trucks around with determination, his little legs whipping along, always moving from one thing to the next.

He’s curious. When he hears something, he asks, “What was that? What was that noise?” He loves to pick things up from the ground – sticks, rocks, whatever. To his mother’s horror, the other day he scavenged a french fry from the floor of the mall and happily ate it. In other words, he is resourceful.

He is observant. He can spot a sliver of the moon in broad daylight, when it scarcely looks different than a scrap of cloud. He learns quickly and is unafraid of embarrassing himself. I’m in a constant pattern of language instruction with him, introducing new words and asking him to repeat them. He does very well at it. I like to throw some curveballs in there too. “That’s called ‘manipulation’, Oliver. Can you say ‘manipulation’?” “Manish-ship-ship-shun.” “Can you say controversial?” “Con-oh-SERial!”

Although his vocabulary may not have caught up to mine yet, he has already superseded my musical ability. His rendition of Gincle Gincle Little Star is far sweeter to the ear than my best attempts. He is also adept at filling in the parts of songs he doesn’t know with semi-melodic mumbling, which will put him in good stead when he needs to sing the national anthem later on in life.

He loves to be tickled. When he’s had enough, he lets me know: “Daddy, dop!” In general he is not afraid to let me know when I’m being a pain in the ass. “No, Daddy. Go way, Daddy!”

On the other hand, he doesn’t like it when I leave. We have interesting conversations in the front hallway on weekday mornings when he tries to prevent me from going to work.

“No Daddy go!”

“Daddy has to go to work.”

“Why Daddy work?”

“Daddy has to work so that he can make money.”

“Why money?”

“Because we need money so that we can buy food.”

“Why?”

“Because we need to eat.”

“Why?”

Why indeed? I used to believe that when I had a child, I would always try to explain things to that child and never resort to the pat answers I’d hear from other parents (“just because”). My child is only two and he is already defeating this goal. Why DO we need to eat?

You can answer that question, sure, but ask enough “whys”, and you’ll find yourself trying to explain the nature and reasons for existence of the universe – to a two-year-old.

Then again, he’s probably got as good a chance of understanding it as most. In fact, I think he’s taught me far more about the ultimate nature of life and existence than I could ever teach him.

07
20
09

Rare Satisfaction

You’re driving, going at a decent clip. Some jerk is tailgating you anyway. He’s so close you can see his face in your rear view mirror. He looks like a douchebag.

He keeps drifting to the left to see if he can pass. He can’t, which makes him frustrated. He probably has a crap job and a worse family, which are stressing him out. Or whoever he’s talking to on his cellphone isn’t telling him what he wants to hear.

He finally gets a chance to pass. Steps on it to make a point and roars past. “Man,” you think, “I really, really hope that jerkoff gets pulled over a few blocks ahead. I’ll smirk as I drive past. Maybe give him a friendly wave. That prick.”

That never, ever happens. But the other night, I got a tiny glimpse of what it would feel like.

I’m coasting in to an intersection. It’s a four-way stop. Some dude is rolling in to the intersection at the same time, opposite to me but turning left (down the street on my right). That means only one of us can go. We’re going to have to stop together, and then one of us is going to have to yield to the other. Either he’ll make his left turn, or I’ll head straight through.

I don’t mind yielding – I’m not in any rush. But he doesn’t give me the chance. He decides to preempt our little negotiation by not stopping at all. He just keeps going, makes his turn, and heads down the street on my right.

Unfortunately for him, we weren’t the only people waiting at the intersection. A third vehicle had arrived at the same time on the same street this guy just headed down. This vehicle, it just so happens, is a police vehicle, driven by a rather large police officer. At the moment I see him his hand is raised, palm upward, in a gesture that clearly communicates exactly the same thing I’m thinking: WTF?

I pause. The cop doesn’t. He u-turns and heads after the dude.

The moment is over, but the feeling remains: a rare, sweet satisfaction.

06
11
09

Similarity Breeds Dislike

When the wildly popular online multiplayer game World of Warcraft came out a few years ago, I played it for about six months. Like just about every other multiplayer game out there, WoW players a faction to belong to, in WoW’s case, either the Horde or the Alliance.

This choice is often arbitrary, although once someone has chosen a particular faction, their friends will often choose the same one so they can play together. But at the time a player joins, they have no particular love for the side they choose or hatred for their faction’s enemies.

This soon changes, however, especially on game servers that promote warfare between the factions (so called player-vs-player servers, such as the one I played on). A raging hatred exists between players on opposite factions that extends out of the game world and onto forums, blogs and so on, where people insult each other, claim the other side has an unfair advantage, etc.

In other words, people who have a ton of things in common, from their frequently similar personal characteristics (young, male, etc.) to their obvious appreciation for the same type of entertainment, spend hours flaming each other as a result of an arbitrary, meaningless choice when they first started playing the game.

As in the world of video games, so in the world of web development. I’m sometimes dismayed by the attitudes expressed by Python programmers towards Ruby programmers, and vice versa.

Don’t get me wrong: lots of people from these two communities are perfectly civil towards one another, and some of the tension is simply a healthy competitive rivalry. But that is not always the case, which is weird: after all, both languages are dynamic and cutting-edge, both communities are producing fantastic software, and both communities are generally contemptuous towards people who program in PHP. So what’s the problem?

Or check out the massive flamewar on Smashing Magazine because someone had the nerve to suggest that web developers don’t need to use Macs. Five hundred comments (and counting) of Mac users bashing Windows users bashing Mac users, occasionally interspersed by pious Linux users wondering what all the fuss is about.

But all of these people are web developers. Some, of course, are respectful to each other, but others are not: the fact they are speaking to someone who is probably much like them, with the same career and probably many of the same interests, does not matter as much (at least at that moment) as that person’s choice of computer.

When we’re online, we often disagree the most with the people who are just like us. Is this the result of competition, like the conjured up war between the Horde and the Alliance in World of Warcraft or the pressures of the hyperactive pace of web development? Or is it a way of insisting that we are unique individuals, even when presented with evidence to the contrary – our peers?

Offline, the situation changes. Put a Ruby programmer and a Python programmer in a room together at a party and they’re bound to meet at some point and trigger the kind of endless, arcane-to-normal-people conversation that prompts their wives to suggest leaving. Put a couple of WoW players into a room at a party – actually, never mind, WoW players don’t really leave the house.

There’s a simple solution for all of this then: when you deal with people online, treat them the way you treat the people you see every day, in person. Even if they still use PHP. Or they’re Horde. You ganking bastards.

06
01
09

What, you’ve never heard of Manny Schwartz?

If you’re fairly well-informed when it comes to science, you may often feel, and sometimes express, skepticism about someone else’s supposedly scientific claims.

For example, if you were to see Suzanne Somers on Oprah telling women that injecting estrogen directly into their vaginas (don’t worry, that link does not go to a photo) will make them look and feel younger, you may think, “that’s crazy,” and you may even feel compelled to remark to someone near you that you believe “that woman is freaking nuts”.

When you criticize an apparently ridiculous person or idea, however, you open yourself up to a common line of attack, which is to point out that history’s revolutionary thinkers and inventors were usually mocked when they announced their discoveries.

I’m slogging my way through Steven Pinker’s The Stuff of Thought right now and I came across a brilliant counter-argument to that. In this paragraph, Pinker is discussing the radical linguistic theories of philosopher and psychologist Jerry Fodor:

Fodor correctly notes that history has often vindicated unconventional ideas – after all, they all laughed at Christopher Columbus and Thomas Edison. The problem is that they all laughed at Manny Schwartz, too. What, you’ve never heard of Manny Schwartz? He was the originator and chief defender of the theory of Continental Drip: that the southern continents are pointy at the bottom because they dribbled downward as they cooled from a molten state. The point is that they were right to laugh at Manny Schwartz. Extraordinary claims [...] deserve extraordinary evidence.

So the next time someone pulls this one on you when you express skepticism about an extraordinary claim, just ask, “What, you’ve never heard of Manny Schwartz?”



Life, politics, code and current events from a Canadian perspective.

Adrian Duyzer
Email me

twitter.com/adriandz

Proud contributor to
Director, Web Division at

Feeds

Meta