Learning to Run

November 17, 2011 at 07:13 PM | categories: running | View Comments

Two and a half years ago I found myself overweight and out of energy. I decided it was time to lose the extra weight. With the help of The Hacker's Diet I spent the next six months getting to an acceptable weight. Life was great; my weight problem was solved and I felt like I had more energy.

But there was still a problem: I wasn't really in shape and I really had to watch how much I ate so that the weight wouldn't come back. Sitting at a desk all day for work wasn't helping my fitness at all. This spring I decided that I could definitely fix the getting into shape part. I looked at a lot of different possible activities and finally decided that running would be best for me. The deciding factor was that I could run in any weather and anywhere.

Now for the specifics. When I was looking for a way to get started it was helpful to see other specific success stories. So, in that vein, I'll stop short of recommending this program, but I will say that it worked for me.

When I started in May, I could run for about three minutes. After that it was extremely hard to breathe and I hurt everywhere. I set what I thought was a fairly reasonable goal: run a 5K in under 30 minutes by the end of the summer. To add a little motivation, I picked a race and registered.

Knowing nothing about running, I needed a program I could follow. I noticed quite a few other programmers talking about Couch to 5K on Twitter and decided that was as good a start as any. I'm terrible with a watch and too cheap to buy an app to keep track of the intervals for the program so I was really happy to stumble onto Podrunner: Intervals. I loaded up my MP3 player and started running. After five weeks, I'd burned through my cheap tennis shoes and visited the local running store for a pair of running shoes. I'd like to say that I was able to follow the Couch to 5K program without a problem, but it didn't work out that way. I finished week six with a 22 minute run and didn't, but it didn't feel good at all. I backed off to doing 10 minute intervals with a 90 second walk in between and then adding a minute to the running portions for each run. Since I was no longer on the Couch to 5K program, the Podrunner podcasts weren't as helpful so I tried out audiobooks. After doing fifteen minute intervals for a week I found that I could pretty reliably run for 20 minutes without stopping. The two weeks before my first race I struggled to run for more than 20 minutes.

My sister agreed to run that first race with me. I showed up early feeling poorly prepared. To make things more interesting I decided to run with music. We started the race together and quickly found someone running a pace we thought we could keep up. Just a little less than 30 minutes later I crossed the finish line. First goal accomplished.

I set a goal to run my next 5K in less than 27 minutes and registered for a 5K three weeks after the first one. My runs during that prep time finally started to feel good and I found myself easily running for 30 minutes. I also started using CardioTrainer to track distance and time for all my runs. It's a lot of fun to be able to see that map after a run and see just how far you've come. The three weeks passed and I finished the race in a little under 25 minutes. All the real runners can laugh at how slow that is, but I was pretty excited.

At that point, I wasn't sure how much time I could trim off the 5K, but I was pretty sure that I could add some distance. My next goal was to finish a 10K, hopefully in under 60 minutes. I spent the next month adding 1km to my runs each week. Unfortunately, right about the time I got up to 9km, I got sick. Two weeks later I felt better, but I had a hard time running even 3km and had to start building up again. I had registered for a 10K, but I was really worried because I only got back up to 7km on my regular workouts before race day.

It rained on race day, but at least it wasn't too cold. I started the race too fast, then had to talk myself out of quitting during the 3km. Around the 4km mark, I started to feel really good. Goal accomplished: I ran the entire race and finished in 51 minutes.

Next up on my list is a 10K in under 50 minutes next spring and finishing a half marathon next summer. It's taken a lot of work to get to this point, but I'm really happy about it.

Scala as a Java REPL

November 08, 2011 at 09:10 PM | categories: programming, scala | View Comments

After years of Python programming, I've been spoiled by always having a REPL available when I want to test something out. As I spend more and more time in Java, I find myself missing a REPL. Well, no more. I'm happy to report that I've finally found a REPL I like using to test out libraries when I'm working in Java: the Scala REPL.

Today I needed to send some JMS messages to ActiveMQ. Instead of firing up eclipse, creating a maven project to get the dependencies, and then writing some Java code, I used sbt and Scala to create a REPL where I could easily send JMS messages.

Create an sbt project

The first step is to create an sbt project. This is as simple as creating a directory with a build.sbt file in it. My example build.sbt file pulls in two library dependencies that I want to have available in the REPL.

name := "jmstest"

scalaVersion := "2.9.1"

libraryDependencies ++= Seq(
  "org.apache.activemq" % "activemq-core" % "5.5.1",
  "org.slf4j" % "slf4j-simple" % "1.6.4"

Run the REPL

Running the REPL is as simple as running sbt console from the newly created sbt project. From there, it's off to the races:

import javax.jms._
import org.apache.activemq.ActiveMQConnectionFactory

val factory = new ActiveMQConnectionFactory("tcp://localhost:61616")
val connection = factory.createConnection
val session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE)
val destination = session.createTopic("jms.test")
val producer = session.createProducer(destination)

val message = session.createMapMessage
message.setString("command", "basic_setup")
message.setBoolean("do_stuff", false)

That's all there is to it. Scala, with the help of sbt, makes a great REPL for testing out Java libraries.