Django like templates in Javascript

April 5th, 2009

Here's a quick ‘n’ dirty Javascript function I hacked together that provides Django-like template substitution.

function sformat(template, data)
    return template.replace(/{{(.*?)}}/g, function(m, n) {
        return eval('data.'+n);

Used something like this:

sformat("Hello, {{ name }}!", {name:"World"});

Which returns the following string:

Hello, World!

Alas, it doesn't support anything other than substitution. If you need anything more advanced (loops etc), you should investigate Javascript template engines.


There's always a way

April 3rd, 2009
Always a way

Where there is a Will, there is always a way.

Spotted in a deli in Oxford. It says ‘Where there is a Will, there is always a way’.

Thats right – always a way!

Just saying.


Fuzzy Thinking

April 1st, 2009

I have an idea germinating that involves using fuzzy logic, something I only had a passing knowledge of. After reading the Wikipedia articles and Googling for it I'm more informed but still haven't found a perfect resource.

The only Python code I have found was informative, but it was from way back in 1990. If there are any Pythonistas who know of a more up-to-date fuzzy logic module, or fuzzy logic resource in general, please let me know!

Search for Posts
© 2008 Will McGugan.

A technoblog blog, design by Will McGugan