Author Archive for Phil Crissman

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.

Some Ruby & Rails Tricks

I certainly can’t claim to have discovered these tips; but they’ve been pretty helpful to me. Maybe this will just make them a little easier to find for whoever is looking for them next.

Getting A Collection’s Index From Within a Partial

Lets say you’re passing a collection to a partial, but that somewhere in that partial you are interested in knowing which index you’re at. Do you need to implement a counter? Nope; there already is one. A collection passed to a partial implicitly creates a counter called [partial_name]_counter. So, if you called with

1
< %= render :partial => 'thing', :collection => @a_few_of_my_favorite_things %>

then in your partial, you could use:

1
< %= thing_counter %>

to return the index as you plow through the collection. Life is good. Rails is looking out for you. (Hat tip to GMarik, which is where I saw this one.)

Obtaining a Class name From a String

Today I found myself wanting to take a string, let’s say "Thing", and use it as a class name, Thing. Again, it turns out this can be done. In Ruby, class names are constants, so you can do

1
2
str = "Thing" #=> "Thing"
Kernel.const_get(str) #=> Thing

Hooray!

Make Finding Easier

Find yourself writing long, complicated find expressions in your code? There is a better way.

Perhaps in your code… maybe even in a view… maybe you want to find all Things that don’t belong to the current use, and which are flagged with some property, and you’re temped to write something like:

1
Thing.find(:all, :conditions => ["user != ? and flag = true", current_user])

What we could do is put some has_finders in the Thing model, something like

1
2
3
class Thing < ActiveRecord::Base
has_finder :exclude_user, lambda {|user| {:conditions => "things.user_id != #{user.id}"}
has_finder :with_flag, :conditions => "things.flag = true"

Having done that, you could now replace that first bit with:

1
Thing.find(:all).with_flag.exclude_user(current_user)

It’s a little shorter, sure, but more importantly, when you read it, it just makes more sense. A completely new person coming to look at this line would have a good idea what it was doing without even looking in the model to see what the has_finders were doing.

Okay then

If you’ve spent any amount of time using rails, these probably aren’t new to you. Everything’s new at least once, though, so hopefully these are helpful to someone.

Other favorite ruby or rails tricks? Leave a comment! Heck, we’re not prejudiced, here, go ahead and comment with your favorite Python or Perl or [other language] tricks, too, if you like.

Up North

So, I’ve been working away from home for a few days….

Those green chairs on the rock also happen to be where the wi-fi reception from the resort across the bay comes in the strongest….

Yeah. It was a tough weekend.

Crocs

Evidently some people don’t like crocs. The shoes, that is. I have a pair I got for Christmas last year that I wear just about everywhere, and I’m stumped why various parties have taken it upon themselves to disapprove of my footwear. They are comfortable and they have no laces. These are highly desirable features, for footwear.

When I don’t like stuff, I just… don’t buy it. What happened to that?

Fortunately, folks opinions on the relative hipness of my apparel does not influence my behavior. Also, let the record show that Jeffrey Rowland’s web comics are excellent, and his Croc-hatred does not alter this.

Flex and Rails

I’ve started to be interested in Flex, recently. This interest piqued when I saw some of the rates that were being offered for Flex developers in this area, so I suppose my interest is completely mercenary and not particularly motivated by an interest in the technology, per se. I think that I’m okay with that.

That said, it does look interesting. And, naturally, some people are using Flex front-ends for Rails applications: one good resource in particular looks to be http://flexonrails.net/.

Also interesting is Project Sprouts, which is a gem and seems to make good use of ruby and rake to automate some aspects of ActionScript, AIR, and Flex development. I’ve had no time (yet) to give it a test drive, so this is nothing more than a pointer: if it sounds interesting, give it a look.

Since I’m thinking about ActionScript, this is as good a time as any to revisit the venerable ActionScript Jabberwocky. Enjoy.

The ActionScript Jabberwocky, from http://www.turdhead.com/2004/08/16/the-actionscript-jabberwocky/

The ActionScript Jabberwocky, from http://www.turdhead.com/2004/08/16/the-actionscript-jabberwocky/

Startlingly Obvious Truism Becomes Revealed As More True Than Previously Thought

I’ve had the opportunity to work with Rails for a good three weeks straight, now. Not just evenings and “spare time”, like I might have before, but actually all day. Most of that has been front-end work, views and the like, but enough of that is tied to other parts of Rails that you definitely start to get a better picture of how it all fits together.

Hence the title, as I realize anew what everyone already knows, that you learn more by doing something than by reading about it.
Continue reading ‘Startlingly Obvious Truism Becomes Revealed As More True Than Previously Thought’

Joyent has JRuby

So, Joyent has JRuby support. That is all.

Long Sign-Up Forms Considered Harmful

Considered useless, maybe, would be a better title.

Of all the various trends that have accompanied the wide range of the “web 2.0″ school of applications, the one feature that sticks out, that I really like, is the minimalist sign-up form. Whether they call it signing up, registering, creating an account, the trend has been:

  • To ask you for less
  • To make it quicker
  • To give you options (login with OpenID, Twitter, Gmail, Yahoo ID, etc.)
  • To make any further information optional

It used to be that any time you “signed up” on a new website, it seemed that you had to go through a long form, including your address (what?), telephone number (you’re calling me?), username, first name, last name, email address, password (twice), favorite color, inseam measurements, and so forth. And for awhile, because that was the norm, I think people online simply accepted that.

No more, thank God. New web applications, if they don’t accept OpenID or an existing ID from a different service, generally just ask for an email address and a password. There’s no particular reason you can’t use an email address as a User ID for many applications, so why make it another field? If you want to have the option (for privacy reasons… not a bad idea), you can always allow people to set a username after signing up. Make it simple.

I can’t speak for anyone else, but as a result, my tolerance for old school, long, multiple page, sign up forms has dipped below zero. If I visit a new service and click “sign up”, chances are I’m just considering checking it out. If click “next”, and see Yet More Fields to fill out before I’m able to get into the application/web site… I’m liable to just close that tab and forget it.

Schroedinger’s Glass

What if we put a glass of water with water in it at exactly 0.5 ratio to the size of the glass. If we also put a person in the box and give that person a drug with a random 50% chance of turning the person into either a pessimist or an optimist, and close the box before we know the effect of the drug on the person, the I suppose the glass is both half-full and half-empty.

Yet another example of why people who don’t really study physics probably shouldn’t be allowed to talk about it.