My Projects Blog

Chaining Asynchronous Methods in jQuery using the Queue

Saturday, August 7th, 2010

Someone recently asked me whether it would be possible to chain asynchronous events in JavaScript. After a little pondering, I figured out a way to do it with a simple queue. I thought this would be an awesome addition to chaining for a good few hours, until I remembered how jQuery did it, and that I’d recently used exactly that function. (more…)

Ten of the best HTML5 Spotify mashups

Sunday, July 25th, 2010

Number 1:  moretrackstrackslikethis.com

A useful mashup of lastfm’s “similar tracks” service and Spotify gives a great way to find new artists and music matching your tastes.  What’s particularly good is that you can match single tracks, so even if you only like one track by a certain artist, you can find good matches.

Written in 100% Pure CSS3, HTML5 and JavaScript.

Number 2: admission that this is just shameless link-bait

There’s some other great mashups out there. Check Spotify’s list.

JS Fireworks – in SVG

Sunday, May 23rd, 2010

I’ve taken another look at last year’s Chrome Experiment, JS Fireworks.

This time I’ve rewritten it to use SVG, whose arrival in IE9 promises to make HTML more interesting. In fact, I’m far more excited about animated SVG than CSS transforms and the fabled HTML5.

I used Keith Wood’s jQuery SVG library, which seems quite helpful, and simply replaced the ‘draw line’ commands with their equivalents.

Canvas is the bitmap to SVG’s vector, so while I have to clear the screen and redraw each time in canvas, I merely need to move the lines in SVG. Presumably the number of shapes on screen affects performance, so that was a big difference.

Here’s the result: JS-Fireworks in SVG. I’ve reduced the number of items in each explosion from 30 down to 10. You’ll see why.

It runs very quickly in Chrome (Mac), slowly in FireFox, and smoothly, though not excessively quickly, in IE9, which I’m quite excited about. Where’s IE9 Experiments?

I haven’t tried IE678. But then I haven’t tried Mosaic either.

Satchmo/Django: “ProgrammingError: can’t adapt type ‘__proxy__’”

Wednesday, May 5th, 2010

I got the above error when laoding a shipping module in Satchmo, but upon working out the cause, I reckoned it must be a pretty common error these days.

The exception is raised in /django/db/backends/util.py, line 19.
When I checked the local vars of the query.py step, line 2369, I got the following SQL:

'UPDATE "shop_order" SET "site_id" = %s, "contact_id" = %s, "ship_addressee" = %s, "ship_street1" = %s, "ship_street2" = %s, "ship_city" = %s, "ship_state" = %s, "ship_postal_code" = %s, "ship_country" = %s, "bill_addressee" = %s, "bill_street1" = %s, "bill_street2" = %s, "bill_city" = %s, "bill_state" = %s, "bill_postal_code" = %s, "bill_country" = %s, "notes" = NULL, "sub_total" = %s, "total" = %s, "discount_code" = %s, "discount" = %s, "method" = %s, "shipping_description" = %s, "shipping_method" = %s, "shipping_model" = %s, "shipping_cost" = %s, "shipping_discount" = %s, "tax" = %s, "time_stamp" = %s, "status" = %s WHERE "shop_order"."id" = %s

with the following params:

(1, 761, u'abc abc', u'abc', u'abcabc', u'abc', u'(UK32)', u'E17 8QG', u'GB', u'abc abc', u'abc', u'abcabc', u'abc', u'(UK32)', u'E17 8QG', u'GB', u'13.2500000000', u'15.0000000000', '', u'0E-10', u'Online', 'Dots Postage and Packing', <django.utils.functional.__proxy__ object at 0x24142d0>, 'dotship', u'1.7500000000', u'0E-10', u'0E-10', u'2010-05-05 14:13:07.134682', u'', 713)

You can see the __proxy__ that shouldn’t be there.

Looking back at my code that provides that particular value, I found I’d used the _() shortcut, which in this file, is bound to ugettext_lazy. Of course, this is the problem! The lazy evaluation isn’t being executed before the query is evaluated.

To fix, either use gettext directly, or change the shortcut for _ from gettext_lazy to gettext.

Replacing the Satchmo homepage by overriding URLs

Tuesday, May 4th, 2010

You can override URLs used by Satchmo by using the built-in urlhelper.

So my project urls.py looks a bit like this:

from django.conf.urls.defaults import *

from satchmo_store.urls import urlpatterns

from django.conf import settings
from satchmo_utils import urlhelper

urlpatterns += patterns('',
    #add my normal urls here
    (r'^blog/index/$', 'myblog.views.blogindex'),
    (r'^photos/', include('photoapp.urls')),
)

urlhelper.replace_urlpatterns(
    urlpatterns,
    [
        #add override urls here (match the name from satchmo's url files)
        url(r'^$', 'myblog.views.homepage', {}, name='satchmo_shop_home'),
    ]
)