1. Using Feedly in Chrome just got a lot easier

    Posted September 15, 2013 in How-to  |  No Comments so far

    When Google Reader died I switched to using Feedly. I like it a lot – enough that I don’t miss Google Reader – but one thing that’s been a bit of a headache is easily subscribing to RSS feeds from within Chrome.

    In the days of Google Reader it was pretty straightforward but the Feedly transition made that process a lot harder. Various Chrome extensions failed to solve the problem, subscribing me to comments feeds instead of main feeds, or simply failing to find feeds at all. Before long I’d reached the last resort of viewing source, doing a Ctrl-F for “.rss”, then copying and pasting that into the Feedly web interface. Going through those steps is enough to make you think that RSS is indeed doomed.

    Anyway, I’ve just found out how to sort this problem out once and for all, integrating Feedly with Chrome just as Reader once was. The solution is posted over here at Coderwall by Rod Hilton and will let you add RSS feeds to Feedly using the standard Chrome RSS extension. It’s just like in the good old days and will allow me to spend a few more months pretending to myself that RSS has a future.


  2. Tips for lazy writers: the “Thought For The Day” pattern

    Posted May 9, 2013 in How-to  |  No Comments so far

    Thought For The Day is the short religious bit on Radio 4’s Today programme. Every day a different religious figure spends five minutes imparting a mini-sermon in the hope of providing listeners with some fleeting sense of spiritual enrichment.

    Like many things in life, Thought For The Day has a pattern. It goes something like this:

    1. Talk about a topical event
    2. Somehow link the topical event to religion
    3. Talk about religion
    4. Conclude by referencing the topical event once more

    Not everyone follows this pattern – Anne Atkins’ stream-of-consciousness scattergun of personal anecdotes consistently buck the trend – but by and large this is what you get when you listen to Thought For The Day. Here’s a recent-ish example from Canon Dr Alan Billings that allows us to see the pattern at work:

    1. Talk about a topical event:

    Over the weekend I looked at the new typology of social class that the BBC has just put on its website…

    This was a reference to the Great British Class Calculator which had been doing the rounds on the web at the time.

    2. Link the topical event to religion:

    For Christians, the question of social class was unavoidable from the start, because Christianity first emerged in a highly stratified society of rich and poor, powerful and powerless, slave and free…

    We could be diplomatic here and say that the segue into religious content is clearly signposted. Or we could not, and say instead that it has the subtlety of a reindeer.

    3. Talk about religion:

    Converts came from each of these groups…

    As you’d expect, this forms the bulk of the text and is usually the section where Thought For The Day contributors make their essential points. It’s also where I tend to tune out.

    4. Conclude by referencing the topical event once more:

    …a healthy society is one where people recognise that what they have in common – their need of God’s grace – is far more significant than any ordering of social class.

    Notice that it concludes with two words, “social class”, that appeared in the very first sentence – a classic top-and-tail technique that encloses the argument and gives the impression that it was actually pretty coherent and well-structured even if you did doze off for a while during the part about the Romans, Corinth and St Paul.

    Making it work for you

    It’s easy to mock this pattern, especially for those who are lazy secularists that see Thought For The Day as a loathsome combination of religiosity and getting up early in the morning. But before we rush to judgement it’s worth recognising its value for those who are also lazy writers.

    It’s a pattern that can be applied to any topic, so if you’re ever asked to write a blog post for your employer or an article for a specialist magazine, and are short on time or energy, why not try using it?

    To demonstrate its effectiveness I’ve set myself the challenge of using it to combine a recent current event, Sir Alex Ferguson’s resignation and the specialist topic of Eurozone monetary policy. I apologise for taking gross liberties with the facts in the passage below; I’m deeply ignorant about both of these subjects.

    Manchester United fans around the world were shocked to learn yesterday that Sir Alex Ferguson, the manager who has won their team countless trophies over the years, has resigned from the club. Many have voiced their concern that the glory days are over. Does Manchester United now face a crisis?

    The same question might be asked about the eurozone. Despite coming through the Greek and Cypriot crises relatively unscathed the ECB faces stormy times ahead… [imagine another 200 words about ECB monetary policy, the general theme being that Mario Draghi is the right person to sort out all the problems]

    …So as we can see there are many reasons to be optimistic. Mario Draghi may not be in the business of winning trophies, but unlike Sir Alex Ferguson we can count on him staying the course for the foreseeable future.

    It’s crude but I hope that the lazy writers among you can see how it can be used to eke out a viable article from the most crude of premises, and with a minimal amount of effort. So if no other inspiration strikes you in the hours ahead, let that be your… thought, for the day.


  3. How to make page titles work properly in Now Reading Reloaded

    Posted May 7, 2011 in How-to  |  9 Comments so far

    I use a plugin called Now Reading Reloaded for the Library section of this site, and very good it is too.

    Unfortunately the developer behind the plugin doesn’t have time to maintain it any more. This means that some things have started to break in newer versions of WordPress, particularly the way the plugin works with page titles. If you’re using Now Reading Reloaded and the title of a book isn’t showing up in your <title> tag, this post should help you fix it.

    The problem is with the file now-reading.php, which you’ll find in the plugin folder. Open this file in a text editor and find the function called nr_page_title(). It starts with the following line:

    function nr_page_title( $title ) {

    This is the function that tells WordPress what to put in the page title, and if you’re having the problem I was having this is where the blame probably lies. To solve the problem you’ll need to replace this function with the one that appears below.

    function nr_page_title( $title ) {
        global $wp, $wp_query, $wpdb;
        $wp->parse_request();
    
        $title = '';
    
        if ( get_query_var('now_reading_library') )
            $title = 'Library';
    
        if ( get_query_var('now_reading_tag') )
            $title = 'Books tagged with “' . htmlentities(get_query_var('now_reading_tag'), ENT_QUOTES, 'UTF-8') . '”';
    
    	if ( get_query_var('now_reading_author') ) {
    		$author = $wpdb->escape(urldecode(get_query_var('now_reading_author')));
            $author = $wpdb->get_var("SELECT b_author FROM {$wpdb->prefix}now_reading WHERE b_nice_author = '$author'");
    		$title = 'Books by ' . $author;
    	}
    
        if ( get_query_var('now_reading_search') )
            $title = 'Library Search';
    
    	if ( get_query_var('now_reading_title') ) {
            $esc_nice_title = $wpdb->escape(urldecode(get_query_var('now_reading_title')));
            $book = get_book($wpdb->get_var("SELECT b_id FROM {$wpdb->prefix}now_reading WHERE b_nice_title = '$esc_nice_title'"));
    		$title = $book->title . ' by ' . $book->author;
    	}
    
        if ( !empty($title) ) {
            $title = apply_filters('now_reading_page_title', $title);
            $separator = apply_filters('now_reading_page_title_separator', ' » ');
            return $title.$separator;
        }
        return '';
    
    }
    

    Copy this function and paste it into now-reading.php. To be on the safe side, take a backup of now-reading.php before you do this. Make sure you paste over the entire function – no more, no less.

    If all goes well your page titles should now work if you’re using WordPress 3.0 and above (and if you aren’t, you need to update WordPress right now). If you have any questions, let me know in the comments.

    Note: I was only able to find this fix by reviewing the code of Now Watching, an actively maintained fork of Now Reading Reloaded which handles movies instead of books. The author of Now Watching is Zack Ajmal and he deserves more credit than I do for this fix!


  4. How to post your Last.fm loved tracks to Twitter

    Posted December 8, 2009 in How-to  |  5 Comments so far

    I remember when Twitter was still quite new. Back then, a lot of people were still trying to think of uses for it and one thing that was fairly common was to plug it into your Last.fm account.

    In retrospect I can see why that was seen as a good idea. Twitter was supposed to be about broadcasting minor ephemeral details, and the music you were currently listening to definitely fell into that category. But there was a downside. People listen to a lot of music and, with a Twitter post for each track played, that added up to a lot of useless information on Twitter. Thankfully, the practise of scrobbling directly to Twitter soon faded out.

    Today there are some more useful and less irritating ways of posting information from Last.fm (or, indeed, its open source alternative Libre.fm to your Twitter account. One of them, Tweekly.fm, produces an automated weekly tweet of your top three artists. Another one, which I’m going to explain here, involves posting tracks that you “love” on Last.fm to your Twitter account.

    Here’s how it works:

    1. If you don’t have a Last.f account, create one here
    2. Get the URL of your “Loved tracks” RSS feed. This is easy: just change “USERNAME” in the URL below for your Last.fm username.

      http://ws.audioscrobbler.com/2.0/user/USERNAME/lovedtracks.rss

    3. Test the URL by opening it in a browser. You should see something that looks a bit like this:
      Last.fm RSS feed browser output
    4. If it works, go to Twitterfeed.com and create an account if necessary
    5. Once logged in to Twitterfeed, click on the “Create new feed” button to the top-right of the screen
    6. In “Step 1: Send Feed To”, select Twitter. Click on the large “Authenticate Twitter” button and enter your Twitter account details. You’ll then be directed back to Twitterfeed.com
    7. In “Step 2: Name feed & source URL”, enter a name for the feed – this can be anything you like. In the “RSS Feed URL” field, paste the URL of your RSS feed
      Twitterfeed screenshot 1
    8. Click on the “test feed” button to make sure the feed is valid
    9. Click “Advanced settings”. A bunch of new options will appear underneath. Here’s a screenshot with the things you need to check circled in red:
      Twitterfeed's advanced settings

    10. In “Post content”, select “Title Only”. This will ensure that the posts to your Twitter account only contain the artist, title and shortened URL to the track you loved
    11. Make sure “Post link” is checked and a URL shortening service is selected
    12. You might also want to enter some text in the “Post Prefix” or “Post Suffix” fields, otherwise your tweets might be slightly baffling
    13. You’re done – just click “Create feed” and that’s it set up.

    Now whenever you “love” a track on Last.fm, your Twitter account will post a link to it. This makes Last.fm’s “love” feature a bit more useful when it comes to recommending music to other people – especially people who don’t use Last.fm. And as long as you don’t love everything you listen to you won’t be clogging up your Twitter feed.


  5. Using Google Spreadsheets to extract Twitter data

    Posted November 20, 2009 in How-to, twitter  |  28 Comments so far

    Last weekend I was looking for ways to extract Twitter search data in a structured, easily manageable format. The two APIs I was using (Twitter Search and Backtweets) were giving good results – but as a non-developer I couldn’t do much with the raw data they returned. Instead, I needed to get the data into a format like CSV or XLS.

    Some extensive googling led me to this extremely useful post on Labnol, where I learnt about how to use the ImportXML function in Google Spreadsheets. Before too long I’d cracked my problem. In this post I’m going to explain how you can do it too.

    Data you can extract from Twitter

    This walkthrough will teach you how to extract two types of Twitter data using Google Spreadsheets – tweets and links.

    Tweets are extracted using the Twitter Search API in conjunction with ImportFeed. This allows Twitter search results to be extracted into a spreadsheet format.

    Links are extracted using the Backtweets API in conjunction with ImportXML. The Backtweets API allows you to find any links posted on Twitter even if they’ve been shortened using services like bit.ly or tinyurl.

    I’m in a hurry, can I just do this right now?

    If you just want to do it – instead of learn how to do it – just open this Google spreadsheet I’ve created.  You’ll need to make your own local copy so you can edit it. Instructions can be found in the spreadsheet itself.

    How to extract tweets containing links

    The instructions below will help you create a Google Spreadsheet that pulls in and displays the time, username and text of all tweets containing links to a specified page. Because it uses Backtweets, these tweets will be retrieved even if they used shortened URLs from services like bit.ly or tinyurl.

    1. Create a new spreadsheet in Google Documents.
    2. Enter column labels in this order: “Search criteria”, “Timestamp”, “Username” and “Tweet text” in cells A1 to D1.
    3. In cell B2, underneath Timestamp, insert the following formula:
    4. =ImportXML("http://backtweets.com/search.xml?itemsperpage=100&since_id=1255588696&key=key&q="&A2,"//tweet_created_at")
    5. In cell C2, underneath Username, insert the following formula:
      =ImportXML("http://backtweets.com/search.xml?itemsperpage=100&since_id=1255588696&key=key&q="&A2,"//tweet_from_user")
    6. In cell D2, underneath Tweet Text, insert the following formula:
      =ImportXML("http://backtweets.com/search.xml?itemsperpage=100&since_id=1255588696&key=key&q="&A2,"//tweet_text")
    7. Now paste a search query into cell A2 – say, http://www.google.com. After a few seconds, you should see columns B, C and D fill up with tweets, looking something like the image below:
    8. Google Spreadsheet showing Backtweets results

    9. The formulas pasted into cells B2, C2 and D2 all reference the URL in cell A2. This means that whenever you paste anything new into A2, the search results should refresh.
    10. Also, you can paste parts of URLs into A2 – not just entire ones. This is useful for seeing all links to a specific directory on your site, for example.

    Finally, this tool can only extract 100 results at a time – but it is possible to set it up to retrieve more than that. Look at my sample Google Spreadsheet if you want to do this.

    Extracting tweets from Twitter search results

    The method for doing this is identical to the above, but uses the ImportFeed function instead of ImportXML.

    1. Create a new spreadsheet in Google Documents.
    2. Enter column labels in this order: “Search criteria”, “Timestamp”, “Username” and “Tweet text”. For the rest of this walkthrough, I’m going to assume that these labels are in cells A1 to D1, but in reality you can put them wherever you like
    3. In cell B2, underneath Timestamp, insert the following formula:
      =ImportFeed("http://search.twitter.com/search.atom?rpp=20&page=1&q="&A2, "items created")
    4. In cell C2, underneath Username, insert the following formula:
      =ImportFeed("http://search.twitter.com/search.atom?rpp=20&page=1&q="&A2, "items author")
    5. In cell D2, underneath Tweet Text, insert the following formula:
      =ImportFeed("http://search.twitter.com/search.atom?rpp=20&page=1&q="&A2, "items title")

    6. Type a search query into cell A2 - say, "Hoth." Hit enter and the results will load. It should look something like this:
    7. Google Spreadsheets with data from Twitter searchThings will go wrong if you insert characters like # or @ into the search query. To get around this, type %23 instead of # and %40 instead of @. This will allow you to search for hash tags and usernames.

    I haven't been successful in generating more than 20 search results per request, but you can get around this using the page number parameter in the ImportFeed query string. See my own Google spreadsheet to find out how to do this.

    I hope these instructions are useful - if you have any comments, questions or feedback, please let me know in the comments.