Tuesday, February 07, 2006

Trendy AllegroCache

CafeSpot's sister application trendalicious collects URLs posted to del.icio.us and ranks them according to the change in the number of people who have recently bookmarked the same URL. Originally trendalicious used a RAM-resident hashtable to track the URLs it had seen. This was fast, and much easier than using a SQL database, but fairly inaccurate because the volume of postings to del.icio.us meant that many URLs were missed between polls and then discarded as old because they hadn't been seen again.

Today trendalicious stores 24 hours of history (currently around 20,000 URLs and their associated popularity statistics) as persistent objects using Franz' AllegroCache. Accuracy is much improved because a URL's popularity can now be calculated as long as the URL is seen at least twice within 24 hours. Using AllegroCache is incredibly easy; any CLOS object can be made persistent by simply setting its metaclass to 'persistent-class' and specifying which slots are indexed. New and modified instances will be automatically stored when COMMIT is called. RETRIEVE-FROM-INDEX finds existing objects by indexed slot, and DELETE-INSTANCE removes an object from the db. Those three functions are the extent of trendalicious' use of AllegroCache but there is plenty more cool stuff including transactions, Prolog queries, and client/server mode.

Monday, August 01, 2005

Syntactic Abstraction

One of Lisp's primary attractions for me is the ability to build syntactic abstractions. Too many languages require you to write the same N lines of code every time you want to accomplish a common task, but with Lisp you can write a function or macro to abstract it. Consider the following code which implements the REST API's place/find-near-point function:

(def-api-function place/find-near-point
((key 'string "user access key")
(latitude 'float "latitude of center point")
(longitude 'float "longitude of center point")
(distance 'integer "distance in meters"))
"Find places within the radius of a circle centered on the
specified latitude and longitude."
(let ((places (if (and latitude longitude distance)
(find-places-near (list latitude longitude) distance)
(list (make-dummy-place)))))
(with-api-response (stream)
(dolist (place places)
(generate-place-details stream place)))))

Isn't that pretty? Concise and simple, yet it accomplishes quite a number of repetitive tasks including registering the function as an API request handler, decoding and validating input parameters, and generating either a help page or the appropriate XML response.

Wednesday, July 27, 2005

Deploying Updates

Deploying updates to CafeSpot is incredibly easy thanks to Common Lisp and the darcs version control system.

The process begins on my laptop in either the primary development repository, or a copy if the primary contains changes that are not ready for release. Darcs' decentralized design encourages temporary branching such as this and provides easy bidirectional merging between branches. After local testing the changes are recorded and sent to the server via the darcs push command which copies and applies patches over SSH.

Once patches have been pushed to the server all that is left is to load the changes into the running lisp process. This is done with asdf which manages dependencies; compiling and loading the updated files as necessary. I simply type (asdf:oos 'asdf:load-op :cafespot) at the CL-USER> prompt and voila, done! No down-time required, the current cafespot.net lisp process has been quietly humming along for over two months and many updates.

Sunday, July 24, 2005

The REST API Is Live

I'm happy to announce that CafeSpot's REST API is now available. The current API functions are available via HTTP GET requests and include:
The output of the API is a simple XML document such as:
I'd certainly appreciate a link to any applications that use the API. Have fun!

Friday, July 22, 2005

Better late than never!

Well, CafeSpot has been alive for about two months now and I still haven't gotten around to setting up a mailing list for comments and suggestions, but creating a Blogger weblog sure is easy!

CafeSpot is a social guide to independent cafes, coffee shops, restaurants and more. It was inspired by all of the excellent links I've discovered thanks to the del.icio.us community, and a desire to do the same for local places with great food and drink. There are of course many restaurant review sites, and local newspapers in every city, but I suspect that the community driven and social nature of CafeSpot will make it much easier to find great independent places, worldwide.

As a Web 2.0 application, CafeSpot has the full compliment of features such as tagging, geocoding, and Google Maps. It will soon have a REST API as well.

I hope you find it as useful as I do!