Posts tagged how to

How to include retweets into tumblr’s recent tweet section

As I retweets more than write tweets of my own, I had some problems getting my Twitter timeline to show up in tumblr.

In tumblr recent tweets are fetched with a script called tweets.js which calls https://twitter.com/statuses/user_timeline/:screen_name.json?callback=recent_tweets&count=5.

Unfortunately that API call does not return retweets but counts them in anyway. Which means that if your last original tweet is more than 5 tweets away, the API call returns an empty list.

In the Twitter API documentation I found an alternative API which accepts a parameter include_rts for controlling whether or not retweets should be included in the response: https://dev.twitter.com/docs/api/1/get/statuses/user_timeline

To use that API instead I made two modifications to my tumblr page (Customize theme > Edit HTML):

    1. I removed the import of tweets.js and
    2. created a custom script block for fetching my tweets:
<script type="text/javascript">
        var script = document.createElement('script');
        script.type="text/javascript";
        script.src = "https://api.twitter.com/1/statuses/user_timeline.json?include_rts=1&screen_name={TwitterUsername}&count=5&callback=recent_tweets";
        document.getElementsByTagName('head')[0].appendChild(script);
</script>

I am still using the original callback function  (recent_tweets) even if I made some minor modifications, like writing out a default text if the API should ever return an empty list again.

The complete API call:

https://api.twitter.com/1/statuses/user_timeline.json?include_rts=1&screen_name={TwitterUsername}&count=5&callback=recent_tweets

Before:

{block:Twitter}
    <div id="twitter" style="display:none;">
        <h3><a href="http://twitter.com/{TwitterUsername}">Latest Tweets</a></h3>
        <div id="tweets"></div>
    </div>

    <script type="text/javascript">
        function recent_tweets(data) {
            for (i=0; i<data.length; i++) {
                document.getElementById("tweets").innerHTML =
                    document.getElementById("tweets").innerHTML +
                    '<a href="http://twitter.com/{TwitterUsername}/status/' +
                    (data[i].id_str ? data[i].id_str : data[i].id) +
                    '"><div class="content">' + data[i].text +
                    '</div></a>';
            }
            document.getElementById("twitter").style.display = 'block';
        }
    </script>
{/block:Twitter}

<!-- Put this at the bottom of the page -->
{block:Twitter}
    <script type="text/javascript" src="/tweets.js"></script>
{/block:Twitter}

After:

<script type="text/javascript">
    function recent_tweets(data) {
        var tweets = document.getElementById("tweets");
            if (data.length !== 0) {
                for (i=0; i<data.length; i++) {
    		    tweets.innerHTML = 
    		    tweets.innerHTML + '<a href="http://twitter.com/{TwitterUsername}/status/' + (data[i].id_st r ? data[i].id_str : data[i].id) + '"><div class="content">' + data[i].text + '</div></a>';
    		}
        }
        else {
            tweets.innerHTML = "Keep calm and carry on. There's nothing to see here."
         }
	 document.getElementById("twitter").style.display = 'block';
    } 
    var script = document.createElement('script'); 
    script.type="text/javascript";
    script.src = "https://api.twitter.com/1/statuses/user_timeline.json?include_rts=1&screen_name={TwitterUsername}&count=5&callback=recent_tweets";
    document.getElementsByTagName('head')[0].appendChild(script); 
</script>

Getting Started with Python on Heroku/Cedar

Tutorial on how to create and deploy a simple Python web app using Flask, virtualenv and the Heroku Toolbelt

Mercurial: Getting all heads on a certain branch

hg log -r "branch('changeset|branchname') and head()"

Replace <changeset> with a changeset number from the branch you’re interested in.

Installing pymetrics

melanie@mipu:~$ sudo apt-get install pymetrics
melanie@mipu:~/pyProject$ find -iname "*.py" | xargs pymetrics -q --nosql
melanie@mipu:~/pyProject$ ls
metricData.csv  src  tests

Installing, running and stopping Jenkins

melanie@mipu:~$ sudo apt-get install jenkins
Starting Jenkins: 

I first tried running jenkins without root permission but that resulted in the following error message:

melanie@mipu:~$ service jenkins start
start: Rejected send message, 1 matched rules; type="method_call", sender=":1.107" (uid=1000 pid=29374 comm="start jenkins ") interface="com.ubuntu.Upstart0_6.Job" member="Start" error name="(unset)" requested_reply="0" destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init")

With root permission:

melanie@mipu:~$ sudo start jenkins
jenkins start/running, process 8919

However, even after starting the server, jenkins was still unreachable; to get around that I had to update the JAVA_HOME variable in jenkins.conf:

from 

/usr/lib/jvm/java-default (or default-java)

 to

/usr

or actual path, e.g.

/usr/lib/jvm/java-6-openjdk

(source: How to start Jenkins?)

melanie@mipu:~$ sudo vim /etc/init/jenkins.conf
Stopping Jenkins:
Needs root permission, same as with start
melanie@mipu:~$ sudo stop jenkins
jenkins stop/waiting

Installing nose

melanie@mipu:~$ sudo apt-get install python-pip
melanie@mipu:~$ sudo apt-get install nose
melanie@mipu:~$ nosetests
----------------------------------------------------------------------
Ran 0 tests in 0.006s
OK