Archive for February, 2007|Monthly archive page

Sillicon Valley Rails Meetup

Please find attached the notes from my presentation to the Sillicon Valley Rails Meetup, from Feb. 15.



RJS + Dynamic Script Tags = AJAX Heaven

One problem that often comes up with Ajax services is that you can’t call them on a domain different from the one that served your page. This is true even across subdomains of the same parent domain. Sucks!

Yahoo has some very clever services that return JSON-formatted data, so you can call them with a Dynamic Script Tag (script tag where src attribute is set dynamically), and easily access the results in Javascript. This is a great way to get around the cross-domain security controls of the XMLHttpRequest object.

This approach is nice for true services that return data, but in my case I wanted to return actual HTML, because the page edits I needed to make were pretty involved.

Fortunately, Rails JavaScript templates come to the rescue. RJS is a clever mechanism that generates Javascript code server side to be passed to the client and applied to the page. Well one of the functions included takes an arbitrary chunk of html and returns it as Javascript to generate that html. Perfect!

The net result is that it’s incredibly easy to convert my old Ajax call into a Dynamic Script Tag call.

Here’s the old client side code:

new Ajax.Updater(‘mydiv’, ‘/site/search?site=<%= site %>&q=<%= @q%>’, {asynchronous:true, evalScripts:true});

And here’s the new client code:

<script id=”rjs_target”></script>
$(‘rjs_target’).src =  ‘/site/search?site=<%= site %>&q=<%= @q%>&output=json’;

And then the magic on the server side:

if params[:output] == ‘json’
render(:update) {|page| page.replace_html @site, :partial => ‘webresults’ }
render :partial => ‘webresults’

The magic is in the page.replace_html call, which wraps the html generated by my partial into Javascript code.

The beauty is that this code uses my old partial exactly as-is. But this call can be served by any server I want. Whoo hoo!

Obama chooses Brightcove…smart decision?

So looks like Barack Obama is using brightcove to host the video at his site. Unfortunately, seems like the audio is complete out of sync with the video. Whoops! Not sure whose fault that is, but it’s not making brightcove look to good.

Someone’s got a perfectly good capture from CNN that you can see at the Election ’08 pod over at vodpod. Video is hosted by YouTube, naturally.

Yahoo Spelling Service API – Ajax version

Man, the web is great. I needed to add spelling suggestion to our search this morning. I spent about 10 seconds thinking about how to implement it myself, then thought, hmm…I bet someone has a web service for this.

Yup, Yahoo’s service is super-simple. One REST call with the query string, and it returns a single value with the spelling suggestion. At first I implemented it in my server code, so my server was calling Yahoo to get the suggestion.

But that’s crappy, because then my web server sits busy waiting for Yahoo to answer. So I converted my code to do everything as an Ajax call from the page. Is nice! Same result, but the client calls Yahoo directly and I get no load at all.

The code is easy, making use of the “Dynamic Script Tag” approach to allow the cross-domain call. Using Yahoo’s JSON result option makes handling the result incredibly easy.

<div id=”spelling” style=”font-size:1.2em;font-weight:bold”></div>

<script id=”spelling_json_container”></script>
window.onload = function()
var q = “bad splling”;
             V1/spellingSuggestion?appid=YahooDemo&query=’ + q +

function handleYahooSpellingResults(json_result)
  if (json_result.ResultSet && json_result.ResultSet.Result) {
  result = json_result.ResultSet.Result;
  $(‘spelling’).innerHTML =
      ‘Did you mean <a href=”/site/search?q=’ +
      escape(result) + ‘”>’ + result + ‘</a>?<br /><br />’;

I love the web!.

I’ve got to buy some Google stock

I don’t know if this makes me laugh, cry, or both:


Microsoft buying ad space on Yahoo’s IM client, to push their own IM client! Am I missing something here?

Technological Generation Gaps

Recently reading this article got me to thinking about generation gaps around technology usage. Here are some interesting “factoids” (ok, lets say generalizations) about technology usage:

  • For people my age (37!), email is the “default” communication mechanism, besides the phone. We use IM, but generally for specific real-time situations. Most people I know do very little SMS texting.
  •  People in their 20’s seem to use IM as their default communication, plus the phone. They also send SMS quite a bit.
  • Teenagers apparently do not use email. For them, IM is their default communication system, then SMS texting, then the phone. Teenagers (and some 20 somethings) also use social networking messages (site mail) to send messages to their friends. I don’t know anyone over say, 25, who does this.

I think that last one is the most intersting. Teenagers consider email as a system only used to communicate with authority figures – parents, teachers, etc… What I think is funny is that that is how I consider snail mail! I never send anyone a personal letter, letters are for business purposes only.

It seems like the pace of technology innovation is compressing the time between generation gaps, so that there’s a whole different set of behaviors between the pre-Myspace and post-Myspace “generations”, even though those people are only like 5 years apart in age.

This rapid churn in user behaviors has lots of implications when it comes to trying to build a web startup. Consider the success of YouTube versus all the major media companies who tried (and are trying!) to build audience around video online. You think it’s an accident that YouTube’s investors left Chad Hurley (29 at the time)  as CEO of the company? I doubt it. They probably wished he was younger! I have been in VC meetings where the partners complained that our 30’s age leader was too old for what we were trying to do!

So what’s an entrepeneur in their 30’s to do? All I can suggest is, listen to your users. This is old, old advice, but the pace of change in web user behavior pretty much demands it nowadays.