Slippery Snippets
Sunday, December 12, 2010
  Relaxing with CouchDB

I’ve been looking for an excuse to use CouchDB for a while. I forget where or when I first heard of it but I've been hooked on its feature set for some time now. Unfortunately I’ve not been able to think of a good app to write or I’ve been unable to fit my app into the CouchDB way of thinking.

Last month, however, I got pulled onto a piece of work where some sort of easy to use, replicating, eventually consistent application would have been really useful. So I decided that this would be the perfect opportunity to start a Couch app. But then I got stuck. I downloaded CouchApp, watched a couple of Evently screencasts and sat there repeating “CouchDB is relaxed. CouchDB is relaxed”. Couch sat there chilling out and I just got more stressed. So I’ve decided to start simple and build up a good base of fundamentals before trying the harder stuff.

So here is (I hope) a few posts about my first steps with Couch and how I got to the point where I started to relax a little.


Baby steps first. I’ve just rebuilt my work laptop. I’m now running Windows 7 with an Ubuntu VM. I want to make sure I use the VM more, so I decided to run Couch from there and connect to it over a host only network. Setting up the VMs network interfaces is left as an exercise to the reader but let’s do a simple walkthrough of the installation under Ubuntu. The latest version of Couch is 1.0.1. Let’s see what’s in the repos first:

me@ubuntu:~$ apt-cache search couchdb
couchdb-bin - RESTful document oriented database, programs
desktopcouch - A Desktop CouchDB instance
evolution-couchdb - Evolution support for CouchDB databases
libcouchdb-glib-1.0-2 - GLib-based API for CouchDB
libcouchdb-glib-dev - Development files for GLib-based API for CouchDB
libcouchdb-glib-doc - GLib-based API for CouchDB
libdesktopcouch-glib-1.0-2 - Glib-based API for Desktopcouch
libdesktopcouch-glib-dev - Development files for Glib-based API for Desktopcouch
python-couchdb - library for working with Apache CouchDB
python-desktopcouch-records - Transitional package, desktop CouchDB Records API
couchdb - RESTful document oriented database, system DB
desktopcouch-tools - Desktop CouchDB tools
gir1.0-couchdb-glib-1.0 - GLib-based API for CouchDB
gir1.0-desktopcouch-glib-1.0 - Glib-based API for Desktopcouch
libmoneta-ruby - Ruby interface to multiple key/value stores
libmoneta-ruby1.8 - Ruby interface to multiple key/value stores
python-desktopcouch - Transitional package, Python Desktop CouchDB
python-restkit - HTTP resource kit for Python
quickly-ubuntu-template - quickly ubuntu application template
xul-ext-bindwood - Firefox bookmark syncing with desktop couchdb

Two likely candidates. The second looks like the best option as I want to make sure that this runs on startup and can be accessed from Windows with minimal effort.

me@ubuntu:~$ apt-cache show couchdb
Package: couchdb
Priority: optional
Section: universe/misc
Installed-Size: 84
Maintainer: Ubuntu Developers <>
Original-Maintainer: Erlang Packaging Team <>
Architecture: all
Version: 1.0.1-0ubuntu3
Depends: couchdb-bin (>= 1.0.1-0ubuntu3)
Filename: pool/universe/c/couchdb/couchdb_1.0.1-0ubuntu3_all.deb
Size: 12814
MD5sum: 12c56b05e323e9ef623379d139811c7e
SHA1: 0c894c4d37bd2126a00be797a20ea60c1d44d051
SHA256: 0572cad50d63d2576a404bba8b78636a604eb6899af3ab2738e65a6ff6e7a103
Description: RESTful document oriented database, system DB
Apache CouchDB is a distributed, fault-tolerant and schema-free
document-oriented database accessible via a RESTful HTTP/JSON API. Among other
features, it provides robust, incremental replication with bi-directional
conflict detection and resolution, and is queryable and indexable using a
table-oriented view engine with JavaScript acting as the default view
definition language.
CouchDB is written in Erlang, but can be easily accessed from any environment
that provides means to make HTTP requests. There are a multitude of third-party
client libraries that make this even easier for a variety of programming
languages and environments.
Origin: Ubuntu


1.0.1 in the repos? Perfect.

me@ubuntu:~$ sudo aptitude install couchdb
[sudo] password for me:
Sorry, try again.
[sudo] password for me:
Sorry, try again.
[sudo] password for me:
No packages will be installed, upgraded, or removed.
0 packages upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 0B of archives. After unpacking 0B will be used.


That’s a pretty useless bit of output, as I’ve already got it installed (plus you can see how bad I am at typing my password in) but you get the idea.

Now that Couch is installed we need to tweak the config to run on external interfaces. You’ll need to edit the /etc/couchdb/default.ini file and search for “bind_address”. I’ve changed mine to “” which will listen on all interfaces. Don’t do this unless you want everyone on your network to be able to access your Couch instance. Change it to the IP address of your host only adapter if you’re running on a VM.

Now let’s test whether things are running okay:

[118]:> (New-Object System.Net.WebClient).DownloadString("")


Who needs Curl, eh? A quick browse to will confirm that Futon is up and running. It’s good practice to create a new user so that we don’t operate in admin party mode but I’m not going to.

That’ll do for the first post. Next I’ll give an overview of the application I’m going to be working on and start working with CouchApp.


Tuesday, June 23, 2009
  Dead? I ain't dead. I'm just resting.

Just thought I'd let anyone who's still tracking this blog that there are some updates to the plugin in the svn repository on Google Code:

I'm hoping to package these up into a release at some point in the (very) near future.

Also, I'll be at EuroPython next week, so feel free to file bug reports in person if you're there as well. 
Monday, February 25, 2008
  1.2.2 Spare time plus a working version of bzr-svn has meant that I've had a bit of time for bug fixing. 1.2.2 is therefore now on

One big change: the plugin is now separate from the bundles. At the moment they both live on the same page, as I don't think it's worth setting up a new page.

Get downloading!

P.S. Many thanks to everyone who's voted for the plugin. It's now sitting at number 24 out of 2149. Quite an achievement given what the first version looked like... 
Sunday, September 30, 2007
  The Usual Suspect The usual problem has cropped up - line endings. A new version will be posted shortly. There also seems to be a problem with the version of Vimball which ships with the Windows version of Vim. Those viewing the file will have some nice folds to aid navigation around the file; unfortunately, under *nix the fold markers get added to the file name. Not very useful.

An interesting point made in the comments:
Your latest vimball has DOS line endings, and svn is still at the last version :(
The reason SVN is the last version is that bzr-svn was not able to push the latest changes up to Google Code. Now I'd like to point out that this is most likely my fault; I noticed that the author of bzr-svn linked to one of my posts about how the plugin didn't work under Windows. Just to clarify - this was due to my lack of effort more than anything else.

I've also enjoyed using bzr and so I'm considering moving to a bzr hosting environment. I'm going to investigate Launchpad but I'd welcome any other suggestions. 
  1.2 just for you Well Blogjet turned out to be a waste of time - its Blogger support is broken, so I can only post new stuff. Given my posting habits that seems like a waste of money, so no upgrading for me.

Anyway - down to business. I've finally managed to release a new version of the plugin, so grab it form

There's a few new features - commands have autocomplete to help you browse the bundles. There are two new commands to help create new snippets and there's a load of bug fixes and bundle updates, so get downloading! 
Monday, September 10, 2007
  Testing BlogJet

I have installed an interesting application - BlogJet. It's a cool Windows client for my blog tool (as well as for other tools). Get your copy here:

"Computers are incredibly fast, accurate and stupid; humans are incredibly slow, inaccurate and brilliant; together they are powerful beyond imagination." -- Albert Einstein

It also presents you with this as the default test post, so I’ll help the Google rankings and let it get posted. Hopefully this should allow me to post a little more. I’ve tried typing up some posts in Vim, but I think that this will be a better solution. Let’s see, eh?

Thursday, July 26, 2007
  Wherefore art thou not working under Windows Hello all.

Still stuck in the Midlands, so posting and development have pretty much ground to a halt. I did manage to do a bit of hacking the other day, but I can't get bzr-svn working under Windows, so you'll have to wait until I'm next in Linux for the next push to trunk.

Anyway, since my last post I've been playing around with wxPython and Django; in particular trying to use one to display the models from the other. During this I ran into another Django bug (second one to stop me in my tracks) and some random behaviour which I didn't quite agree with.

In a huff I decided to try out Pylons - mainly because because it plays well with SqlAlchemy.

It's hard work getting going with Pylons - documentation is nowhere near as complete as Django's but if you're prepared to hunt through the source most things become apparent. The IRC channel is very friendly as well, though you sometimes have to wait for America to wake up.

Here's my handy Pylons tip for the day:

def screenshot(self, id):
i = model.Screenshot.get(id)
if i:
im =
pylons.response.headers['Content-Type'] = "image/%s" % (im.format and im.format.lower() or 'bmp')
pylons.response.headers['Content-length'] = "%s" % len(i.image)
if request.params.has_key('thumb') and request.params['thumb'] == "True":
im.thumbnail(THUMB_SIZE, Image.ANTIALIAS)
w = StringIO(), im.format)
return str(w.getvalue())

The above action pulls an image out of the database and serves it up. If the GET has thumb=True set then you'll get a thumbnail instead.

I know that you're not supposed to serve images from the DB but, trust me, I have good reason for doing so.

It also looks as though there are some issues when returning large images; it's been suggested that FileApp.DataApp is the way forward. 
Saturday, May 19, 2007
  Another demo Spotted this one thanks to Google Alerts.


July 2006 / August 2006 / September 2006 / October 2006 / November 2006 / December 2006 / March 2007 / April 2007 / May 2007 / July 2007 / September 2007 / February 2008 / June 2009 / December 2010 /

Powered by Blogger

Subscribe to
Posts [Atom]