08 Apr 2009
Building a RESTful webservice is pretty straight-forward with Django, but in many cases you want to have both
a human readable website and a machine readable api. A lot of websites solve this problem by using www.x.com
as the human site, an api.x.com as the machine site. They also will typically have different structures to
support the different usecases.n Unless your documentation is really excellent and the person writing the
client to your service actually reads it building a client for the service is an error prone process. In an
ideal world the developer would be able to browse the website and use the same urls in their client program.
Fortunately HTTP has two headers which make it possible to do just that, Content-Type
and Accept
.
The Content-Type
header describes the type of data that is included in the body of the HTTP request.
Typically this will be values such as text/html
, application/json
or application/x-www-form-urlencoded
.
A content type is sent by the client when POSTing or PUTing data, and whenever the webserver includes some
data in its response. The Accept
header is sent by a client to specify what content types it can accept in
the response. This header has a more complicated format that Content-Type
because it can used to specify a
number of different content types and to give a weighting to each.
When combined these two headers can be used to allow a normal user to browse the site and to allow a robot to
make api calls on the same site, using the same urls. This makes it easier both for the creator of the
programmer accessing your site and for you because you can easily share code between the site and your api.
Read More...
02 Apr 2009
ID Software have taken time out from letting you play Quake 3 in your browser to
release a port of the granddaddy of all first person shooters - Wolfenstein
3d. The iPhone is really beginning to show itself as an
excellent gaming platform, and despite its age Wolfenstein really looks at home on the phone.
The graphics are, quite frankly, rubbish. However, they’re exactly as they were when the game was released in
1992 which is exactly the point. The sound has faired much better and sounds great. The voices of the German
soldiers still send shivers up your spine. It’s an extremely faithful port of the game, and the addition of an
automatic save feature means it really works as a pick up and play game. It’s very easy to dip in and out of
taking one level at a time.
The controls have naturally been revamped for the iPhone’s unique control system. You steer by moving your
left finger over up/down/left/right arrows and fire by tapping your right finger on a button. This works
really well and it is very easy to pick up and to start running around the Nazi prison that you find yourself
in. The controls do rather feel like driving a fork lift truck. You regularly find your self reversing
backwards around a corner, which is not how a person would move, but it’s easy to forgive and hard to see how
else it could be done.
Read More...
24 Mar 2009
Toby Segaran’s book is given the subtitle “Building Smart Web 2.0 Applications”. It’s clearly been assigned to
the book by a marketing drone who felt that they needed to get the phrase “Web 2.0” in there somewhere.
Unfortunately this left me feeling a bit disappointed when read this book because it’s not really what the
book is about. A far better subtitle would have been “An Introduction to Machine Learning”, but I don’t work
in marketing.
My expectation based on the title was that the book would focus mainly on how to generate recommendations
based on a user interactions with a set of objects. I was expecting it to cover not only the mathematical
basis for such algorithms but also the practical implications that sites like Last.fm
and Amazon have to deal with processing such enormous data sets. While the book
does cover recommendation systems they’ve given only a small slice of what is already quite a short book.
There is no mention of how to process huge datasets either through map/reduce or some other scalable
architecture.
The rest of the book is take up with classifying objects in a set, predicting the prices of a new objects
given similar objects or filtering items such as email into spam and ham. These are staples of machine
learning textbooks, but here are introduced in a very accessible and easy to read way. These chapters are
interesting and informative but perhaps not that useful if you’re building a web 2.0 site.
Read More...
18 Mar 2009
Yesterday, as was splashed all over the web, Apple announced the iPhone OS
3.0. The key features in my view that were announced are
cut and paste, push services and the possibility of turn by turn navigation.
I was a bit skeptical over being able to copy and paste. I imagined that it would only be useful if your were
using the iPhone for business, which I don’t. Apple’s implementation seems to be highly impressive though, and
I’m suitably impressed. Rather than just being limited to copying text between the inbuilt application it
appears that you will be able to copy HTML, images and more between both the inbuilt applications and more. If
you want to send more than one photo in an email just copy it from the photo app and paste it straight into an
email. Sweet.
Recently my iPhone has been suffering from a strange problem where the battery goes from full to empty in just
a few hours and feels warm to the touch. I suspect that the problem maybe due to the mail
app so it is excellent news that
the much delayed push services will be coming this summer. Rather than applications needing to poll for
information developers can ‘push’ updates out to your phone automatically. This has the dual benefit of saving
battery power and giving some applications a fake running in the background mode. The facebook app could keep
you logged into facebook chat all the time and alert you whenever someone sends you a message. The same is
true for email and other chat applications.
Read More...
11 Mar 2009
CouchDB views are a bit like stored procedures in a traditional database system.
As with stored procedures it’s difficult to keep them in sync with your code, and to keep them in your version
control system. In this article I’ll show you how you can use a django management
command to update your views from files in your code base.
CouchDB uses a map/reduce system where each view is made of a filter program (the map) and an optional post
processor that runs over the output of the map (the reduce). These pairs are grouped into design documents
which are stored as a single unit in the couchdb database.
This command assumes that you store your map and reduce functions in the directory structure set out below.
project/
app/
couchviews/
database1/
design1/
mapreduce1/
map.js reduce.js
mapreduce2/
map.js
design2/
mapreduce3/
map.js reduce.js
database3/
design3/
mapreduce4/
map.js reduce.js
Read More...