Rock the PyCharm?

I think I’ll always prefer a plain text editor and the command line for my computing work. Maybe it’s because I was introduced to computing on a VT-320 terminal connected to a VAX? Maybe I’ll never know. I just feel more comfortable with plain text and the power that the command line provides. A lot of folks prefer to write code in an IDE. Syntax highlighting, intellisense, integrated debugging, etc. There are a lot of reasons that IDEs are so popular among developers. Some IDEs even have their own followings like a NFL team or a religion. One thing I’ve learned over the last few years is that a programming language can really benefit from a high quality IDE (or 10). By having a great IDE available, more people will likely be pulled into the language to use it for their next big app/script/widget. I’m excited to see JetBrains working on PyCharm. It’s not because I like their Java IDE or that I like their work over the others (Netbeans, WingIDE, PyDev, etc.) I’m excited because Python is getting more IDE love. That’s a great thing! If you’re looking for a Python IDE, check out PyCharm. If you really want to ‘Develop with Pleasure’, code your next app/script/widget in Python!

Rocking mercurial on a Cloud Server

I’ve been using Rackspace cloud servers for a couple of months now. I’ve been very pleased with their 256MB Cloud Server. At 1.5ยข/hr, it’s a great place to test out new ideas without needing to come up with a chunk of cash up front. You might also be surprised at how much computing you can get out of a single 256MB Cloud Server. I’ve been using a 256MB Cloud Server (running Ubuntu) to host this blog and a site for my wife. They get a modest amount of traffic, so I’ve been looking for other ways to maximize my utilization of that Cloud Server. I’ve started tracking all of my personal projects (even my resume and other text documents) with mercurial. These mercurial repositories have been living on my mac mini. This works fine since I’m really the only person using them.
However, I’d like for these projects to be backed up offsite. I’d also like to easily be able to work on these projects when I switch between machines. To accomplish this, I moved my personal mercurial repositories to this 256MB cloud server. Here’s what I did to get that working:

First off, I’m using key-based ssh login.
You can read more about it here. Combining the key-based login with a proper ~/.ssh/config like:

Host myssh_alias 
   HostName myhostname_or_IP 
   IdentityFile /Users/myusername/.ssh/mykeyname
   PasswordAuthentication no
   Port 22 
   User myusername

makes getting to your machine as easy as:

ssh myssh_alias

and with no username/password to remember.
(Rock the short command line!) I point this out since I’ll be using ssh to access my mercurial repositories on the cloud server.

Next up, install mercurial on the cloud server:

sudo apt-get install mercurial

To make backing up my repositories to cloud files (or S3…or wherever) easy, I also installed duplicity (and python-cloudfiles for cloud file access):

sudo apt-get install git-core
git clone git://github.com/rackspace/python-cloudfiles.git
cd python-cloudfiles
sudo python setup.py install 

sudo apt-get install duplicity

With the necessary components now in place, I scp’ed my mercurial repositories to my cloud server. Something like this:

tar jcf myhgrepo1.tar.bz2 myhgrepo1
scp myhgrepo1.tar.bz2 myssh_alias:/repos/myhgrepo1.tar.bz2
ssh myssh_alias
cd /repos
tar jxvf myhgrepo1.tar.bz2

I put all of the repositories in /repos on the cloud server.
If you don’t put them in your home directory, you’ll need to make sure to include an extra ‘/’ in the URL when using hg clone.
Like this:

hg clone ssh://myssh_alias//repos/myhgrepo1

If you put your repositories in your home directory, that command would look like:

hg clone ssh://myssh_alias/repos/myhgrepo1

With all of my repositories on the server now, I setup a cron job to back up the repos to cloud files using duplicity. Something like this shell script should work:

#!/bin/bash
UPLOAD_TO_CONTAINER="name_of_cloud_files_container" 
export CLOUDFILES_USERNAME=cloudfiles_username
export CLOUDFILES_APIKEY=cloudfiles_api_key
export PASSPHRASE=password_for_backup

/usr/bin/duplicity /repos cf+http://${UPLOAD_TO_CONTAINER}

(Thanks to Chmouel Blog for the tips on rsync like backup with duplicity.) Now, you’ve got a central place for your personal mercurial repositories that includes periodic backup.

If you’re looking for a new computing toy (that’s not really a toy) and don’t want to drop bling on an iPad or (insert the name of the product you’re currently drooling over), a cloud server is a really cool (and useful) thing.

Rock the Mock

I spent a lot of time scratching my head at work this week as I looked at a java project’s maven build output:

Tests run: 1457, Failures: 0, Errors: 1, Skipped: 0
[INFO] ----------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ----------------------------------------------------------------
[INFO] There are test failures.
[INFO] ----------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ----------------------------------------------------------------
[INFO] Total time: 51 seconds

When I first encountered this, I suspected that I had broken a test with some new code I had been working on. I opened up the test that was being flagged with an error and, to my surprise, it ran fine when I ran it individually. I ran it from the command line with maven and also from within my IDE. By itself, it ran without error.
Each time I ran the full unit test suite, it failed with the same error:

java.lang.IllegalStateException: 0 matchers expected, 2 recorded.
    at org.easymock...

This further confused me because the line it was failing on was the equivalent of this:

expect(mymock.getValue()).andReturn(anotherMock).anyTimes();

I wasn’t using any matchers on this line. Since the test worked by itself, I started to suspect that one of the other tests was somehow polluting the test environment.
This project uses the “fork once” option to run the test suite. So, all of the tests are executing in the same JVM. As a quick sanity check, I changed the pom.xml file to “fork always” (new JVM for each test class). When I ran with this configuration, all of the tests passed (it just took a LOT longer):

[INFO] ----------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ----------------------------------------------------------------
[INFO] Total time: 20 minutes 49 seconds

So, now to track down the test or tests that are causing the unit test suite to fail. (While the “fork always” worked, I didn’t want to leave it at that and wait 21 minutes for each round of unit tests!) Unfortunately, we don’t have the tests running as part of our continuous integration builds (yet). So, I just started rocking svn log with a date range to look for recent changes that touched tests executing prior to the test in error.
Finally, I ran across a class that had something like this in it:

expect(obj.execute(isA(Action.class))).andAnswer(new IAnswer<Object>(){
        public Object answer() throws Throwable {
            .
            .
            .
            .
            return EasyMock.anyObject();
        }
}).anyTimes();

At first glance, I didn’t see anything wrong. But then I started looking more closely at EasyMock.anyObject() after googling around for “N matchers expected, M recorded.” There were several sections like this in one of the test classes. All of them had a

return EasyMock.anyObject();

line. Since anyObject() is an argument matcher, I didn’t think it needed to be returned by our mocked object. In this case, I was able to simply replace

return EasyMock.anyObject();

with

return null;

After doing this, the test suite started running successfully.
Rocking the EasyMock.anyObject() outside of the normal argument matcher scenario really hijacked the test suite.

Closing Thoughts

Obviously, we need to get this project’s tests running as part of the continuous integration process. Not doing so costs us time, broken tests, and a lot of head scratching.
I believe mock objects can be a very valuable component of every project’s test suite.
If you’re not using them in your project, please don’t let this post stop you from doing so. For every mock slip up we’ve had, we’ve had a ton of bugs caught by unit tests using mock objects. Just be careful if you start throwing around anyObject()!

Rock the Mock

Rock the Command Line: Install packages on OS X

Today I had a need to install a new version of python on a Mac via ssh. Just like using graphical installers on OS X, installing from the command line is remarkably easy. (I think it’s even easier. I’ll be rocking the command line even more now!) You’ll typically pull down a dmg with the software you want to install. In this case, I downloaded Python 2.6.4 using curl:

curl -o python2.6.4.dmg \
     http://www.python.org/ftp/python/2.6.4/python-2.6.4_macosx10.3.dmg

Now, I can mount the disk image:

hdid python2.6.4.dmg

hdid can also mount disk images over http if you want to combine those two steps:

hdid http://www.python.org/ftp/python/2.6.4/python-2.6.4_macosx10.3.dmg

With the disk image mounted, you can now rock the install using installer:

sudo installer -pkg /Volumes/Python\ 2.6.4/Python.mpkg -target /

Check out the installer man page for more information.

Rock the command line!

Rock 2010

I’ve decided that I need to broadcast some goals for 2010.
In the past, I’ve had a lot of ideas for projects that I wanted to work on and I’ve not followed through with them. In 2010, I’m making it known what I want to accomplish. If I don’t come through with these things, I want you to call me out on it. (I think I could use some public peer pressure to get some of this going.)

Contribute to Open Source Projects

I’ve been using and benefiting from open source software a lot over the past decade. I’ve not given back to the community. I plan to change that in 2010.
I’ve selected a couple of open source projects that I’m going to contribute to in 2010:

Ajellito

We’re moving to Agile development methodologies at work. I want to help ensure that there are high quality tools available for people that are managing Agile projects. Ajellito uses django and python (so it has to be dominant, right?!?!). If you don’t see me contributing to Ajellito in 2010, call me out on it!

feedparser

In 2009, I did a lot of screen scraping and feed parsing.
This is so easy in python. A lot of that comes from good libraries like feedparser. They’ve recently restarted development on it and I want to help them close out open issues. If you don’t see me contributing to feedparser (in some way) in 2010, call me out on it!

Publish a couple of iPhone Apps

I’ve spent some time in 2009 working on a couple of app ideas. I want to bring those ideas to the AppStore in 2010.
(The first app I developed for the iPhone OS is now on the AppStore: icyou Health Video. I did this project for my employer. It’s a free download. Check it out!)

iRocKnots

This is the app that has been rolling around in the back of my head since the iPhone debuted. (Yet I have nothing in the AppStore to show for it…) My tie collection doesn’t grow fast enough to provide new fat knots each week. I plan to empower the people in 2010 to document their knots in real time. Dressed up for an important business meeting, church event, wedding, special occasion, or just a regular work day… post your neck wear on irocknots.com! If irocknots.com is not online or you don’t see iRocKnots in the AppStore in the first quarter of 2010, call me out on it!

RxGadget

For the last six months or so, I’ve been managing my father’s medication. Dad needed help keeping track of his meds, so he started using the MedReady timer.
This device has been great for him. It secures his medication and it ensures that he’s reminded to take the appropriate meds at the appropriate time. If he misses a dose, the tray prevents him from double dosing. RxGadget is an iPhone app that will provide caregivers with a powerful tool for tracking medications for their loved ones/patients. If you don’t see RxGadget in the AppStore by the second quarter of 2010, call me out on it!

Python

I want to get more involved with the python programming community in general. I’ll be attending PyCon 2010 in February. I’ll be looking for ways to get more involved at that conference. I’m specifically looking to promote python’s use more in South Carolina.

Blog and Tweet more

My blog was rarely updated in 2009. In 2010, I want to write more. Looking back over the last year, there’s a lot of stuff I come across each day that could benefit others. If I write it down, it might help someone and it might help me to remember it.
If I’m not blogging a couple of times a week and tweeting daily, call me out on it!

Happy New Year!!!

Rock the Fat Knot in 2010.

Merc Rocks a Fat Knot

Merc Rocks a Fat Knot

Robert Mercorelli sent me this image of him rocking a fat knot. Merc travels a lot and interacts with a lot of clients in important meetings. His years of experience have taught him that rocking the fat knot is the way to go. Good work, Merc! Just try not to impress too many people at once. I’d like to sleep a couple of hours next week!

One of Westall’s Laws

While cleaning up around the house today, I ran across some notes from grad school. I took a networking course from Mike Westall while I was at Clemson. I never took that many notes (probably should have) but I ran across a piece of paper where I had written this:

Westall’s Law

for any theory there exists a workload that will prove it correct and other theories wrong
I thought Westall was the man back then. A true hard core computer scientist. After almost a decade in industry, that quote reminds me that he’s still the man.

5-3-2009 Fat Knot

SANY0009.JPG

Today’s my brother’s birthday. So, it’s fitting that I wrap up the series of “Birthday Fat Knots” with this post. I really like this tie. Combined with the poplin suit, it’s a dominant fat knot.

4-26-2009 Fat Knot

SANY0007.JPG

Another tie from my birthday!

4-19-2009 Fat Knot

SANY0001.JPG

My wife got me some ties for my birthday. I’ll be rocking them over the next few weeks. Here’s the first in the series…