Saturday, 20 December 2008

Implementing Copy using REST

I have a requirement to implement "copy" functionality for a resource.

Given a resource at /asset-set/1234 I need to create copy at /asset-set/4567.

The obvious way to do it is to GET the resource at /asset-set/1234 and PUT it to /asset-set/4567. The issue I have with this is that the size of the resource may be significant and to GET the resource to PUT it back to the same server seems a bit wasteful.

There is a WebDAV verb COPY that I could potentially use, but would rather keep within the confines of the 4 standard HTTP Methods.

Representations of a resource in REST do not need to completely describe a resource. e.g. in Atom we may have a binary representation of an asset and also an atom+xml representation.

If I use alternate representations for the PUT method I could PUT an application/resource-ref representation which contains a URI to the representation we wish to copy. The server would then GET that resource (which would be local) and create the new resource using that information.

I would be interested on anyone's opinions on this (Is it RESTful?) and also if there is an alternate way of doing this?

Monday, 27 October 2008

Main colours in an image

I need to find out the main colours used in an image for a project.

I have a list of colours that I want to tag the image with - around 30. Ideally I want this to happen automatically, so I need to get information on the colours used in the image.

I already use Image Magick in this project, so may well use this. I think the process will be something like.

1 - Get a histogram of colours in the image.
2 - Specify a range of colours for each of the colours in our list, it is possible these will overlap somewhat.
3 - Calculate the percentage of the image within the range for each colour in the list.
4 - If the colours exceed a given percentage then tag the image with that colour.

Not sure how this will handle highlights and if this is likely to be important. Think if it is we may need to look at some measure of the distance of colours in the image, so we can for example tag an image as red (and grey) if it has thin red stripes on a grey background.

Wednesday, 24 September 2008

YUI Grids CSS

Looking at CSS frameworks recently and the YUI Grids CSS in particular.

This seems to have come under some criticism for requiring non semantic markup, with class names such as yui-b.

Should be quite simple to write something to replace these classes with more semantic ones for a particular site. Sounds like a simple search and replace to me.

Does not deal with the need for lots of div's though, but I guess that is the price you pay for the flexibility offered by the framework.

Perhaps an alternative is a "framework" which does not try to produce a css file to handle all cases, but a framework generator which can produce you css based on a specification for the page..

Friday, 12 September 2008

Dynamic loading of javascript

I have been working on dynamic script loading with jquery and have this working

$.requireScripts(
new Array(
"/script/ui.core.min.js",
"/script/ui.draggable.min.js",
"/script/ui.resizable.min.js",
"/script/ui.dialog.min.js"), function(){
showADialog();
});

This will load the javascript specified in the first parameter before executing the function supplied as a second paramater.