James Wilding's Weblog

Month: June, 2009

Magpie: a Twitter search gem

Today I’m releasing my first ruby gem into the wild. It’s called Magpie and is designed to provide a simple interface to Twitter’s search system, like this:

[ruby]
require ‘magpie’

search = Magpie::Search.new(‘Hello World’)
tweet = search.results.first

# Get the contents of the tweet
tweet.body # => ‘Hello World!’

# Get the publication date + time as a DateTime object
tweet.published_at # => #<DateTime: 1060555/43200,0,2299161>

# Get the name of the tweet’s author
tweet.author.name # => "Mr Foo (mrfoo)"

# Get the author’s Twitter URI
tweet.author.uri # => "http://twitter.com/mrfoo"

# Get the URI for the author’s profile image
tweet.author.image_uri # => "http://example.com/url/for/img.jpg"

# search.results is just an array
authors = search.results.collect { |tweet| tweet.author }
[/ruby]

Extra Search Options

You can specify additional search parameters as a hash of options:

[ruby]
# Provides 100 results limited to tweets in English
Magpie::Search.new(‘Hello World’, :rpp => 100, :lang => ‘en’)
[/ruby]

There’s a list of valid search params on Twitter’s Search API page.

Installing Magpie

The source code for Magpie is available on GitHub, and you can install the gem thus:

gem sources -a http://gems.github.com
gem install jameswilding-magpie

Magpie is very much a rough draft so feedback and suggestions for improvement are welcome. If you like it, pass it on!

Twitter Followers: Quality Over Quantity

From DailySEOBlog:

Don’t tell me that Twitter is all about good karma, bliss and living happily ever after! Everybody knows that everyone is looking for more followers. Period.

Rubbish. The number of followers you have on Twitter doesn’t matter: what matters is the quality of your followers.

If I were a small blogger who wrote about Mac software, and posted links to my blog on Twitter, one of the best things that could happen to me would be to have John Gruber follow my updates and re-tweet them. Even if John Gruber were the only person to follow me, his re-tweets would massively raise my profile in the indie Mac community. Which would be great (if I were an indie Mac blogger).

I’d hazard a guess that a sizable proportion of the mass of people who follow people like Oprah or Stephen Fry (who have 1,342,000 and 542,000 followers respectively) just see the follower status as a badge of honour — “yeah, I love Oprah so I follow her on Twitter”. Whether these people actually pay careful attention to their tweets is another question entirely. The DailySEOBlog actually links to an article which makes the same point: there is probably no direct correlation between the number of followers you have, and the number of people who click links in your tweets.

The race for more followers is basically a popularity contest. When combined with a desire to drive traffic to an external website (blog, sales, viagra, whatever), it reminds me of bad SEO in that it puts too much emphasis on numbers and not enough emphasis on content and findability. What you say is as important as who you say it to, and quality Twitter followers will be the folk who read what you write and pass it on if they value what you have to say — you don’t need thousands of them, just enough to reach an audience. Twitter should be a network based on quality, not dominance of numbers.

Pragmatism & Bad Markup

I’ve been reading a lot recently about semantic markup: when to use it, why to use it, whether to use it at all. For many people, semantics in HTML is a holy cow — no matter what, the argument goes, you should never shirk your responsibility to use markup that adds meaning to your content.

This is something I broadly agree with, but: sometimes it’s OK to use ‘bad’ markup. If you’re just creating something for your own private use, or are prototyping some HTML that you’re going to flesh out later, then the semantics of what you’re writing really don’t matter. As long as you can come back later and use ‘better’ markup when it matters, it’s OK.

Note the ‘can’ in my last sentence. You need to know that you’re going to be able to replace your tag soup with something beautiful at a later date, before it matters; otherwise you’re creating a code debt that you won’t be able to replay. It’s like the difference between borrowing a little money which you can afford to pay back later, and borrowing too much.

So when does ‘bad’ code start to matter? For me, the answer to this question comes in two parts. First, bad code starts to matter when the code becomes a problem for your users — when it starts causing accessibility issues, for instance. Second, when bad code starts to create problems for you — maintenance problems for instance, or problems understanding your past intentions — then the code matters. This is when you should stop, and rewrite.

HTML is an easy language to learn, and a difficult one to master. Like Ruby, it gives you more than one way of doing things; this is both a blessing and a curse. Because HTML allows you to markup code ‘wrongly’, we should always be careful to manage our code debts and learn to respect our own limits. A little borrowing against future effort it OK; an unmanageable debt of badly written, meaningless code is not.

Rails Code

[ror]
class ApplicationController < ActionController::Base

rescue_from(SomeError) { redirect_to error_page }

def index
@posts = Post.find(:all)
end
end
[/ror]

Image Test

What if I upload an image?

picture-11

Test

[ruby]
puts "hello world".capitalize
[/ruby]