September 3, 2010

Setting up Satchmo on a Debian Server

At the request of people on the satchmo-users mailing list, here’s my step-by-step guide to installing Satchmo on a Debian server.

Debian is a wonderful base for Satchmo, much easier to set up and maintain than RedHat in my opinion. The magic is in the “apt” packaging system, it simply eliminates most of the ugly tracking-down of the right versions of software and their dependencies.

This is a step-by-step, not a full discussion. To read more about “why”, please see the excellent article Creating my Dream Server for Django, which I heavily borrowed from.

[Read more...]

Why you should use Caching in your webapp.

Cache Manager Screenshot

Look at that hit rate! That isn’t unusual, a 75% hit rate for cached elements in a well designed system. That cache page is copied from an e-commerce site undergoing testing for a couple hours, by the way. Most of the caching is from presentation stuff, such as menuing and page widgets.

I think that the incredible hit rate goes to prove that for most any real application, you should be thinking about caching sooner rather than later. Build it in. It is not “premature optimization” to design it up front.

The background of that screenshot

For my Django apps, I use a cache manager application I wrote in a brainstorm fugue state a couple months ago. I really needed it for my still-in-testing InvisibleCastle gaming site rewrite, since I do so many lookups and repetitive viewing of the same information.

Once I’d written and debugged it — which took longer than I’d have liked, of course — I started using it as a matter of course in all my client projects. Then last week I had another brainstorm and actually wrote a quick set of management pages for it. Now I can observe the cache in operation, clear it, or even a subsection of it. It has been invaluable, and I can see the vast increases in speed it affords my apps by simply comparing the performance with and without the cache running. I haven’t run formal trials, but it feels at least twice as fast, probably more.

[tags]django,caching[/tags]

Django and Lighttpd init script and config for SSL.

I’ve gotten a lot of interest from my article about my SSL configuration for Django/Lighttpd. To make things even simpler for you, I’m posting a zip file with my raw config files and init script.

The init script is intended for use on a Redhat-style system, since that is what most VPS solutions are going to give you. It actually works, and I’ve never seen any other examples of working Django init scripts. Drop it in, edit the config files, run “chkconfig –add yourapp” and you should have a django setup which autostarts, and a Lighty config which is ready to serve it.

Enjoy, and please let me know if you see a way to improve the scripts.

tribe.zip version 1

Adding AIR mimetype to Lighttpd

If you tell Lighttpd about the mimetype for your AIR apps, then your users will be properly prompted when they click on the files to download/install. If not, then their browsers will complain about unknown file types. Happily, like so much else with Lighttpd, adding the mimetype is extremely simple.

In your lighttpd.conf file, under “mimetype.assign”, set up the new mime type. Like so:


mimetype.assign = (
".air" => "application/vnd.adobe.air-application-installer-package+zip",
[...]
)

How to do HTTP Basic Auth in Ajax

You can use HTTP Basic Authentication with Javascript/Ajax in just three steps. I’ll give you them in just a moment.

The Background

This morning, I was experimenting with Adobe AIR, writing a client to tell me whether I have games waiting for me to make a move on Weewar, and I needed to be able to use my username and “token” via Basic Auth to do that.

It was not easy to find how to do it. In fact, I had to connect a few dots to get it to work. Here you go:

Step 1

First, get Base64.js from Webtoolkit, and load it on your page. We need the encode routine from that library.

Step 2

Construct your Authorization header like so:


function make_base_auth(user, password) {
  var tok = user + ':' + pass;
  var hash = Base64.encode(tok);
  return "Basic " + hash;
}

Step 3

Use it in your Ajax call.


var auth = make_basic_auth('me','mypassword');
var url = 'http://example.com';

// RAW
xml = new XMLHttpRequest();
xml.setRequestHeader('Authorization', auth);
xml.open('GET',url)

// ExtJS
Ext.Ajax.request({
    url : url,
    method : 'GET',
    headers : { Authorization : auth }
});

// jQuery
$.ajax({
    url : url,
    method : 'GET',
    beforeSend : function(req) {
        req.setRequestHeader('Authorization', auth);
    }
});

[tags]ajax,javascript,extjs,xmlhttprequest,jquery[/tags]

Weewar – a fun online game

This morning, I started playing a great new online game, Weewar. which reminds me of old-school “empire” from my Amiga 800 days.

It is a turn based game with a bunch of interesting AJAX-y features, the best of which is live updates of the other players moves. I’m still in my first game, but I’m really enjoying myself so far.

If you’d like an invite, drop me a note from my contact page.

Django and Lighttpd configuration for smooth SSL

I use and prefer Lighttpd for serving my Django applications. Tonight I worked out a nearly perfect configuration which allows me to serve the app through fastcgi in both http, and SSL-enabled https. The media files are directly served by Lighty, without hitting the django backend at all, for maximum speed.

Better yet, this configuration allows me to directly serve the media files through ssl without having to get a separate certificate for the web server. Lastly, it serves both “www” and “non-www” versions of the domain, automatically redirecting “www” traffic.

[Read more...]

Why I'm moving from jQuery to ExtJs

Update (21 Nov 2008): I changed my mind a few months later.

This week, I’ve switched favorite Javascript frameworks. I was a heavy jQuery user, and still think that the framework is very nice. As part of a discussion on the Satchmo-Developers list about what Javascript framework to use as the default for the Satchmo web shop framework, I ended up doing a survey of the best ones available.

This is highly debatable, of course. In the end, I simply ended up trying to optimize my based on these desires.

  • It should be nice to the global namespace. I dislike frameworks that pollute the air with all kinds of function names.
  • It should be fast.
  • It should have nice, easy to use effects.
  • It should have extremely capable DOM manipulation.
  • It should have great CSS selectors.
  • It should have a good window.onLoad mechanism.
  • It should not modify the base language. Prototype is right out! I really really hate that.
  • It should be terse. I do not like wordy frameworks as a matter of style & taste.
  • It should work well with Safari.
  • Based on these requirements, I narrowed my choices down to:

    I then made a web page, loaded each of these in, and tried out various DOM manipulations and effects using the FireBug console. This was a fair way to do it, because it is how I prefer to explore a new framework. I like good docs, of course, but I also like being able to exercise the framework in an intuitive manner.

    My results, in very short nutshell descriptions:

    jQuery

    Intuitive, easy to use, fast, great DOM manipulation, good effects. Great window.onLoad handler. Give it an A- grade.

    ExtJs

    Intuitive, very very extensive, great DOM manipulation, solid effects. The fastest to get things done when puzzling out on the commandline. Give it an A.

    Mochikit

    Very terse, much more “functional” in approach rather than class-oriented. Not good about polluting the global namespace. Yes, this is runtime-optional, but the alternative is very wordy. The functional approach (i.e. map(set, func) rather than $(selector).each(func)) is a bit off-putting actually. It makes it much harder to know what functions are appropriate to use with what objects. Give it a score of B+ due to my highly subjective sense of style.

    Dojo

    Too wordy. I dislike their framework for building widgets. I love their inclusion mechanism, but dislike that the reason for it is that Dojo is so huge. Give it a C.

    The winner: ExtJs

    In the end, I went with ExtJs. I am happily converting my existing code to use the framework, and encountering little resistance. It is a very easy conversion. I’ll still use jQuery for deployed clients, but all my new library code is going to be Ext based.

    [tags]javascript,jquery,extjs,mochikit,dojotoolkit,dojo[/tags]

    Spamato after two weeks – incredible

    Spamato
    After two weeks, I’m pleased to report that Spamato has been the best, most accurate spam killing solution I’ve ever tried.

    In fact, the crazy truth is that I sometimes find myself wondering whether something is wrong with my mail. “I’m not getting any mail, that’s odd.” I’m just not used to sometimes checking my mail and not having anything new in the box. That’s how good the system is.

    I particularly like the IMAP integration. I’ve got “spam” folders set up on each account, and if I get something miscategorized as spam, I just drag the item from spam back into my inbox. It brings it right out, and updates the system with my decision. That increases accuracy.

    This one is a keeper. I couldn’t be happier, and it is free.

    [tags]spam,spamato,email[/tags]