Belief

The rogue searches a trap door for booby traps.

DM: You believe that it is free of traps.

Chris: And you believe you still want someone else to go first.

Rupert And Rock & Roll Numbers

I love humor with depth. I’ve lately been enjoying some metahumor—humor that alludes to a detail related to the work, not the story of the work itself:

In Harry Potter & The Half-Blood Prince, Professor Slughorn never can quite remember the name of Harry’s friend Ron Weasley. Slughorn tells Harry that he has “a house-elf taste every bottle after what happened to your poor friend Rupert.”

Rowling is clearly nodding to the fact that the actor who portrays Ron in the movies is a fellow by the name of Rupert Grint. [chuckle]

In a recent episode of Phineas & Ferb, Lawrence (Ferb’s father) is watching television. (We don’t see what he’s watching, just the flickering of light on his face.) Finally he pipes, “This isn’t much of a horror movie! Where are all the rock & roll numbers?”

Now that’s pretty funny by itself in a Monty Python-esque non sequitur sort of way. But it’s bloomin’ hilarious if you realize that the guy who voices Lawrence Fletcher is Richard O’Brien, the man behind The Rocky Horror Picture Show, a musical “horror” film. Brilliant! (Rocky Horror is not exactly a film I recommend, by the way, but I must confess that I have seen it.)

Also in a recent Phineas & Ferb (perhaps the same episode), they did a takeoff of one of the Twilight movies (which they called something like “Almost Dark”—heh, heh). The werewolf character is voiced by none other than Michael J. Fox, the original ’80s Teen Wolf. Genius!

Enumerate, Iterate, Pretty Kate, …

Ever wanted to iterate over some objects using Java’s for each syntax, but the only interface exposed is an Enumeration? I have.

There’s an exercise in the Head First Design Patterns book that adapts an Enumeration to the Iterable interface. Pretty nifty, so I coded it up and used it in some code at work. Works great!

But then I found this: the list() method of the Collections class. It stuffs all the items in an Enumeration into a List. And it’s been there since Java 1.4! Where in the world have I been?

Anyway, the upshot is that instead of having to use this old drivel

Enumeration<Nargle> nargles = Nargle.getNargles();
while (nargles.hasMoreElements()) { 
  Nargle nargle = nargles.nextElement();
  // do something with nargle
}

You can do this

for (Nargle nargle : Collections.list(Nargle.getNargles())) {
  // do something with nargle
}

Yes, that is a sight better.

Around “To Where”

When did “around” replace “regarding” or “with respect to”? And when did “to where” replace “so that” or “in order to”?

Examples:

“Remind me what you were saying around the quarterly report.”

“There’s no forest so big to where they won’t find you.”

Really? We can’t do any better than this?

I Never Dreamt Of Such A White Christmas

I have lived all 35 of my years in Limestone County/Athens, Alabama. I never remember having snow on Christmas. The most we hope for around here is a wet Christmas, but never a white Christmas. Really, for most of us around here, “just like the ones I used to know,” is simply a bald-faced lie.

Well in outright protest against history, we awoke this morning to this:

Our front yard covered in snow with falling flakes visible in the foreground

Early morning snowfall

Our neighbor's faux well covered in snow with falling snowflakes in the foreground

Snow-covered well

The view of our front yard and driveway and in the distance, a neighbor's house, all covered in snow with snowflakes still falling

White Christmas on the front porch

Our back yard and our kids' swing set covered in snow

Snowy swing set

We Southerners hardly know what to do with ourselves.

(Update: Evidently I have forgotten that we had snow on Christmas in 1989. Nevertheless, it was nothing like this.)

Webkit Disrespects My Personal Whitespace

I’ve been trying to put some of CSS3′s nth-* selectors to use in a site I’m working on right now, and I’ve run into a problem. I’m testing my markup and styles in Safari 5 (before moving on to other browsers), and I am trying to style child elements 3, 7, 11, etc. So I write this rule:

p:nth-of-type(4n - 1) { … }

That should work, right? After all, 4(1) − 1 = 3; 4(2) − 1 = 7; 4(3) − 1 = 11.

Well I open up Safari, and my changes haven’t taken. OK. How about a different but equivalent equation?

p:nth-of-type(4n + 3) { … }

Again, pretty simple: 4(0) + 3 = 3; 4(1) + 3 = 7; 4(2) + 3 = 11. The last one hasn’t taken, for whatever reason, but this one’s right on.

Still nothing.

I begin to doubt my math skills. I’ve been doing software of one type or another for 15 years, but my bachelor’s degree is in electrical engineering. I had to take four calculus classes, linear algebra, and differential equations. OK, I haven’t used most of that in years, but an + b is simple algebra—stuff I’ve been doing for over 20 years. I know simple algebra.

I decide to fire up Firefox (version 3.6.12). Lo and behold, there is the formatting I’ve been trying desperately to get to show up. Firefox gets it (so does Opera, for the record), but Safari doesn’t (neither does Chrome). Evidently we have a Webkit bug.

For grins, even though it won’t get me where I want to go, I try this:

p:nth-of-type(4n) { … }

The formatting appears correctly in both Firefox and Safari! Therefore Webkit does understand nth-of-type, but something about an + b gives it heartburn that an doesn’t.

I try one more thing: remove the whitespace in the equation.

p:nth-of-type(4n+3) { … }

It works! Safari and Firefox both rendered the formatting properly. Webkit just doesn’t care for the whitespace.

But is whitespace forbidden in the equation? Here’s what the spec has to say:

Whitespace is permitted after the “(“, before the “)”, and on either side of the “+” or “-” that separates the an and b parts when both are present.

Valid Examples with white space:

:nth-child( 3n + 1 )
:nth-child( +3n - 2 )
:nth-child( -n+ 6)
:nth-child( +6 )

http://www.w3.org/TR/css3-selectors/#structural-pseudos

So then, we do have a bug. Webkit doesn’t respect the whitespace in nth-child and the other nth-* selectors. The workaround is easy enough, but it’s going to be hard for me to break the habit of adding space around the arithmetic operator. It’s a best practice, so far as I’m concerned, for code readability. Nevertheless, the expressions are simple enough that it’s not a terrible price to pay to get Safari/Chrome to play.

If you want to see it in action, check out this test file. Below is a screen capture of Safari’s rendering (left) and Firefox’s rendering (right). As you can see, Safari only renders nth-child(2n+1) correctly while Firefox renders them both correctly.

Safari's rendering is on the left. It does not render nth-child(2n + 1) correctly, but only nth-child(2n+1), i.e., without spaces. On the right, Firefox renders both correctly.

nth-child Rendering Comparison (Safari vs. Firefox)

How To …

#1, sure. I can understand the curiosity about #2. But #3? I thought that was pretty widely known.

Suggestions at Google for "how to"

Suggestions at Google for "how to"

Widely known enough not to be the third highest entry in Google Suggest!