Using the Goodreads API

Posted 24 April, 2011 by David Porter
Categories: Uncategorized

A few days ago I decided to switch from LibraryThing to Goodreads to track my reading. I’d been a LibraryThing user for several years but had always found the site clunky and hard to use. Recently I came across Goodreads, and after exploring it a bit I decided to make the switch.

Of course this meant I’d need to copy my library from LibraryThing to Goodreads. I followed the instructions for doing this and exported my LibraryThing data as a TSV file, which I then fed to Goodreads. No errors were reported, and a quick check showed all my books were there in my new library.

But then I noticed that most of the books were missing data, such as the dates I’d read them and the ratings I gave. No problem, I figured, there’s bound to be an API for manipulating the library. And indeed there is. I set about writing some code so add the missing data.

It turned out to be a straight-forward exercise. I simply grabbed a Goodreads API key, configured OAuth authentication for my Goodreads account, and then wrote a few methods to read data from my LibraryThing export and feed it to Goodreads. Pretty soon I had my library looking just the way I wanted it.

I’ve placed the code on Github in case it’s useful to someone else.


Learning Something About the URL

Posted 10 May, 2010 by David Porter
Categories: Uncategorized

Alan Skorkin has written a nice article on the essentials of the URL. He argues that since all programmers are likely to encounter web programming at some point, the URL is one of the fundamentals of programming that developers should master. I agree with this.

There are a couple of things I found interesting in the article. First, Alan describes the path component of a URL as “basically [something that] tells us where on the server machine a resource lives”. While this is often true, particularly historically, it’s clear that URLs increasingly represent concepts rather than files. In his book The Art of Rails, Edward Benson points out that web developers are more and more often crafting URLs to represent high-level concepts, and the URL thus plays the role of the API for web applications. Frameworks such as Ruby on Rails certainly encourage this.

And then later in the article I discovered something I didn’t know about URLs: a path component can contain parameters, and these parameters are distinct from query parameters. Take this URL for example:;p1=v1/name2;p2=v2?q1=w1&q2=w2

Here, p1 and p2 are path parameters, and v1 and v2 are their corresponding values, while q1 and q2 are query parameters with w1 and w2 their corresponding values.

Anyway, Alan’s article is a good discussion of the URL for developers. I found it useful, and my grip on one of programming’s fundamentals is now slightly tighter.

Noisy Workmates and In-Ear Monitors

Posted 2 May, 2010 by David Porter
Categories: Uncategorized

I’m the kind of person that needs silence in order to concentrate. Most kinds of background noise distract me, and the most distracting of all is the sound of people talking, particularly when it’s close to me. And I’m distracted like this all the time at work. I share an office with seven other people — most of whom are not programmers — and they frequently chat and laugh and make loud phone calls. Most days my concentration is broken every thirty minutes or so, which makes me unproductive and frustrated.

A few weeks ago I decided I had to do something about it. Many times on the web I’d seen programmers recommend the use of noise-cancelling headphones to block out background noise. This sounded like the way to go but I knew next to nothing about them. A bit of research was in order.

It turns out there are basically three types headphones:

  1. external full-size headphones;
  2. earbuds;
  3. in-ear monitors (aka canalphones)

The best choice for blocking background noise while maintaining high sound quality and good portability are in-ear monitors (IEMs).

So the next step was to research which IEM model to buy. Here, was invaluable. Head-Fi is an audiophile forum devoted to headphones, earbuds, IEMs, and everything else audiophile. It contains a cornucopia of expertise and information. I read numerous discussions and reviews, and eventually a particular model stood out: the Head-Direct RE0.

REO In-Ear Monitors

REO in-ear monitors

The reviews claimed the RE0s have fantastic sound quality, good isolation, and are very good value at US$79. So I went ahead and ordered them.

Ten days later they arrived and I tried them out on the walk back from the post office. My first impression was actually a bit underwhelming; perhaps all the glowing reviews — and my own imagination — had led me to expect something staggering. The music certainly was clear and well defined, but it felt rather lifeless. I guess I’d been too exposed to bass-heavy car stereos and their ridiculous thump. Anyway, the reviews all agreed that the RE0 sound quality would improve with time, so I hoped that would be the case with mine.

I should remind you that the primary purpose of buying the earphones was to block out office noise to I could concentrate properly. And in this they accomplish well. As soon as I put them into my ears (which required a bit of fiddling and grimacing) all background noise vanished. I did feel isolated. My colleagues’ talking and laughing and loud phone calls seemed to me a million miles away.

So now it’s a few weeks later and my concentration at work has improved greatly. I’ve even had bouts of that programmer’s holy grail: the state of flow.

And as for the REOs’ sound quality, it has indeed improved noticeably. The posters on were right. In fact, the REOs sound better than anything I’ve ever heard (which admittedly isn’t much.) I now notice lots of little things I’ve never heard before in songs I’ve played a million times.

So the mission is a success. I’m no longer distracted unnecessarily by my workmates. I’m more relaxed and productive. And I’ve even rediscovered my love of music.

However the most significant outcome of all this is my discovery of a love for Norwegian post-jazz. This can only mean I’m extremely sophisticated.

Adding a Journal Entry Using Org-Mode

Posted 18 December, 2008 by David Porter
Categories: Uncategorized

Last week I decided to begin keeping a journal to record my programming notes and code snippets.  Since I’m a dedicated emacs user I wanted to be able to maintain the journal without leaving emacs.

Some quick research led me to Org-mode.  From the Org-mode homepage:

Org-mode is a mode for keeping notes, maintaining ToDo lists, and doing project planning with a fast and effective plain-text system.

Clearly it is a powerful system, and has lots of features beyond those I need for a simple journal.  However I was easily able to set it up to do what I need — namely, prepend date-stamped entries to a single file.

To make entering new journal entries as simple as possible I wrote the following function:

(setq journal-file "~/")

(defun start-journal-entry ()
  "Start a new journal entry."
  (find-file journal-file)
  (goto-char (point-min))
  (org-insert-time-stamp (current-time) t)
  (open-line 2)
  (insert " "))

(global-set-key (kbd "C-c j") 'start-journal-entry)

It opens the journal file, creates a new date-stamped entry at the top, and then positions the cursor ready for me to type the body.

So now I can easily start a new journal entry at any time by hitting C-c j.

Update: Dmitri Minaev pointed out that this can be more easily achieved by taking advantage of org-mode’s integration with remember-mode. Hence, I’ve replaced the above code with

(setq org-remember-templates
         "* %U %? %^g\n\n   %x"
(global-set-key (kbd "C-c j") 'org-remember)

The only thing I don’t like about this method is that trailing newlines are removed from the entry when it’s saved to the journal file. I prefer to separate journal entries by two blank lines. A quick check of the manual and the org-mode code didn’t uncover a way to turn off this behaviour.

SSHKeychain Not Storing Keys

Posted 16 December, 2008 by David Porter
Categories: Uncategorized

Recently I tried to make an ssh connection using keys from my OS X box, and I was surprised to be prompted for my passphrase.   I use SSHKeychain to manage my keys and it should automatically load them on demand.  However, I hadn’t used ssh in a while and evidently something in my configuration had changed.

I checked SSHKeychain’s agent status and found that no keys were listed as loaded.  I tried to load the keys manually by choosing  Agent -> Add All Keys, but I received the error

Failed to add all keys to the agent

without even being prompted for my passphrase.

Knowing SSHKeychain could store passphrases on the Apple Keychain, I figured it had created an entry there that was now incorrect for some reason.  I checked Keychain Access and it did indeed contain an SSHKeychain entry.  I deleted the entry and repeated the attempt to add my keys to SSHKeychain.  This time I was prompted for my passphrase and the keys were added successfully.

So now ssh is back to connecting without asking for my passphrase.