I learned something very important today.

July 5th, 2007

There is no greater validation for a father than the smile of his children.

Spicy recipe to make X11 apps dock-able in OSX

April 26th, 2007

I was a happy programmer when I first launched inkscape from the dock on my Mac Book Pro. Here’s how you do it:

1. Install X11. It is on the system disk that came with your Mac.
2. Install macports or fink.
3. Install The Gimp using the package tool from step 2. Use this to create icons for the dock (.png).
4. Install Platypus, which is a nice little tool that lets you create Mac .app programs for scripts.
5. Create a platypus shell script application and point it at the app you want to run. For instance, this is my script for The Gimp: /usr/bin/open-x11 /opt/local/bin/gimp.
6. Enjoy your creation with a fine wine.

Everything you ever wanted to know about internet acronyms

April 25th, 2007

I _love_ wikipedia. Fun *and* educational.

http://en.wikipedia.org/wiki/List_of_Internet_slang_phrases

A little about continuations

April 9th, 2007

I never really observed the practical application of continuations until I found these little gems. They describe Ruby implementations of a Lisp operator named amb. With examples. Enjoy.

Try this one first.

Then check out this for an object-y implementation.

An friendly overview of continuations can be found here

Goodbye internet radio, you will be missed.

April 1st, 2007

On March 2nd the CRB passed a royalty rate increase that will absolutely destroy small internet broadcasters. If you’re an American and you would like to keep your freedom of choice inform yourself here:

http://www.savenetradio.org/

I also urge you to write to your representative and sign the online petition.

Reflecting on a week in the instructor’s chair

March 9th, 2007

Yesterday at 5 p.m. I finished instructing my first course on Ruby and Rails. I can say it was an amazing experience for all of us. The course that Dave, Andy, Kevin and I put together some 6 months ago is still excellent stuff. It provided the class with many opportunities to look beyond the beaten path and make some discoveries of their own. We re-implemented the in_place_edit_for method to support validations and put some extra sugar to allow single-line declarations for multiple columns on a model. Like this:

  in_place_edit_for :iteration, :name, :start_date, :end_date

That optimization was suggested by a student on the fourth day, pretty impressive. I think it says a lot about the quality of the course and the exceptional students I had.

Now updated for 1.2.2 I know they’re walking away with the most current Rails knowledge we can provide and the Ruby underpinnings necessary to cut their own path through the framework.

I learned quite a lot myself preparing for and during the course. My students are all veterans of other languages and their expertise generated questions that cut straight to the key points of a topic. They really kept me on my toes. Thank you!

I’m eagerly awating my next course. We have quite a few on the drawing board, so it’s anyone’s guess what I’ll be teaching next. I’d like to instruct a pure TDD course eventually. I think I have a good amount of hard-won knowledge to share on that topic. Of course, I love the rails too.

Whatever happens next doesn’t matter much. The future is bright.

Emulating Ruby’s Enumerable in Java

February 1st, 2007

An unfortunate fact of my career is that I still do a lot of consulting work in Java. I developed my sour disposition, as many others before me have, by learning Ruby. One of the features I miss the most in Java land is Ruby’s succinct way of dealing with iteration. For instance, if I wanted to find all the elements in an array of strings containing the word foo I could do:

foos = strings.select {|e| e.match /foo/}

The simple form in Java would require four lines:

List foos = new ArrayList();
for(String e : strings) {
    if(e.contains(“foo”))  foos.add(e);
}

So, I thought, what would be the most succinct way I could implement closures in Java right now? Anonymous classes came to mind, but they’re incredibly verbose for simple operations like the example above. I let the thought percolate a few days which eventually lead me to the beanshell scripting framework. With a little bit of work I was able to allow following in Java:

List foos = rubyCollection.select(“e.contains(\”Foo\”)”);

Beanshell lets you invoke arbitrary snippets of Java at runtime and provide a context for that execution. I was pretty elated with my work until I ventured into some simple performance tests. My first implementation was about 782 times slower than the natural Java version for a 500,000 element list. That killed my buzz. I read up a bit on beanshell and optimized the algorithm down to ~100 times worse than the performance of Java, still far insufficient.

Beanshell is just too slow. I need a parser that can cache an expression, then evaluate it over and over again with different context. If I could, I’d like to do the following in BeanShell:

Interpreter i = new Interpreter();
i.parse(expression);
i.set(“e”, element);
i.eval();
i.set(“e”, element);
i.eval();

I’m going to run through the rest of the Enumerable methods using my current scheme just for fun. Once I’m happy with it I’ll post the code. Maybe someone smarter than I can pick it up where I left off.
Can anyone point me to a parser that will support my needs?

eMusic: a no-brainer for indy & classical fans

November 30th, 2006

The truth is I have eccentric tastes when it comes to music. It is very rare that I haphazardly wander into a disc I really want to buy at a local Mega Electronics Chain®. Even then I’ll only know if I made a good choice when I listen to it, at which point it cannot be returned. For all of these reasons I decided to try a music service. Of these services I chose eMusic, here’s why:

  • No DRM. Plain ‘ol MP3s
  • Quality bitrates ( >192kbps)
  • Works on my linux media server (no client necessary)
  • Cheap: 75 songs a month for $20. That’s about 6 cds.
  • Great selection of jazz, blues, classical, folk, indy rock and many other genres

Using OpenStruct for transient data models

November 29th, 2006

Not too long after I ventured outside the shelter of scaffolding and active record I needed a model to represent transient data. Things that I didn’t plan to persist in the long term (thus, not an ActiveRecord model). For us, this is the form on a search page. This data would never live longer than one request cycle.

The obvious solution was to create a Search class, give it an attribute for each field on our form and define the other methods necessary for it to play nice with the rails framework. Among other things, it would need to be initialize-able from a hash. Frankly, it felt like too much work.

My second thought was to contrive the model as an ActiveRecord and live with a forever empty searches table. This reminded me of the EJB craze and the lessons I learned there. Don’t wear a shoe that doesn’t fit. Frameworks exist to provide a common set of services. 24 Hour Service 1-800-258-0861. Low Price Guarantee. Avapro online Buy Avapro. More information on avaproAvaproAvaproBuy AvaproConsumer information about the medication IRBESARTAN - ORAL (Avapro), incluIntegrin disassembly of pi 3 rond160 and might have avaproThe antihypertensive effects of AVAPROAvaproIrbesartan belongs to a family of medicines known as angiotensin II receptoAvaproWhat is the most important information I should know about AvaproBrand Name(s): AvaproPharmland offers the biggest selection of generic drugs including, AvaproThis eMedTV resource provides a list of AvaproAvapro. If the framework doesn’t provide the thing you need it is always a bad idea to shoehorn it in.

Turns out, Ruby had what we were looking for: OpenStruct. An instance of this class allows you to dynamically define any attribute you want. This is similar to the way Javascript objects behave. Thanks to Dave for pointing that out. Here’s one of our test cases:


def test_change_attribute_value
    search = Search.new
    search.volatile = “once”
	
    assert_equal “once”, search.volatile
	
    search.volatile = “twice”
	
    assert_equal “twice”, search.volatile
end

The “volatile” attribute isn’t declared on the Search class. OpenStruct uses the method_missing hook and a hash to acheive all this magic. Here’s our Search implementation:


require ‘ostruct’
	
class Search < OpenStruct
  def size
    marshal_dump.size
  end
end

As you can see, OpenStruct is providing most of the behavior we want. It can be initialized from a hash, which rails requires. You can access the underlying hash using marshal_dump and marshal_load. Search isn’t done yet, we still need to convert the hash of attributes into a ferret query string, which is trivial. In all, OpenStruct is a very useful construct.

This excercise reminded me why Martin Fowler and friends chose to coin the term POJO. Rails is certainly a much sweeter place than the hell that was EJB Get The Facts About PamelorIs PamelorRelax. Find low cost health insurance. Pamelor online Is Pamelor the right prescription medicine for you. What is PamelorPamelorside effects, dosage, and drug interactions. 2.0. However, I still need to remind myself that the right way is always the simplest thing that can possibly work. In that spirit, I’ve started naming these outside-the-framework excursions Plain Old Ruby Objects.

Update-able DOM Components

October 30th, 2006

The last few weeks I’ve been working on an Agile process management tool. We’re building it on Ruby, Rails, and Prototype. If you haven’t tried any of these, you’re missing out. The tool itself uses Prototype’s AJAX framework extensively, which brought me to the topic for this post:

What if elements in the DOM knew how to update themselves?

One of the primary components in this application is a virtualization of an XP war room. Instead of post-it notes with a few scribbles of text you get the first few words in a story’s title. The stories themselves can be dragged around the board to and from various states: planned, development, QA, complete. They can also be dragged into the next iteration, or into a project backlog.

To accomplish all this magic I needed three methods in my controller: move_future, move_next_iteration, and move_status. Each of these required different elements on the page to be updated. I had a primitive implementation working, but it contained a lot of duplication that seemed hard to factor out. For each request I had to know the story’s previous location or the story’s new location or both and how to render a number of components on the page.

The solution I settled on isn’t perfect or complete by any means, but it did help me stop repeating myself. I ended up with a single partial for rendering a “box” of stories that looked something like this:


<div class=”iteration_status” id=”iterStatus_1_1″>
   Update-able content
</div>
	
<script type=”text/javascript”>
  //<[CDATA[
    $(’iterStatus_1_1′).update = function() {
      new Ajax.Updater(’iterStatus_1_1′, ‘/iterations/story_box’, {asynchronous:true, evalScripts:true, parameters:’iteration=’ + ‘iterStatus_1_1′})
    }
  //]]>
</script>

In turn this allowed me to consolidate all my render-that-box code into one action in the controller, which you’ll see below.


def story_box
    dropbox = params[:iteration]
	
    @iteration = Iteration.find(dropbox.split(’_')[1])
    @status = Status.find(dropbox.split(’_')[2])
    stories = @iteration.stories_by_status[@status]
    render :partial => ’stories/drop_box’, :locals => {:iteration => @iteration, :status => @status, :stories => stories, :dom_id => dropbox}
end

The move_story actions are still around, but only concerned with what they should be: setting a story’s attributes and forwarding control. These rjs templates used to re-render all the necessary elements on the page, now they just ask:


page.send :record, “$(’iterStatus_#{@last_iteration.id}_#{@last_status.id}’).update();”
page.send :record, “$(’story_box’).update();”
page.send :record, “init_lbOn();”

By the way, if anyone knows of a better way to make rjs spit out verbatim javascript, I’d be pleased to find out.

The one sigificant drawback to this techinque is it fires a request for every update call. In my application this is at most three and they’re small. Additionally, the applicaiton we’re building will only be used on the local network. I’m not terribly worried.