Sunday, May 15, 2011

A Pattern for Nested Asynchronous Calls

I recently wrote an HTML5 application that loaded a large data set into the browser using nested calls to a web service. The first call loaded up information to make a set of subsequent calls, each of which in turn loaded up information to make a third set of calls.

You could point out that seems to be a lot of interdependent calls to get data. In my defense it was a third party service and I did not want to write my own server to handle data aggregation. Yes. I was being lazy. So I continued to load data in a piecemeal fashion and used the following callback pattern to provide incremental feedback on the loading process.
function loadData(stepCallback, endCallback) {
...
}
The loadData function above calls stepCallback() whenever one of the nested calls returns and endCallback() when all of the nested calls return. I used this pattern of callbacks to create a polite loading window that notifies users about what is being loaded in real time.

I may be lazy, but I do have manners.

Sunday, November 21, 2010

Dating yourself

After being dissatisfied with the complexity of JavaScript date widgets, I wrote this snippet to create a natural language solution, backed by the Datejs library.  It works by parsing the text a user entered on blur. 

It's a little rough at the moment, but a few refinements could make it just as effective as some of the more complicated implementations out there.
$('input.datefield').blur(function () {
  var field = $(this);
  var date = Date.parse(field.val());
  if (date) {
    field.val(date.toString("hh:mm tt"));
  }
});

Monday, October 04, 2010

How sexy is your form?

I attended a presentation by Stephen Anderson on The Art and Science of Seductive Interactions today.  He has an approach to design that explicitly incorporates behavioral psychology and is encapsulated by a deck of cards which is generating a lot of interest in the interaction design community. 

I got a chance to talk with Stephen for a bit before and during the presentation.  He is one of the most interested (not a typo) people that I have ever met.  Anyone who can provoke me to ramble on about my workout regimen and collegiate experience must be a profoundly curious soul.  That kind of curiosity and a deck of cards will do well against any interaction design problem.

The one question left unanswered for me was whether the cards (representative of behaviors) are best utilized with specific user behaviors or whether the cards can delineate a direction for an entire application as he suggested may be possible.  I suppose I may need to attend a workshop to find out.

Sunday, October 03, 2010

How clean is your form?

A secondary use for $.serialize() is altering a form's behavior if the user has updated the form since the document was loaded.  When the document is ready, the initial state of the form can be captured in a single variable that is easily compared.
$(document).ready(function() {
    var clean = $("#myform").serialize();
});
Now whenever a change event is fired on an element within the form, you can re-serialize the form and compare it to the original "clean" value to figure out if the form has been changed and update behavior if necessary.
$("#myform").delegate("input select textarea", "change", function(){
    var dirty = clean !== $("#myform").serialize();
    if (dirty) {
        enableSave();
        warnOnUnload();
    }
});
Kinda neat and a little more robust than other solutions.

Sunday, June 20, 2010

How clean is your bathroom?

From Coach Glassman:
When I go into the gym and I see a dirty bathroom, what I see is that you don't give a fuck. And that's fatal. There is no amount of poverty or lack of clients that excuses a dirty bathroom... it's a symbol for something more important than the bathroom, and that is for how much you care. I can fix bad training. I can't fix that you don't care. I can't give you pride where you don't have it.
There are many things that I love about Crossfit. This talk is one of them.

Wednesday, December 30, 2009

Purple Question

I just finished Purple Cow. In the book, Seth Godin asks one very intelligent question a number of different ways.
What are you doing to create a remarkable experience for the person who will consume your product?
The foundation Godin uses to answer this question is a mixture of anecdotal evidence and rational thought. The choice of case studies and source material makes the answers compelling narratively but prone to criticism from a scientific standpoint, similar to the work of Malcolm Gladwell. I do feel, however, that the question is an interesting litmus test for the work that I do as an application developer. It works in interviews, in code reviews, in strategy meetings, everywhere. It's rare that a single question can cut to the chase like that and cross domains with ease. Pretty awesome.

Tuesday, December 22, 2009

Coders in Transit

Yesterday I was in transit for twelve hours door to door. While I wasn't sleeping or on conference calls regarding secure video for the web, I read three chapters of Coders at Work.

There is a fascinating and nuanced history to the development of software engineering and it's a shame that so little of the field is dedicated to capturing it in a permanent form. It's fortunate that Peter Seibel had the foresight to interview the people directly involved in the making of that history and disseminate their thoughts to the rest of us.

Read it. It's awesome.

Current Projects

SALi is short for sensor abstraction layer. The intent of SALi is to ease the development of sensor based applications by abstracting away both technical and social sensor management issues.

About Me

Previous Posts

Archives

Powered by Blogger