PROTIP: Rails + JSON + Flex

October 3rd, 2007

I had problems getting the Flex JSON parser to consume the default Rails JSON output of #to_json, and I managed to find this setting to put in my environment.rb:

ActiveSupport::JSON.unquote_hash_key_identifiers = false

And Flex happily drank down the JSON I fed it :)

Thunderbird’s Tags are Worthless

October 2nd, 2007

One of the big features of Thunderbird 2 was that you could now tag your messages. I was excited, until I tried to use it.

Unfortunately, they’re tags in name only.

In fact, they look and function no differently than the old labels. The only difference it seemed, was that you could create as many as you wanted, and you weren’t limited to 10 of them.

So why aren’t Thunderbird 2’s tags actually tags?

For me, the reason is that they are expensive to create:

Thunderbird tags suck

Tags are nice because they’re lightweight, and inexpensive. They’re cheap. When you use del.icio.us, you don’t have to go through a dialog to add a new tag, you just type it. You’re not prompted if you type a tag that you already used. Indeed, that is the benefit of tags; they’re organic and they align with how your brain works.

Adding tags through a dialog just doesn’t work: it’s slow and expensive.

Feeling Constrained

September 27th, 2007

This layout needs to go. See those links to the right (if you’re reading this on the site)? Worthless.

I know Google loves the link juice. The site’s too narrow.

Ruby: Using Array#assoc to keep ActiveRecords in order

September 9th, 2007

Lately, I’ve had the need to sort ActiveRecords by a certain attribute, but the order is completely arbitrary, and supplied by the user.

Take, for example, the following call to a model in Rails:

input = %w(MN CO TX CA)
State.find_by_state_code(input)

This generates SQL that looks something like:

SELECT * FROM states WHERE state_code IN('MN','CO','TX', 'CA')

state_code
----------
CA
CO
MN
TX

Seemingly random results (actually alphabetized, but still worthless to me), but I have a specific requirement to process the results in the order the user specified (MN CO TX CA).

We can solve this by using Array#assoc to build a simple index of States and their codes:

input = %w(MN CO TX CA) # user-supplied
states = State.find_by_state_code(input)
states.map! { |state| [state.state_code, state] }
# states now looks something like:
# [["CA", #<State state_code="CA">], ["CO", #<State state_code="CO">], ["MN", #<State state_code="MN">], ["TX", #<State state_code="TX">]]

Now we iterate over the user-supplied list, and use assoc to pluck out the state that we want:

input.each { |s| puts states.assoc(s).last.inspect }
#<State state_code="CA" ... >
#<State state_code="CO" ... >
#<State state_code="MN" ... >
#<State state_code="TX" ... >

Previously, I was doing some ugly mumbo-jumbo with creating a hash, but assoc is a much cleaner solution. This also allows me to stick to using the SQL IN() operator, instead of iterating over the user input and doing a single call to the database, which obviously gets expensive.

This sort of reminds me of a Schwartzian Transform, although it’s not exactly the same.

Tom Poppendieck: When not to use agile

September 6th, 2007

I found this little nugget while surfing the “Selling Agile” Yahoo group (My emphasis added):

Lean/Agile is at it’s foundation, the fourth industrial paradigm, the first being Craft Production, Factory Production with machine tooling, Automation and Taylorism. These come along every hundred years or so and take a few decades to work through. Each paradigm includes the preceding one and makes it dramatically more productive.

There is no need to sell agile except to organizations that want to survive long term. If they don’t see the threat/opportunity they cannot succeed with agile or lean nor can they sustain economic viability in the long run.

No Incentive

September 4th, 2007

I recently got the following email from Apple, asking for 15 minutes to fill out a survey:

Apple Customer Survey

————————————————————-

Help us develop better products for you.
Please complete the Mac survey.

Thank you for your purchase of a Mac computer. Please take a moment to complete a fifteen minute survey to help us understand how to better meet your needs.

Your responses will remain strictly confidential and results will only be viewed in aggregate.

To take the survey, click on the following URL or copy it into your Web browser: [url removed]

Thank you for your participation.

Now, why should I fill out a survey you dumped into my INBOX? The email you sent provides no benefit to me, besides helping you develop better products for me. Where’s the reward in that?!

15 minutes is 15 minutes I could spend working (or blogging about an annoying survey email!). Without any incentive to fill out the survey, why would I even bother?

Update: I took the survey and they didn’t give me a single stinkin’ thing.

Yes I am still alive

August 29th, 2007

Matthew writes about blogging again, so now I’m considering it.

What would I blog about?

Edit: Comments turned on :P

Logitech Control Center for the Mac is completely fucking worthless.

March 10th, 2007

I recently heard that Logitech had new drivers out for the Mac. I was interested, because my most favorite mouse in the world is the Logitech MX500 series of mice. Nice shape, lots of useful buttons. I got sick of not being able to use the “Cruise up” and “Cruise down” buttons for scrolling quickly, and I really wanted to be able to use the forward and back buttons on the mouse for web navigation.

The only problem is that Logitech has their head completely engulfed in their ass when it comes to writing drivers that work.

First off, their control panel crashes more than Mel Gibson. I was so afraid of making the panel crash, that I’d set one button, and back all the way out to make sure I didn’t lose anything.

Once I managed to get my buttons configured just right, I was disappointed to learn that however they implemented the “Expose” feature was frustratingly ever so slightly different than Apple’s.

You see, I like to put Expose on the application switcher button on the MX500. The application switcher button is PERFECT for this, and it’s really fast. With default Apple drivers, I can press and hold this button to activate Expose, mouse-over a window, and release the button to have Expose “cancel.”

Because Logitech sucks ass, I have to press the button once to activate, and press it again to deactivate. Screw that.

I managed to get around this problem by mapping this button to “Mouse Button 6,” which is then set to activate Expose in the Apple control panel pane.

Finally, everything was perfect, or so I thought.

Then I decided to install the Logitech drivers on my MacBookPro (I had been using them on my Mac Pro), and a totally new problem comes up.

Unplugging the Logitech MX500 with these piece of shit drivers installed causes my laptop to kernel panic. Every. Single. Time.

With all due respect, Logitech, fuck you. You’ve lost a customer. All I ever wanted was to use my mouse buttons.

Son of blog.caboo.se

February 13th, 2007

The Caboo.se blog, the blog of my virtual hangout, is back, with bigger-than-ever fonts.

Ruby.MN Presentation Slides - GIS on Rails

January 30th, 2007

The slides from my talk at the January 2007 Ruby.MN meeting, entitled “GIS and Rails” are available.

The slides cover the use of Rails, PostgreSQL/PostGIS, GeoRuby, spatial_adapter and YM4R/GM for creating a simple zipcode map, which is adapted from Guilhem Vellut’s tutorial.

Edit: Wow, what a turnout tonight! I appreciate the positive feedback from the presentation.