infundibulum

Wikipedia will Eat us All

April 26th, 2006

I was reading somebody’s description of their job interview at Google, and apparently they asked him something to do with the birthday paradox:

you are at a party with a friend and 10 people are present including you and the friend. your friend makes you a wager that for every person you find that has the same birthday as you, you get $1; for every person he finds that does not have the same birthday as you, he gets $2. would you accept the wager?

And I thought to myself, wouldn’t it be funny if the birthday paradox had its own entry in Wikipedia?

Birthday paradox - Wikipedia, the free encyclopedia

Honestly, it’s becoming a little frightening.

Ugh

April 11th, 2006

Get your own damn sandwich.

I find it weird

March 30th, 2006

That more of the CSS design wonks of the world haven’t produced stylesheets for Wikipedia.

Flickr vs Google Images

March 11th, 2006

I didn’t think I would ever find myself thinking that a site that got its started from scratch could come to the point of actually being better than Google, but as far as image searching goes, Flickr really seems to have gotten there–specifically since they added tags.

Case in point: I was messing around with some layout experiments for Blogamundo, and I wanted to know what “splotches” looked like. (Kind of hard to explain the idea…)

Anyway, check out the results for “splotch” on Google Images. Certainly splotchy. But there are some odd ones in there… including a rather unfortunate woman whose jugular seems to be exploding.

O.o

Then I started digging around in Flickr tags:

http://flickr.com/photos/tags/splotch/

http://flickr.com/photos/tags/splotchy/

Etc.

Pretty quickly, I came across a rather amazing (to me, at least) comment:

glueslabs says:

nice detail on concrete.

you should submit this to my new group:

www.flickr.com/groups/splotches/
Posted 8 months ago.

Okay, right. So there is actually like a group of people collecting splotches. 105* photos, of splotches.

Flickr, for the win.

* Um, 107. Since I first wrote this post.

The Most Annoying thing about Python

March 6th, 2006

Python is my favorite language.

But I have an axe to grind, here.


from xml.sax import ContentHandler
class MyHandler(ContentHandler):
def __init__(self):

This is the typical beginning to using Python’s standard xml.sax module, which implements a SAX parser.

But that’s sort of irrelvant. What I think is confusing is the class syntax:


class MyHandler(ContentHandler):

Call me crazy, but in that line ContentHandler looks like a parameter. Everywhere else in Python, and indeed in most languages on the planet, parens mean “this is a parameter.” It doesn’t mean that at all. It means “MyHandler is a kind of ContentHandler.” So if you want to compose a variation on the theme of ContentHandlers, you write MyHandler(ContentHandler).

As far as how the thing is actually called, it’s SIMPLE: you just look in the __init__ method. Because you see, the __init__ method is sort of the constructor. Not really, but sort of. (There is also a __new__ method, and I really haven’t figured out what the hell that does.)

So when you read as far as:


class MyHandler(ContentHandler):
def __init__

You have to think “to see the way that my ContentHandler will be called, I have to look at what comes after the __init__.” Which is back in the realm of normal, right? Our old friends, the parentheses, who have changed their wayward ways and now really do mean something like “here comes a list of parameters.”

Except, not really.

Well okay yeah really, but the thing is, the first parameter isn’t something that gets passed in when you do the __init__ dance… it refers to “the thing itself.”

It’s “self.” (You can call it anything you want, actually, but you shouldn’t, because to call it anything else would be, you know, confusing.) So the list of parameters there is really only parameter-y from the second argument on. Assuming you have more than one parameter. If there is just self, well… it’s like the self isn’t really there. But you have to have it.

Plain as day.


class MyHandler(ContentHandler):
def __init__(self):

Right, so, let’s review.

MyHandler is a kind of ContentHandler, even though it looks just like a function, and ContentHandler were a parameter. You must banish that intuition because it is wrong.

And then to instantiate the class, you need to have an __init__ (actually, come to think of it, I think I heard somewhere that __init__ is optional, did I mention that? Although people don’t actually seem to leave them out, well… ever). And actually when you initialize the thing, the init isn’t part of the call.

And please, people, two underlines, people, both sides. Kthx.

And you have to unbanish that bit about parameters, because now parentheses mean parameters again.

Except that the first parameter is not a parameter, it is self.

Behold, the self.

Behold, me kicking my SAX parser in the genitals.

Yes, I know that any programmer who is halfway decent will quickly get used to such details and move on with their lives. But I defy anyone to claim that they guessed that this is how all this ever-so-deceptively-simple-looking syntax worked when they first encountered it.

And besides, what good’s a weblog if you can’t whine in it.

Heresy

February 6th, 2006

Sometimes, I must admit that Microsoft’s stuff is easier to understand than the W3C’s. For instance:

DOM extension - getElementsByTagNames

In this description of useful function by JS guru PPK, we see that IE supports a function called “sourceIndex.”

The first element in the page (<html>) has sourceIndex 0, the second (<head>) has sourceIndex 1, etc.

If you ask me, that’s pretty easy to understand.

Now compare the WC3’s Level 3 Dom function:

compareDocumentPosition is a Level 3 Core method that compares the document position of two nodes and returns a bitmask:

  • 1: Position disconnected
  • 2: Precedes
  • 4: Follows
  • 8: Contains
  • 16: Is contained by

If, for instance, a tag is contained by and follows another tag, compareDocumentPosition returns 16 + 4 = 20.

We’re only interested in compareDocumentPosition’s values 2 or 4: precedes or follows. Therefore we do a bitwise AND 6 (& 6) so that the result is 2 or 4 (of course it can’t be 6: a node cannot both precede and follow another node).

Yes, it gives you a lot more information, and so it’s more useful in the long run. But just looking at the description is enough to make my poor eyes glaze over.

And as long as I’m being heretical, I always thought Microsoft’s (clearly incorrect) interpretation of the CSS box model made more intuitive sense.

Now I shall go and say my ablutions.

Getting the font-family of selected text?

November 30th, 2005

I have the Firefox DOM Inspector doohickey (which you should have too if you do any significant amount of web design), and also a plugin called “Inspect Element.”

One cool trick you can do once you have all this set up is to highlight some text, click “Inspect element” in the context menu, and then select “Computed Style” from the dropdown in the right-hand pane of the DOM Inspector. Then you can go and look at font-family and see just what fonts are specified for the text you selected.

So, here’s my question:

It must be possible to access this info from Javascript. Then, I could make a one-click bookmarklet so I could select some text and have the font-family value pop up.

That would be fly. So… anyone know how to do it?

Bueller? Bueller?

I for one welcome our Browser Overlords

November 28th, 2005

One time I was talking in one of the Linux IRC channels.

Generally I can only handle doing that for about five minutes because it seems to be an important shared goal to make people feel dumb.

*cries*

But I remember back in the day there was a weird extension to the Konqueror web browser that let you open up a shell in the bottom half of the screen, almost as though it were a web page.

And I thought that was kind of neat, because you could hack on web pages textually and see how they looked, all right in the same application. So I started thinking about, for instance, Javascript and bookmarklets and how the address bar was almost becoming a command line of sorts.

So I meekly suggested to the Linux geniuses that some day maybe the browser and the shell would merge. And in fact, the more I think about it. the more I’m convinced that this will be the case. In fact, I’ll just say how I really feel: I suspect that the distinction (as far as most users are concerned) between the operating system and the browser will just go away.

But all I said to the people in this channel was that I thought it would eventually be possible to run a shell from the browser. And they went BERZERK. They actually said stuff like “I will spend my life working to prevent it.” And I was like buh?

Well anyway, leave it to the ever-avant-garde _why to bring us one step closer: try ruby! (in your browser)

Killer App

November 8th, 2005

Using voice chat + a VNC to develop software is an amazingly productive way to work.

Mojibake

November 2nd, 2005

Now there’s a useful word:

Mojibake is a Japanese loanword which refers to the incorrect, unreadable characters shown when a piece of computer software fails to render a text correctly according to its character encoding.

Mojibake - Wikipedia, the free encyclopedia