Monthly Archive for September, 2008

Redtip: Rails plugin

I’ve finally got around to putting Redtip, a Rails plugin I’ve been working on, up onto github. It can be found here; I also have a minimal project page (for now) here.

Redtip is mainly a few helper methods and a lot of JavaScript that gives you some tooltip-like popouts to use, or some that act a little more like dropdown menus. I needed that sort of functionality for some features I was working on, and wound up basing the plugin off of Craig Ambrose’s Redbox, which was in turn based on Thickbox. So, hooray for code reuse. In the words of Hal Abelson, if I have not seen as far as others, it is because giants were standing on my shoulders.

If you want to check it out, try script/plugin install git://github.com/philcrissman/redtip.git

What Microsoft Could Do To Improve Their Image

It would be very easy.

They could release an update to IE which consisted of a script which removed IE and downloaded Firefox 3, accompanied with an apology for IE ever having existed.

I’m just saying. I’d respect them more if they did it, for one.

The haml of the gods

I really like haml.

Haml is just a markup language that avoids a lot of the repetition and extra cruft which xml-based markup requires.

It’s so easy to install and use that writing Yet Another Short Haml Tutorial would be a colossal waste of time. Just visit the above link and you’ll be running in moments.

What? You aren’t using Ruby for web applications? (Not that there’s anything wrong with that) Oh. Well. Then you can’t use haml. Sorry!

Stupid Ruby Tricks

I can remember, once, long ago, being entranced with the idea of writing programs whose output was identical to its own code. This is, of course, entirely impractical and not really good for anything.

Ruby has a built-in variable, $0, which refers to the name of ruby program currently being executed, and which therefore makes the writing of self-describing programs trivial. So, you can write a ruby program which outputs itself like so:

1
2
#!/usr/bin/ruby
IO::readlines($0).each{|n|puts n}

Pretty nifty. Can it get any shorter? If you’re willing to use bash commands, yes it can:

1
2
#!/usr/bin/ruby
system("cat #{$0}")

If you want to dispense with the shebang and run it with ruby stupid.rb (or whatever you’d like to title your work of art) then you can shave another 15 characters off of it. The shortest way I could see to get it would be

1
puts `cat #{$0}`

which assumes you have to run it with ruby ... rather than just with it’s own name. That’s all rather pointless, of course.

Of course, the $0 variable also means that you can do exciting things like rewrite the file which is currently executing while you’re executing it:

1
2
#!/usr/bin/ruby
File::open($0,mode="w").write('puts "Hello #{`whoami`}"')

Have fun with that. Oh, and, um… only try this at home.

mysql –i-am-a-dummy

In case we ever need it, mysql has provided us with the --i-am-a-dummy command line switch.

It’s a synonym for -U (--safe-updates) which will “Only allow UPDATE and DELETE that uses keys.”

In other words, it won’t let you accidentally send a file with DELETE * FROM thetable without a WHERE clause, for example. [link]

So, yeah, it’s just a reasonable little safe-mode feature. I was just chuckling because of the optional name.

Kool Aid, Confirmation Bias, and the problem with Democracy

Confirmation bias (though you can probably discern the meaning just from thinking about the phrase) is a name given to our tendency to gravitate toward the evidence that confirms whatever it is that we already believe. It’s pretty easy to want to think that it’s just other people (usually “the other side” of whatever the dichotomy happens to be) is suffering from the effects of confirmation bias, while we, of course, are objective and reasonable, as is “our side” (if applicable).

Paul Buchheit had a post along these lines not long ago:

Humans aren’t rational — they rationalize. And I don’t just mean “some of them” or “other people”. I’m talking about everyone. We have a “logic engine” in our brains, but for the most part, it’s not the one in the driver’s seat — instead it operates after the fact, generating rationalizations and excuses for our behavior.

Granted, Paul’s an entrepreneur and not a social scientist. Still, I think it makes a valid point.

Pop culture has a morbid term for an extreme variety of confirmation bias; we call it “drinking the kool aid,” after the mass suicide in Jonestown where cyanide was taken in something like Kool Aid. Again, because of the origin of the term, “drinking the kool aid” is nearly always something that “other people” do. Not us. Those people, you know, them. If anyone does use the term to apply to themselves, it is usually in the past tense, to describe their affiliation with some group or idea of which they would now prefer to distance themselves. What isn’t usually considered is that almost anyone might be considered by someone else to have “drank the kool aid.” To an environmentalist or a global-warming skeptic, each probably thinks the other side has had some. Any pair of opposing viewpoints you might consider, each one is probably going to describe the other in terms that are usually reserved for dangerous cults.

So, we’re having an election.

Please don’t take the title wrongly; I like democracy. I can’t think of an alternative that would work better. That said, this means that we are leaving the decisions up to people who are probably not going to change their minds as the result of a reasonable argument from any angle. We are not inclined to listen to evidence that would imply that our carefully constructed beliefs could be incorrect. And even if we do change our minds, it isn’t necessarily for rational reasons.

This evening, I turned from the tail end of Palin’s speech to glance at twitter, and all I saw just depressed me. There were a lot of people who liked and disliked Palin, but I just had the unshakeable feeling that she could have said anything, or nothing, and the same people would have disliked her, and the same people would like her. Not that the speeches don’t matter, and it was a fine speech, as political speeches go. It’s just that judging from reactions, it didn’t matter. No one is changing their mind.

Now, I know that, statistically, there are a significant group of swing voters, who do change their mind; or voters who have already made up their mind but who don’t necessarily make it to the polls on voting day unless properly motivated. So campaigning, really, is not about changing too many minds; only a few minds are even willing to consider changing at all. Everything else is just about motivating the choir to remember to go vote in November.

Lest I leave some stone unturned in this, admittedly, rather depressing outlook on contemporary politics, I know that some folks do change their minds. Sometimes rather dramatically; hippie radicals become staunch conservatives, Ayn Rand devotees become anarchists. It happens, but it doesn’t happen a lot. Even when it does, when all that we hear about are such extreme examples, if you don’t agree with someone’s choice of epiphany, the temptation is simply to think that perhaps they too simply got a little too close to the kool aid. But still, yes; viewpoints can change.

But mostly, I think we don’t let them. Too often when we do change them, it’s not for any rational reason. It’s for a feeling, or a sense of group membership, or to rationalize something or other.

I’m not going to start writing about politics. I’m tired of politics. It’s especially difficult to get enthused about something when you realize that both sides (unfortunately here in the US there are de facto only two choices, for all intents and purposes) have already made up their mind, and that the results of the election is really a function of who can raise the most money and get the most of “their people” to get off the couch and commandeer a pencil at the polls come November. This lengthy post is just a long drawn out sigh of resignation.

If you’ve bothered to read this far, I promise to write something cheerful next time, like a post about drawing state machines for non-deterministic finite automata or something.