Twitter Status Script for Scala

Posted by rob on April 23, 2009

I’ve been playing with Scala a bit lately. Tonight, I was fooling around with Scala using an online, interactive shell called lotrepls. I decided to write a script that would call the Twitter API and return me the status for a Twitter user. The script takes a Twitter user name as input and prints that user’s status to the screen. It turns out that Scala has some built-in XML parsing capabilities that makes this really easy.

This is the script.

import java.net._
import scala.xml._
val screenName = "robbr"
val url =
  new URL("http://twitter.com/users/show.xml?screen_name=" +
  screenName)
val conn = url.openConnection
val twitterXml = XML.load(conn.getInputStream)
val twitterStatus = (twitterXml\"status"\"text").text
println(screenName + ": " + twitterStatus)

I’ll quickly break down the script line by line for non-Scala people. Not that I’m a Scala export myself.

  1. Scala is compatible with Java. Scala can call Java and Java can call Scala. In the first line, I am importing all classes in the java.net package to use for making a HTTP request later in the script.
  2. In the second line I am importing all classes in the Scala XML package.
  3. I set the screen name which is input to the Twitter status API call. I could instead prompt the user for the screen name using Console.readline(), but this doesn’t work with lotrepls.
  4. Set the URL for the Twitter status API.
  5. Open a URL connection.
  6. Load the XML output of the HTTP request into a variable. The “val” modifier makes the variable final, therefore it can’t be changed.
  7. Finally, in the last statement, I use an XPath like statement to navigate the XML for the data element I am looking for. I get only the text of that element.
  8. Output the screen name and Twitter status to the screen.

This script can simply be cut and pasted into lotrepls. Remember to switch to Scala before running the script. Use CTRL+ENTER to execute. That’s all there is to it. Enjoy.

Larry Ellison’s Cloud Computing Comments Revisited

Posted by rob on April 21, 2009

Back on September 26, 2008, Larry Ellison (CEO Oracle) made the following comments about cloud computing. Larry was quoted by the Wall Street Journal as saying…

“The interesting thing about cloud computing is that we’ve redefined cloud computing to include everything that we already do. I can’t think of anything that isn’t cloud computing with all of these announcements. The computer industry is the only industry that is more fashion-driven than women’s fashion. Maybe I’m an idiot, but I have no idea what anyone is talking about. What is it? It’s complete gibberish. It’s insane. When is this idiocy going to stop?

“We’ll make cloud computing announcements. I’m not going to fight this thing. But I don’t understand what we would do differently in the light of cloud computing other than change the wording of some of our ads. That’s my view.”

With the announcement yesterday that Oracle is buying Sun, it will be interesting to see what this means for Sun’s cloud computing technology.

The rant against cloud computing was well covered at the time, but I couldn’t help but to think about it again in light of yesterday’s big news. Actually, my favorite part of the quote is that part about software being like woman’s fashion. So true sometimes.

End of An Era

Posted by rob on April 20, 2009

Sun agrees to be acquired by Oracle. This is huge news in so many ways. Oracle will own MySQL, the most widely used open source, relational database. They will now own OpenOffice/StarOffice, a competitor to Microsoft Office. Oracle acquired BEA last year, so acquiring Sun makes that acquisition all the more interesting. And Sun owns some up the best cloud computing technology out there. Hmmm, I can only begin to think about what this does to the software landscape.

Oracle to Buy Sun

Toodle-Li-Do, Toodle-Li-Dum

Posted by rob on April 08, 2009

I have finally found a satisfying to-do list solution for my iPod Touch. Its called ToodleDo. For $3.99 ToodleDo has an iPhone/Touch application that can sync up to a ToodleDo basic (free!) Web account. I’ve been looking for this since I got my Touch over a year ago.

Java Support Added To Google App engine

Posted by rob on April 08, 2009

In what is great news for the Java community, Google has added support for Java to the Google App Engine.

Google adding Java support to App Engine

Time For An Update

Posted by rob on March 08, 2009

My last post was on December 31 of last year. I know everyone is waiting on pins and needles for my first post of 2009. I’ve been very busy with work and life as well as suffering a writers block, so I thought to get things going again I’d post an update of what I have been up to.

  • I’m now managing a software group at IEI. I’m also still writing code. Balancing both responsibilities will be an exciting challenge for me this year.
  • Java is the primary technology and language I develop software in. The new language I am focusing on is Python. I already written a number of things in Python, but still have a long ways to go in mastering the language.
  • I didn’t get a chance to attend No Fluff, Just Stuff in St. Louis this weekend. Last year’s was very good, so this is a bit of a disappointment.
  • I’ve attended a couple of the Lambda Lounge meetings, so far this year. This is an exciting user group focused on functional and dynamic languages.
  • I went skiing in Breckenridge a couple of weeks ago. The weather and the snow were both great. It rocked.

Five Predictions for 2009

Posted by rob on December 31, 2008

Drum roll please… Here are my five technology predictions for 2009.

  • Google will buy Twitter.
  • Sun Microsystems will be purchased by one of the following companies - IBM, Google, Oracle or Microsoft. Sun’s current market cap is $2.8 billion. Update 2009-04-20  Sun agrees to be purchased by Oracle. http://tinyurl.com/c85lfw
  • IT departments will hunker down due to the depressed economy. Java, .Net, Oracle and SAP will remain entrenched as the dominant enterprise technologies until the recession if over.
  • Yahoo will be acquired by Microsoft. With Jerry Yang out, the battle of egos is over.
  • Google Android, Amazon and Mozilla Songbird will force Apple to rethink its music download business model. Update 2009-01-13 Apple is going DRM free. http://news.cnet.com/drm-free-itunes-store-to-haunt-apple/

JEval 0.9.4

Posted by rob on December 30, 2008

I couldn’t finish the year without writing one last post about JEval. A new maintenance release is available. For whatever reason JEval’s download rate had more than doubled over the last couple of months. The number of downloads has now exceeded 1500.

‘Tis the Season for a Great Quote

Posted by rob on December 24, 2008

Einstein has so many great quotes. Almost as many as Yogi Berra. This one I just discovered the other day and I think it fits in perfectly with the Christmas season.

“There are two ways to live your life - one is as though nothing is a
miracle, the other is as though everything is a miracle.”

Enjoy the miracle. Merry Christmas everyone.

The Easy Way to Select a Java Web Framework

Posted by rob on December 11, 2008

Sorry for the delayed post. Things have been very busy lately. Besides, I just don’t get around to writing as many blog articles now that I use social networking applications like Twitter and Facebook.

The most difficult part of writing this article was getting started. I didn’t want this article to be another taxonomy of Java web frameworks like my original article. Instead, I wanted this article to present a pragmatic way to select a framework that is easy and matches the things that you and your team find valuable to software development.  Let’s get started.

Instead of looking at the numerous features of web frameworks, I’m instead going to focus on three high level categories. They are “safe choice”, “cutting edge” and “rich user interface”.

Safe Choice
If you work for an enterprise where going with the tried and true is looked upon more favorably than taking a risk on something new, then you fall in to the “safe choice” category. Another motivation for going “safe” is that you want a standard set of Java and web technologies to work with. Since JSF is a Java specification, many of the major JSF implementations will work here. If you go down the JSF path you will most likely end up looking at JBoss Seam to work as a middleware solution for your JSF front end. There are a lot of folks out there that do not like JSF. If that is the case then your best choices are Spring MVC and Struts2. With Spring MVC you will most likely also be looking at using the Spring Framework and Spring Web Flow for your middleware. The Spring suite of software libraries is immensely popular these days and their penetration into the enterprise has been immense. Struts2 is for those who feel like it is the best migration path for existing Struts applications. Remember that Struts2 isn’t really a Struts upgrade. It is actually the wonderful WebWork framework that has been refactored, renamed and adopted by The Apache Software Foundation to be to the formal replacement for Struts.

Cutting Edge
If you work in an environment where management is more tolerant of trying new technologies, you are on a team that has a ton of Java web experience or you are simply excited by trying new things, then selecting a “cutting edge” framework may be for you. Without going too much into these frameworks, I will simply list out some of the popular frameworks that fall into this category. They are: Tapestry, Stripes, Wicket, Ruby on Rails on JRuby and Grails. These framework are either not adopted to the extent that the “safe choice” frameworks are, or they employ the use of dynamic languages. An interesting choice in this category is Grails, because it is written on top of Spring MVC, which is a “safe choice” framework.

Rich User Interface
Do you need a rich user interface instead of a more standard HTML one? Do you want a full AJAX interface instead of one with small amounts of AJAX mixed in? Only you will be able to answer these kinds of questions based on your business and technical requirements. If you answer “yes” to either question, then you are in what I consider the be the “rich user interface” category. And by definition if you want a rich user interface, then you have already left “safe choice” category. I don’t have as much experience in this category, so I will tread lightly. Choices in this category include Google Web Toolkit, Echo, ICEFaces (also a JSF implementation) and the new JavaFX.

Conclusion
There are countless choice, but selecting a Java web framework doesn’t have to be hard. You just need to know your environment and values that are important to you. Not making a choice at all will make selecting a framework hard, so don’t let this decision take too long. Regardless of what Java web framework you end up selecting, the days of using only one framework is a thing of the past. If your selection isn’t working out or if you think some other framework is a better choice for another application, then by all means select a different framework. Good luck.