FeedVolley: Messages From Iran

I just put up a quick hack I made with FeedVolley (more about FV here), that aggregates Twitter (and other media) feeds coming from inside Iran: Messages From Iran

I don’t know about news value, but it’s pretty cool to be able to refresh that page now and then and get a snapshot of the current mood and happenings, in these possibly historic times there.

It was also cool to find another use for FeedVolley, which I neglected a bit recently ;) I added some page caching on top of the existing feed caching, to allow it to handle some traffic (Slicehost’s 256MB slices seem to start sending swap alerts as soon as traffic rises above negligible). The sources are basically the ones listed here, with a few additional ones I’m trying to find. In fact, if you really want to keep a close watch on what’s going on, you may want to watch the FriendFeed stream – the FeedVolley page is really just an HTML skin to make the feed look a little nicer (hopefully).

(Favorite tweet so far: “@jonobacon IRC is blocked. Tell our regards to Ubuntu Global Jam from Iran. I’m twitting the #iranElection story from a Kubuntu machine :)“. Makes me think of starting to use Twitter again..)

JSONP, Quickly

I discovered JSONP just recently, following Chriscomment. Though I initially didn’t intend to support JSON, JSONP made enough difference that I rewrote most of the TheRealURL code (all 20 lines of it) to support it. Since it took me some time to figure out JSONP initially, perhaps a quick guide might help those who follow.

JSONP allows you to make an HTTP request outside your own domain, which enables consuming Web Services from JavaScript code. It relies on a JS quirk: while XMLHttpRequest is blocked from making external requests, there’s no such limit on <script> elements. What JSONP does is add a <script src=> element to the DOM, with the external URL as the SRC target.

To serve JSONP simply return the JSON data inside a function. e.g., this JSON:

{ "hello" : "Hi, I'm JSON. Who are you?"}


some_function({ "hello" : "Hi, I'm JSON. Who are you?"})

(The reason is that the latter is actually code that will run inside the created by the JSONP client, so it needs to be executable code rather than plain JSON data)

some_function is provided by the calling client, usually in the ‘callback’ parameter. So, a query like this:


Should return:

getthedata({ "hello" : "Hi, I'm JSON. Who are you?"})

On the server side, this means adding some code similar to this:

// assume $json holds the JSON response
if ($GET['callback'] != '') $json = $GET['callback']."( $json )"; 
return $json;   // my PHP is rusty but you know what I mean

On the client side, modern JS frameworks include JSONP support (or you can DIY). For example, in jQuery <= 1.2 adding &callback=? to the query string in getJSON method’s URL sends a JSONP request.(jQuery transparently replaces the ‘?’ with a unique string). Here’s how you get the unshortened URL for ‘bit.ly/a’ using therealurl:

	function(data){ alert(data.url) }

That’s about it. JSONP probably won’t feature in the next Beautiful Code edition and obviously you need to watch the URLs you’re accessing so you don’t get malicious JS code executed, but, until cross site XHR is resolved, JSONP can get the job done.

The Real URL

[UPDATED on April 21st, 2009 to reflect the JSON/P additions. Since it’s <24 hours after the initial release, I hope it won’t cause anyone problems.]

The Real URL began as a joke – after discovering, while working on another project, over 80 URL shortening services, I figured there must be room for a service that un-shortens all these URLs. (The web is overflowing with hype and blog posts/articles complaining about it just add to the noise, so it’s better to make your point by building something. My favorite example is the Twittering Office Chair).

Turns out there are already several out there: (eg, trueurl) but I built it anyway, since I had a slightly different approach in mind. The Real URL is meant to be used as a web service rather than on its own. It returns the “real” URL in either raw text, JSON or JSONP format – examples and details are on the homepage. (I added JSON mostly for JSONP, per Chris’ comment – admittedly I didn’t even know it existed ;) This enables cross site JS requests which might actually make The Real URL useful.

While I do want The Real URL to be solid and reliable in the long term, I don’t want to spend much time/money keeping it up. It’s a sustainability issue – building a system that will work reliably over a long time while requiring minimal care and resources. I made a few design decisions to that end:

  • Keep it simple (always a good idea). Real URL does only one thing and is accessible in only one way (the homepage demo uses XHR to access the service, to keep it so). It now supports text/JSON/JSONP, but it’s just the same output formatted differently. Sometimes you give up some elegance to make the product useful. As in the following item:
  • Deploy with Google’s App Engine. Initially it was nice, super-minimal Sinatra code. Unfortunately Google App Engine doesn’t support Ruby yet and there’s no service that offers comparable cost/stability ratio, so I rewrote in slightly less minimal Python for GAE.
  • Use App Engine’s domain (therealurl.appspot.com). Buying a domain and keeping it renewed isn’t a big deal, but it still requires some attention – especially if you happen to hit a nice domain name which people try to grab or piggyback on. Sticking with appspot.domain minimizes this issue. (if the need rises I might add a “real” domain later on, but in any case therealurl.appspot.com will remain active)

If you find a use for The Real URL this or have an idea for one, please comment here or email me at niryariv@gmail.com. Let the street find its own uses etc ;)

List of URL Shortening Sites

I’ve been compiling this list of URL shortening services for some time now, for use in one of my projects, and thought it might help developers who need it for their own work (or VCs who seek to place a couple $mil on one)

Anyway, here are the 74 82 (thanks commentors!) sites I got so far. If you use Ruby, just stick %w{ } around it and you’ve got an array. If you own one of these sites, put “Twitter-compatible” on your homepage, who knows ;):

adjix.com b23.ru bit.ly budurl.com canurl.com cli.gs decenturl.com dolop.com dwarfurl.com easyurl.net elfurl.com ff.im fire.to flq.us freak.to fuseurl.com g02.me go2.me idek.net is.gd ix.lt kissa.be kl.am korta.nu krunchd.com ln-s.net loopt.us memurl.com miklos.dk moourl.com myurl.in nanoref.com notlong.com ow.ly ping.fm piurl.com poprl.com qicute.com qurlyq.com reallytinyurl.com redirx.com rubyurl.com rurl.org shorl.com short.ie shorterlink.com shortlinks.co.uk shorturl.com shout.to shrinkurl.us shurl.net shw.me simurl.com smallr.com snipr.com snipurl.com snurl.com starturl.com surl.co.uk tighturl.com tinylink.com tinypic.com tinyurl.com tinyvh.com tr.im traceurl.com twurl.nl u.mavrev.com ur1.ca url-press.com url.ie url9.com urlcut.com urlhawk.com urli.ca urlpass.com urlx.ie xaddr.com xrl.us yep.it yuarel.com yweb.com zurl.ws

UPDATE: I moved the list to listable.org, per Karan’s suggestion, which allows easily exporting the date to SQL, JSON or text. Future updates will all be there: http://www.listable.org/show/url-shortening-sites

UPDATE #2: As a result of this post I ended up building a URL unshortening service, which I now think might actually have some uses. More here.

Backing Up MySQL Database with Subversion

While working on a recent Rails project, I wanted to occasionally backup the database to a remote location. Since we were already using Subversion for source control, I figured I could just use it for storing the DB contents as well and came up with a short Ruby script for this, called dbbackup (ironically, stored on a Git repo – I guess it could use a –use-git option ;)

The only Rails tie is that it uses config/database.yml to get the database name and login info, so you could easily adapt it to run on non-Rails projects too. It’s built so that it can be ran by a nightly cron task, and since it’s only sending the diffs it wouldn’t be too resource-heavy.

I wouldn’t use this for Facebook’s production servers, but if your needs are more moderate you might find it useful. Feel free to send over any questions or patches to niryariv@gmail.com. Here’s the repo URL again, with the script and an explanation on how to use it: http://github.com/niryariv/dbbackup/tree/master

Feedvolley Design

I like 37signal’s Design Decisions posts, which explain the thinking behind seemingly small details in their apps. It makes sense: building the core functionality of most web apps is relatively straightforward, the real quality (and, ultimately, most of the effort) is in the details. So, here’s my take on Feedvolley‘s design.

I’m not aware of any site that does the quite same thing as Feedvolley, so the first challenge is to get users to understand what it’s about and how to use it. My favorite way to learn to use something is to play around with it (not recommended with firearms, bikes and similar BTW), so the goal was to make Feedvolley’s interface invite users to do just that. That means making it as easy as possible to accomplish something, and then make it rewarding to keep playing with what was created.

To make starting out easy, the homepage is a minimal form with fields for feed or HTML page URL (one of the features that make RSS/Atom a good Web API is the fact it’s often auto-discoverable) and email (more about that in a moment). A default theme is pre-selected.

Another way to create a page is by clicking the “Create a page like this” link located on top of every user-created Feedvolley page. This lets users start with an existing page and modify the content and HTML to their needs. That’s one of my favorite web app buttons – it invites a viewer to become participator, and lets users start with something similar to what they want, and just modify it as they learn the system.

You might have noticed there is no registration step here. Personally, I hate having to register to a website in order to do anything. Feedvolley (like Notifyr) uses email as its user authorization system. Each user gets an edit link with a unique token string. This token is also kept in a cookie, so users aren’t forced to go to their email in order to start editing. “Create a page like this” also serves as backup for this system. In case a user lost the edit link, she can simply go to her page, create a duplicate and continue editing that.

This may not be perfect, but seems optimal for most users. If some users ask for a more rigid authorization system, we can always add it later on as an option.

Once a user created a page, the next step is to make further work on it possible, and worth the time. This is where the “Customize” link comes into play: users can set a page’s URL path and have complete control over the HTML, JavaScript and CSS in the theme. To make themes as easy as possible, Feedvolley’s markup closely follows that of Tumblr (Tumblr’s templates inspired the Feedvolley concept, in fact. They do great work over there). In “work with the existing environment” spirit, this lets users easily adapt existing Tumblr themes for Feedvolley and also use Tubmlr’s docs, which also saved us some documentation pains :)

As far as design goes, I’m with the “it’s done when there’s nothing more to remove” (as opposed to “nothing more to add”) school. So, I’m pretty happy with the result in Feedvolley. Some challenges remain: how to make it more obvious that a page can be customized once it’s created, for example. It’s not perfect yet and we’ve already incorporated some user feedback into it – if you have any comments or requests, please leave them here or email me directly: niryariv@gmail.com.

Mod_rails and Accepting the Environment

I don’t usually read Fast Company & co, but I found an article in the recent issue pretty inspiring. It’s about a landscaping company called Whole Systems Design which tries to build stuff in a way that takes into account the environment where it’s located. Environment not just in the “compost your pizza leftovers to offset CO2 of your vacation” meaning, but in the “stuff that already exists when you start building” sense. It’s a simple and intelligent approach to design – create something that works with what’s already there. From the article:

[company’s founder, Ben Falk] calls mainstream environmentalism, with its “nihilistic,” minimize-human-impact approach, one of the “largest hurdles we face toward being a good community member of the earth again.” He cites one of his influences, Berkeley architect Christopher Alexander, who asked, “Can a building be just as natural as a tree?” Adds Falk: “Or a beaver dam? … It goes beyond ‘Let’s pretend we’re not there.’ We’re here. Let’s make a good impact.”

This links for me with the release of Phusion Passenger, aka “mod_rails for Apache”. I don’t know how well it works (Dreamhost now offers it, which seems a good sign), but if it works well this may be the most important thing that happened for Ruby on Rails since it was launched.

Rails’ main weakness, in my opinion, was that it did not take into account what was already before it, namely the Apache web server (and also stuff like existing code/DB schemes, but that’s less critical perhaps). It was very slow under Apache, and instead of fixing this the Rails community set out to replace Apache with something else – first lighttpd, then Mongrel, now nginx. But it turns out Apache leads its category, by a large margin, for a reason and that creating a good web server, though it might seem pretty straightforward to begin with, is actually pretty hard.

With mod_rails, Rails deployment may now be as easy as PHP deployment, which will give RoR a chance to compete in the shared server space, which is often looked down upon and yet is far bigger than the dedicated server domain, as seen here (this is based on PHP IP vs Domain stats – very rough but generally the right idea):

Ruby on Rails potential market, before & after mod_rails

It is said that The Velvet Underground were hugely influential even though few actually bought their records, because most of those who did listen to them ended up starting bands. For some time, I was thinking Ruby on Rails is going to end up similarly – myself and many other developers got our initial exposure to MVC and ORM and Convention Over Configuration from Rails, but we often ended up building applications in Rails-influenced frameworks like CakePHP or Code Igniter that implemented these ideas in languages that could be easily deployed with reasonable performance (the key word here is easily. You can get performance with Rails, but it requires leaving your core problem for some time, to specialize on deploying RoR). Now, it may not be this way – provided people are still working on improving the docs :)

Prixfeed.com and Design Decisions

I spent some time recently polishing the old “Amazon price feed” project, and gave it its own domain: Prixfeed.com (pricefeed.com was, naturally, taken). Basically what it does is take an Amazon product (by its page URL or ASIN code) and returns an RSS feed of its price. This lets users keep a watch on the price, getting updated whenever it changes.

Always liked 37signals‘ Design Decisions posts, so here are a few I made with Prixfeed, mostly to keep it simple and minimum-effort as possible (BTW, where it says “RSS Reader” I refer to the software reading the RSS feed, not the person using that software):

  • One URL:

    http://prixfeed.com/?ASIN=<Amazon ASIN or product URL> returns the RSS feed.
    (Or, with URI Templates: http://prixfeed.com/?ASIN={ASIN} )

    http://prixfeed.com/ without params will display a form where the user can enter an Amazon ASIN code or product URL, which then directs to the its RSS feed.

  • No cron jobs: Prixfeed simply checks a product’s price whenever the above URL is called (naturally, some caching is needed here to guard from buggy/malicious clients overloading it). This means data refresh is timed and triggered by the RSS readers, removing the need to build a backend update system or keep track of what data needs to be – ie, which products are currently monitored. Which leads to:
  • No database: so no need to keep track of who’s tracking which product, but with a non-RSS system (eg. email alerts) you’d still have to store prices in order to guarantee you’re only sending out a message when the price has changed. RSS, though, has a guid element which lets an RSS reader determine whether an item was read before. By making that GUID a function of the price, Prixfeed makes sure the RSS readers will display only new prices as new items.
  • Machine readable: it’s easy to programatically create a Prixfeed URL request for an item price, but I wanted to make the response machine-parseable as well, while keeping it human-readable. One way would be to have a URL param that will return an XML response, but I like the minimalism of a single URL so I decided to use a Microformat-like approach. The response’s description element contains HTML which includes attributes like id="price" etc that allow automatic parsing of the content (more details here).
  • Small output: each message contains the text “The Amazon price for <item> is now $x” and a purchase link. I like minimum friction products – there should be some proportion between the value you’re getting from something and the investment it requires you to put in, both when entering information and reading it. Since the value here is less than life-changing, I figured I better keep the time investment minimal as well.

That’s it then – once again I manage to write a blog post with more lines than the code its about! Go on and RSS thy Amazon purchases!