The Sun BabelFish Blog
Don't panic !
Adding twitter to my blog using Scala
Having added javascript widgets to my blog a few months ago, I found that this slowed the page downloads a lot. Here is a way to speed this up again, by pre-processing the work with a Scala script, and using iFrames to include the result.
Here are the short steps to do this:
- I wrote a Scala Program (see source) to take the twitter Atom feed, and generate xhtml from it.
- I wrote a shell script to run the compiled scala jar
#!/bin/bash export CP=$HOME/java/scala/lib/scala-library.jar:$HOME/java/scala/lib/learning.jar /usr/bin/java -cp $CP learning.BlogIFrame $*
- Then I just started a cron job on my unix server to process the script every half an hour
$ crontab -l 5,36 * * * * $HOME/bin/twitter.sh $HOME/htdocs/tmp/blogs.sun.com/tweets.html
- Finally I added the iFrame to my blog here pointing to the produced html
<IFRAME src="http://bblfish.net/tmp/blogs.sun.com/tweets.html" height="300" frameborder="0"></IFRAME>
As a result there is a lot less load on the twitter server - it only has to serve one atom feed every half an hour instead of 1000 or so a day - and my html blog page does not stall if the twitter site itself is overloaded.
Also I learnt a lot about Scala by doing this little exercise.
Posted at 01:25PM Apr 29, 2009 [permalink/trackback] by Henry Story in Java | Comments[6]
Note on comments:
- I know the forms below are a little small. We have asked for years for this to be changed, but I don't think it's going to happen soon. In Apple's Safari you can resize the entry box with you mouse. For people using other browsers click on this javascript link, that should allow you to resize your form.
- Comments are moderated, so they will take a little time to appear. Currently moderation means I have to read them personally. Hopefully with OpenId deployment, this will become more automated.
- HTML markup no longer works here, due to some decision made somewhere. Sorry about that.
- If you are having trouble posting, it may be that you need javascript to be enabled. I don't think javascript should be needed for submitting a form, but that's the way it is here.
- Check your comments by using the preview button...

Interesting, I 've just bought a book on scala.
What's your feed back on scala, what did you learn ?
Posted by Christian Fauré on April 29, 2009 at 03:15 PM CEST #
Scala is cool, didi you know that dannyayers.com is some scala aggregating twine?
it's here: http://scm.trialox.org/sandbox/org.trialox.sandbox.twine/
cheers,
reto
Posted by Reto Bachmann-Gmür on April 29, 2009 at 03:48 PM CEST #
Christian, I am still exploring Scala, and have not yet come to a final judgement yet. I like the way one can say a lot in little space, yet still retain the clarity of strong typing. Being able to write XML directly in the lanuage is neat. For the moment it still takes me more time to write a Scala Program than the equivalent Java one, as I am more familiar with Java. Of course I really appreciate how close Scala is to Java, for that very same reason. The pattern matching part of Scala is very helpful, though I did not use that this much here. I think there is still a lot for me to discover here...
Reto: I don't quite understand what you wrote. Are you saying dannyayers.com is a site running Scala? And how does that fit with twine? That sounds very interesting...
Posted by Henry Story on April 29, 2009 at 04:00 PM CEST #
yes what you see on dannyayers.com is the result of a scala script running on the trialox platform aggregating the RDF representation of ttp://www.twine.com/twine/1247b40gj-21j
Posted by Reto Bachmann-Gmür on April 29, 2009 at 04:27 PM CEST #
scala> "blah&blah&blah&".replace("&", "&")
res2: java.lang.String = blah&blah&blah&
Posted by James Iry on April 29, 2009 at 07:37 PM CEST #
Thanks for the hint James Iry, I checked the new version in with the simpler code:
http://is.gd/vpXP
Posted by Henry Story on April 29, 2009 at 08:37 PM CEST #