Sunday, September 23, 2007

First day at JAOO - Agile retrospectives

I'm in Aarhus, Denmark for the JAOO-conference.

For the first day of JAOO, I went to a tutorial on "Agile retrospectives" with Diana Larsen. It was a really good workshop, with a lot of exercises on different ways to gather information and deciding what to do about it.

All agile methods focuses on continuous learning (inspect-and-adapt). The only way to be better at something is to learn what you are doing wrong, and do something about it. Or as Diana put it "You could do the same thing over and over again, and hoping for a different result - But that is often called insanity".

Basics of a retrospective

Here is a short summary of what was discussed during the tutorial.














  • Set the stage
    • Working agreements, room setup, everybody's feelings ("Are we ready to start this?"), goal, agenda
  • Gather data
    • Get everybody's perspective of what really happened during the iteration/release/project etc.
  • Generate insight
    • Get a group's shared picture
  • Decide what to do
    • Prioritize and choose a few improvements that will make a difference to the team
  • Close the retrospective
    • Summarize follow-up activities, and thank team members for their hard work with the retrospective. End in good spirit, nothing bad with a little celebration.

And don't forget the follow up. It is really bad for the motivation of the team members if the result is just laying and collecting dust in a word document. somewhere.


Tuesday, September 04, 2007

Automate everything

"Don't Use Manual Procedures"

I always wanted to follow the advice "Don't Use Manual Procedures" - tip 61 in the excellent book "Pragmatic Programmer".
But I always thought that I didn't have the right tools to make it simple to automate stuff. I used to be a windows user, but was so frustrated. Even the simplest things, like zipping a bunch of files and naming them with a suffix of todays date, was really hard work using the poor "bat"-scripts.

Andreas Automation v. 0.1 (Windows/Cygwin)

So I used to use cygwin, and store small snippets of bash-scripts for my most repetitive jobs. I also did use some perl and ANT-scripting for simple automation.


Andreas Automation v. 0.2 (learning Ruby)

For about two years ago I found out about ruby, and thought that often ruby was simpler to use than shell-scripts (and perl, and definitely better than ANT for the same tasks). So I started to collect small snippets of ruby code to do my repetitive stuff.
But I could not use it to interact with my regular desktop-apps (I guess you can use some-kind of VB-scripting to do some work with Microsoft programs, but I did not want to go that way...)


Andreas Automation v. 0.3 (Learning Mac...)

This year I switched to use a Mac for work, and I saw the promise of using some-kind of blend of "Quicksilver-AppleScript" to automate stuff with my desktop apps. Quicksilver is an amazing piece of software, but after a while I found myself using it mostly for finding stuff (applications and files) fast. And I didn't really like the approach of AppleScript (I wanted the power of Ruby...). So what is the solution?


Andreas Automation v. 0.4 (July 2007...)

I have found a new way to be truly productive (At least I hope so, this approach is really new to me, and I haven't figured out what is possible yet...

So what is the solution? During the last weeks I have found out about two different ruby gems that seems to solve my problem, "RubyOSA" and "Sake".
What these two techniques combined let me do is:


  • RubyOSA: Interact with Mac applications from Ruby

  • Sake: Have a repository for categorized scripts and a simple way to use them

RubyOSA

RubyOSA is a bridge from the Ruby language to the Apple Event Manager. What that means is basically that what you can do with AppleScript you can now do with Ruby (!). RubyOSA was developed by Apple and published under the BSD-license, see RubyForge.


Super-short-tutorial

$  sudo gem install rubyosa

Create a file: "on_itunes.rb"


require 'rubygems'

require 'rbosa'

app = OSA.app('iTunes')

puts "'#{app.current_track.name}' by '#{app.current_track.artist}'"

What that let's me do is:

$  ./on_itunes.rb   

--> 'Palace & Main' by 'Kent'


To impress colleagues and friends, it is even cooler to use irb. Start by opening irb, and paste in the code from "on_itunes.rb".
Then type: app.next_track (and hear how iTunes starts playing the next song in your playlist). Did, I hear a "Wow!" ?


Changing songs in itunes from the command line is maybe not the most useful thing you can do, but it was mostly to illustrate the point.


Another example then:
Sometimes I want to work without being interrupted by emails, im-clients etc. Particularly when I am doing a presentation with a projector, or when pair-programming. What I want then is a script to just say "World - don't interrupt me now!" and expect Skype, Icq, Msn, Mail-client (whatever) to just "shut-up". So this is the start of such a script (it only interacts with Skype and Adium right now).


require 'rubygems'
require 'rbosa'

mess= ARGV[0]
skype = OSA.app('Skype')

skype.send2("SET PROFILE MOOD_TEXT #{mess}", "send script")
skype.send2("SET USERSTATUS OFFLINE", "send script")

adium = OSA.app('Adium')
adium.adium_controller.my_status_message = mess
adium.adium_controller.my_status_type = OSA::Adium::ASST::OFFLINE

For more info, see Maczealot's more complete tutorial (that's how I found out about it)





Sake

Sake is a "system-wide Rake". (If you don't know what Rake is, it's a build system for Ruby (similar to make or ANT etc.) that can be used for a lot more than builds. More info about Rake

How to install sake? Simple, just:

$  sudo gem install sake

So why would that be useful? For instance by wrapping my "on_itunes.rb" in a Rakefile like:


namespace :itunes do
desc "Displays the current chosen song in itunes"
task :current_song do

require 'rubygems'
require 'rbosa'

app = OSA.app('iTunes')
puts app.current_track.name
end

desc "Play next song in iTunes playlist"
task :go_next do

require 'rubygems'
require 'rbosa'

app = OSA.app('iTunes')
app.next_track
p "Now playing: #{app.current_track.name}"
app.play
end

end

I can now install tasks from my rake file into the "system-wide repository of useful scripts" :

$  sake -i rubyosa.rake itunes:go_next
$  sake -i rubyosa.rake itunes:current_song  
$  sake -T itunes

Displays the following:

sake itunes:current_song   # Displays the current choosen song in itunes
sake itunes:go_next # Change to next song in itunes playlist (and play it)

What's next?

One thing I really like to automate is blog posts, like this one, with code examples that I like to be syntax highlighted.
So this post is done using a plain text markdown-file. With a few lines of ruby code I first identify code-fragments, then syntax highlight those rows using the excellent ultraviolet-gem which highlight files based on TextMate-themes, and then the whole markdown-file is transformed using the normal "bluecloth"- API.


To create this post I did:

$  sake blogger:preview automate_everything.markdown 

I still have to log in to blogger and paste the html created, so this is not good enough...
I'm working on the "sake blogger:post"-command that will use the blogger REST-API to add blog posts.

To be continued... (Andreas Automation v. 0.5...)

Thursday, August 23, 2007

Geeky running

For a while (years...) I have been trying to activate myself.

This year I have registered for the "lidingöloppet" (30 km running in terrain). But how will I motivate myself to train for that?

Well, I found a nice formula:

  1. Buy a new toy (eh...I mean training equipment, e.g. a watch that can record speed, distance, heart rate etc.)!
  1. Feel guilty about not training when you have bought such a nice device!
  1. Force yourself to go out running (you have to record data, to have anything to analyze, remember...)
  1. Go home,connect the watch to the computer, and start analyze your running
  1. Start over again...

I have had various more or less advanced training watches (from Polar and Suunto) but this summer I found my ultimate training companion, "Garmin Forerunner 305". It is a wristwatch equipped with a GPS-receiver. With this watch I can go out running, then go home, attach the watch to the computer via USB, and immediately watch my whole run on google maps, together with heart rate, distance, speed, elevation etc. Really cool!

There are a lot of different programs out there to upload the GPS-data and let you analyze it. I have tried out a few of them.

  • Garmin Training Center (the included program) - basic, pretty crappy...

  • Motionbased.com - Web application, really simple to upload data from device and nice interface to analyze data, and share a URL to your run. (I think Garmin bought motionbased.com). There is one version that costs about $100/year, and another more limited, free version (I just realized that the free version only lets you store your latest 10 activities)

When using Windows I had some bad experience with the PC didn't find my device and I had to uninstall/install the USB-driver, and the good-old "restart the computer"-action to find it again. But that is not really a problem for me because I much rather use my Mac.

When I am using a Mac there are two good Open Source applications I use.


  • LoadMyTracks (Simple app that just connects to your watch and download the GPS-log and store it in GPX-format (XML), or KLM-format if you want) - not even a single time I have had any problems with "finding the device"

  • TrackRunner - a desktop app that lets you view your run on a map together with training data. It is a bit buggy, but you get an overview over all your runs, and can do basic analysis and what the runs on a map.

  • Also, motionbased.com are focusing on getting their tools to work for Mac, and the latest beta works to upload your tracks from the device if you are using safari (not firefox yet) with a plugin.

I really love my Garmin Forerunner, I just tried the "virtual partner" function, which means that you can either use an old GPS-log in the watch or download GPS-data to the watch. Then you can compete against your (or somebody else's) old run, and at every moment you can see on the watch how many seconds/meters you are before/after your partner. Because you are running the same way as a previous course you can even view the elevation.
I even tried to fool the watch by running a slightly different way - and got an "off course" message, then when I went back the same way I got a "course found" message, and my virtual partner was starting to catch up with me again...

As an example of what data you can get from the watch, look at "midnattsloppet" (based on the GPS log from my watch, from a 10km race in Stockholm the last weekend)

The latest cool thing I found out about is the facebook application "MyMotionbased" that shows the five latest runs on motionbased in facebook.

To conclude, Garmin Forerunner is really an amazing training partner which gives me motivation to go out running and I hope it will help me finish "lidingöloppet" the 29th of September...



Thursday, June 14, 2007

Code syntax highlighting on blogspot

For my last post I wanted to get syntax highlighting for my code examples. That was not as easy as I had hoped!
(I think I spent more time trying to fix that than I spent on examining the activeresource-API...)

Anyway I tried a lot to get SyntaxHighlighter to work. But I did not succeed.
What I did end up doing instead was to follow the advice from QuirkeyBlog and use the TextMate Bundle's "Create css from theme" and "Create HTML" from theme. I'm pretty pleased with the result that is visible on screen, but it demanded a lot of copy-pasting of html-code. I have to automate that process for next "code-example-post". If anybody out there have a better idea of how to get syntax highlighting to work on blogger, please tell me.

Wednesday, June 06, 2007

What is a RESTful application?

In the Rails community (and elsewhere) there is a lot of talk about "RESTful applications". But there is a lot of questions of what is really meant by REST. IMHO the most characteristic and interesting parts of REST is:

  • Everything is a resource, uniquely addressable using a URI.
  • There are a few well-defined operations to view and change state of a resource
For Rails, the REST-buzz started with David's keynote at RailsConf last year and the "RESTful" controllers/routing was part of Rails 1.2, where it is very easy to create a webapp with "RESTful" characteristics (the new routing etc.). The client side of the RESTful interface, Active Resource, was not part of rails 1.2 but now can be easily used anyway. I come back to how soon...

Maybe the easiest way to create a RESTful application in rails is using the "scaffold_resource" generator (since rails 1.2).

Example "service":
$ ./script/generate scaffold_resource result match_date:date home_team:string\
away_team:string home_score:integer away_score:integer
$ rake db:migrate
$ ./script/server

Apart from giving a web application that can be used right away this also gives a REST-service that can be used with for example curl. When at least one item has been added with the scaffold web app, it can look like the following.
$ curl http://localhost:3000/results/1.xml

<?xml version="1.0" encoding="UTF-8"?>
<result>
<away-score type="integer">0</away-score>
<away-team>Denmark</away-team>
<home-score type="integer">3</home-score>
<home-team>Sweden</home-team>
<id type="integer">1</id>
<match-date type="date">2007-06-02</match-date>
</result>


Ok, that's fine. There is a lot of stuff that we get for free when using scaffold_resource. But how can we have a little more sophisticated client than curl?
Here comes the fun part. As I said above, ActiveResource was not part of Rails 1.2, but we don't even need to run edge-rails to run it now. It has been released as a gem and can be easily downloaded and installed, see Ryan's post for more info.
  • sudo gem install activeresource --source http://gems.rubyonrails.org
If the activeresource gem is installed we only need a couple lines of ruby code to access and make changes to resources. We don't even need rails, a small ruby-client will do.

require 'rubygems' 
require 'active_resource'

class Result < ActiveResource::Base
self.site = "http://localhost:3000/"
end

result = Result.find(1)
p result.home_team



This will access my REST-service and print out the home team of the resource "results/1" => Sweden.

The really cool use of activeresource comes when I want to create a new record. When I add to my following code example:

Result.create :home_team=>"Sweden", :away_team=>"Iceland", :home_score=>5, :away_score=>0, :match_date=>Time.now


It creates a new entry in my railsapp, that instantly can be accessed by activeresource or in a browser with
http://localhost:3000/results/2

I think it is pretty amazing that you in just a few lines of ruby code can create both a REST-service and client. The next step for me will be to test how activeresource and REST might work for a larger application. How about error handling? Using other clients than Ruby towards my REST-service (like a Java-client)? Can I throw out my SOAP-solutions now? (say yes!)...

Thursday, May 24, 2007

Deploying Rails to tomcat just works...

So, RailsConf 2007 is over, and I am back in Sweden again.
A lot of people in the blogosphere has summarized the different talks at RailsConf, so I won't do that right now.

For me, one of the best experiences from RailsConf is JRuby. I went to the tutorial "Your First Day with JRuby on Rails" on Thursday.
Ola Bini has continuously told us in the Rails community in Stockholm about the development of JRuby. But still, I was impressed of how easy you can turn a regular railsapp into a self-contained war-file running in an appserver, and using ActiveRecord JDBC. This is done with the goldspike-plugin on rubyforge.

Ok, so after the tutorial, I knew the theory, but does it really work for a real application?
Let's checkout!
I used a normal rails-app we use internally at my company.

Recipe
Here is a quick recipe for what I did to make it work:
(The assumption is that there is already a functioning railsapp using mysql on the computer, and that Java and ant, and tomcat is also installed.)

1. Install JRUBY (You can download a binary, or install it from source as is described here)
$ svn co svn://svn.codehaus.org/jruby/trunk/jruby
$ ant test
Add jruby to path:
$ export JRUBY_HOME =/Users/andreas/dev/jruby
$ export PATH=$PATH:$JRUBY_HOME/bin

2. $ cd "your-existing-railsapp-dir"

3. $ jruby script/plugin install svn://rubyforge.org/var/svn/jruby-extras/trunk/rails-integration/plugins/goldspike

4. Add support for mysql-jdbc:
Add to config/environments.rb:
require 'jdbc_adapter'

Add a new file config/war.rb with the following content:

maven_library 'mysql', 'mysql-connector-java', '5.0.5'

Add the following to each environment-description in config/database.yml :
adapter: jdbc
url: jdbc:mysql://localhost/blp_development
driver: com.mysql.jdbc.Driver


5. $ rake war:standalone:create
This will create a war file including a lot of java libraries (The jar-files that are needed are collected from maven repositories, including the mysql JDBC-driver specified in war.rb)

5. $ cp appname.war /opt/local/apache-tomcat-5.5.23/webapps/ (or wherever your tomcat is installed)

6. http://localhost:8080/blp

Voila, it works the same as the normal railsapp would, running in mongrel.
There is still some issue with static content, like css, but I am sure it will probably get fixed real soon. I haven't got any feeling of performance (it seems a bit slower then running it in mongrel), and other problems yet. But I am sure that backed up by Sun etc., the JRuby team will put a lot of energy in that (if it is an issue).

So why?
So, it works, but why would you use JRuby instead of standard c-ruby for railsapps?
Well, many customers I have shown small railsapps for has been impressed by the productivity boosts and how easy you can do things. But then they say "We can not have rails in our production environment, we are a Java shop".
My friend Peter has written a blog post that I think summarize "the why" pretty well.

The benefits of Jruby

  • Can use existing deployment environment in an organisation (if any, like Weblogic, jboss...)
  • Can use all existing Java-libraries out there from your railsapp...
Cons
  • Can not use native-c plugins , like ferret, rmagick... (This might be a problem if there are no alternative Java-libraries)

So, I look forward to see how this will effect the Rails-deployment strategies, rails adoption etc...

Thursday, May 10, 2007

RailsConf, here I come!

I am really excited of going to RailsConf next week.
It hasn't been much rails coding recently (because I am involved 100% i a Java project), but I started to play with the RESTful stuff the other day, and it is really cool, and the scaffold_resource generator lets you get started in seconds. More to come on that topic, when I have the time...

With Dr. Nic's good app myconfplan, I publish my preliminary conference schedule

Look forward for some posts on various aspects from RailsConf (I know I have atleast 5 readers out there ;-) !