A Tip for Developing Twitter Sites

I've been working on a site that interfaces with Twitter lately. For the most part, it's straightforward. The API is simple, it's easy to register your application with them, and they are fairly quick to whitelist you (which allows you to exceed the normal limitations for requests/hour) if you have a decent reason for needing it.

One problem I ran into, though, is with the oauth callback URL. When you register your app with them, you specify a callback URL that will be used once your user has been authenticated with Twitter. Normally, it would be something like this:

http://mysite.com/oauth_callback

When you're developing your application locally though, you'd like to have the site run on your own machine so you can run it without having to publish to a different server and so that you can debug. In such a case (say it's a Rails app), you'd want the callback to be something like this:

http://localhost:3000/oauth_callback

Twitter won't take this though, as it doesn't appear to be a valid web address. My initial thought was that the specification of a port (3000) was causing the issue, but it's actually that 'localhost' couldn't be a valid URL.

If you're using Linux, you can easily work around this by editing your /etc/hosts file and adding a line similar to this:

127.0.0.1 local.com

Now you can update your Twitter app to use http://local.com:3000/oauth_callback as the callback URL, and run your site locally.

No Comments


How Piracy can Lead to Increased Sales, a Case Study

About seven years ago, I wasn't much of a reader. The occasions where I'd sit and read a novel were few and far between. I had a bookshelf full of technical books, but only a handful of non-technical books. Project Gutenberg and my Palm device changed that. I installed a free e-book reader (Weasel Reader, I believe), downloaded some classic texts from Gutenberg, and I was off to the races.

I didn't really know much about literature, though, so finding good stuff in the thousands of texts that are available at Gutenberg was a hit-and-miss process. H.G. Wells, and Mary Shelley were fun to read, but I found Moby Dick painful. My interest started to wane.

A short time later, I came across a binary newsgroup for e-books where someone was in the process of uploading several hundred megabytes of books. Some of the texts were public domain, but most were scanned from copyrighted works. The collection leaned heavily toward science fiction, but there were thousands of authors represented and plenty of variety. I downloaded all of them and started my own collection. I started mainly with sci-fi and fantasy; I whipped through the "Lord of the Rings" trilogy in no time. After that, I tackled Arthur C. Clarke's "Odyssey" series, Roger Zelazney's "Amber" series, and Aasimov's "Foundation" series. It was great stuff.

Naturally, as I read more, my knowledge of, and interest in, literature grew. I started focusing on novels that have been earmarked as the best of the century, and I was able to pull quite a few of them out of the collection that I'd downloaded. I enjoyed titles like "Slaughterhouse Five", "One Flew Over the Cuckoo's Nest", "To Kill a Mockingbird", and anything by Hermann Hesse or Ernest Hemingway so much that reading started taking up more and more of my time.

At some point, it occurred to me that it would be nice to start building a library of the novels that I'd enjoyed the most. I started buying cheap paperbacks, but I quickly found that it was much nicer to have decent editions. Chapters became my favourite place to shop, and I logged a lot of hours browsing Amazon as well. Then one day I received a mailing from a company called "Folio". I'd never heard of them, but the full-colour brochure caught my attention right away. They had beautiful hard-cover editions of tonnes of classic books. Each book had it's own slip-cover. Naturally, these books weren't cheap, and the only way to get membership was to buy several of them. I splurged, though, and I haven't regretted it since. I always look forward to receiving their mailings for new books, and I've renewed my membership each year.

In no time at all, I filled two existing bookshelves in my living room. We added another book case, and it too became full. My reading started moving from classic novels to psychology and philosophy. I started buying the collected works of Carl Jung one at-a-time, and dove into Dostoevsky and Tolstoy. It actually got to the point where I started giving away some of the books I'd bought earlier as I replaced them with nicer editions.

Several years later, I'm still reading every day. I split time between reading e-texts on my Palm and reading old-fashioned paper books. I have an impressive library, on which I've spent thousands of dollars.

My point is this: if it weren't for the pirated collection of e-texts that I downloaded several years ago, it's very unlikely that I'd have spent any of that money on books. I feel that authors would do well to get their works into the hands of the readers by any means possible.

The sales will follow.

No Comments


Quick tip: Trouble installing sqlite3-ruby Gem

On Ubuntu, I ran into this today:

sudo gem install sqlite3-ruby
Building native extensions. This could take a while...
ERROR: Error installing sqlite3-ruby:
ERROR: Failed to build gem native extension.

/usr/bin/ruby1.8 extconf.rb install sqlite3-ruby
checking for fdatasync() in -lrt... yes
checking for sqlite3.h... no

make
make: *** No rule to make target `ruby.h', needed by `sqlite3_api_wrap.o'. Stop.

Fixed as follows:

sudo apt-get install libsqlite3-dev

No Comments


Uptime

As  mentioned in my previous post, I've moved from Slicehost to an Amazon EC2 instance.  Slicehost is a really great company, and I thoroughly enjoyed my time with them.  The've got APIs to make everything easy to automate, and their documentation is incredibly complete.  As much as I hate to move away from something that has worked so well, however, I've been a big proponent of EC2 since it was launched, and the timing is right.

Anyway, I shut down the Slicehost slice yesterday, but before I hit the final 'delete' button, I logged on to the server and ran the 'uptime' command, which shows how long the server has been running since the last reboot.

Two-hundred and thirty-two days!

Of course, I'd restarted the mongrel instances many, many times during the period, but the server hadn't been rebooted in almost eight months.  That's pretty impressive. I recall one time in the two years that I was with Slicehost where they advised me that a hardware failure necessitated a move to a new machine, but other than that, their service was nearly perfect.

With a slight twinge of guilt, however, I proceeded to delete the slice.

It's "farewell", not "goodbye", Slicehost.

No Comments


EC2 Reserved Instances

For a couple of years, I’ve been using Slicehost to host my applications.  My needs aren’t intensive: there are a couple of public applications with moderate usage and a handful of utility applications that are mainly for my own use.  I started with a 256MB ($20/month) slice and was able to upgrade painlessly to a 512MB ($38/month) slice when I needed the extra memory.  Overall, Slicehost has suited me very well.

However, ever since Amazon started offering EC2, I’ve been planning to go that route.  The only thing that’s been holding me back is the cost, which at 10 cents/hour ends up being over $70/month.  The killer feature of EC2 is, of course, the ability to add capacity whenever it's required, but my needs now are for a single, full-time server, and it just didn't make sense to pay the extra money.

Until now.

Last week, Amazon announced Reserved Instances, which basically allow you to make a pre-payment to reserve the server for one or three years, and then pay a reduced hourly rate.  For example, I signed up for a 3-year small instance, which costs $500 up front and then the hourly rate is only three cents.  This reduces the overall cost of the server to under 50% of what it was previously, or roughly $36/month.  A small instance in EC2 is still quite a step up from a 512MB slice, so I now have some room for future growth.

I’ve been setting things up over the past few days, and it has all gone very smoothly.  This is my first time running Rails apps under Passenger in a production environment, and it’s been a pleasant experience.  More on that later.

No Comments