Tuesday, November 28, 2006

A little more dabbling ...

Had a few moments spare, so I've been playing around with a few ideas.

I decided to add Technorati entries and tags into my "mood" page. This was simplicity itself.

There is no error handling at the moment - so if it bombs, it bombs. It's a bit slow because I'm pulling data from other services, combining on the server and then serving.

All that was needed was a few bits of JavaScript like :-

function processTechnoTags( tagList ) {
var subset = {};
subset.blogs = new Array();
subset.count = tagList.document.result.postsmatched;

for ( let aBlogId in tagList.document.item )
subset.blogs.push({
title:tagList.document.item[aBlogId].title,
link:tagList.document.item[aBlogId].permalink});
return subset;
}


and suddenly, hey presto I've got entries from Technorati as well as Flickr combined together. Again this is from someone who doesn't know JavaScript in detail!

Ok, it's all server side at the moment, no AJAX stuff yet but I like this language ... lots, it couldn't be simpler.

This isn't even going into the persistance side of things, which for an old DBA like myself is child's play.

2 comments:

Mark Fowler said...

Maybe you should consider using caching. This is the entire implentation of a cache that expires things automatically:

Cache.getCached = function(name, callback, duration) {
var cache = Cache.search({'name': name});
if (cache.length != 0)
return cache[0].content;

if (duration == null)
duration = "+1h";

var content = callback();
var c = Cache.create();
c.name = name;
c.content = content;
c.expires = duration;
c.save();
return c.content;
};


Use is simple:

cached = Cached.getCached("name", function () { .... });


Where the function returns the new value if the thing named "name" has expired already.

swardley said...

Thanks for this - much appreciated. The site now has caching.

Actually, I could use this to give a visual representation of how things were.

Cool, 24 hour snapshots of mood change.