All articles, tagged with “computing”

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.

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.

Rocking Python in Netbeans

I’m a hard core vi user. You just can’t beat it for a quick file edit. (This is where my friend, Jack Lunn, would argue that Emacs is better… but I think we can agree that both are faster to crank up than most IDEs.) Recently, I’ve switched to Netbeans for Java development at work. I had been using IntelliJ and it almost drove me insane. (See my post about the Corrupted Cache.) Netbeans has been working well for me, though. (It’s no vi, but it does have features that are very useful when working with large projects.) With Netbeans 6.5, you can get Python support. I’ve been using this for a few weeks now. It’s nice to have all of my Java/Python code open in one IDE. This morning, I ran across a screencast showing some upcoming code coverage support for Python in Netbeans. This looks impressive.

Rocking ZFS: Recovering from a pkg install gone wrong

I’ve been using OpenSolaris 2008.05 at work since it was made available. I use it as my primary OS on my work laptop (an HP Compaq 6910p My wife refers to this laptop as “the ugliest laptop in the world.” Compared with the Apple products she’s used to working on, the HP is not very attractive.) From the beginning, I’ve had issues installing/updating packages with the new IPS packaging system. I’m not dissing IPS. I just ran into a lot of issues trying to run pkg install and pkg image-update. Other people have reported similar issues with timeouts and such. Anyway, in a recent attempt to update my version of pkg, I managed to hose up my system. Having so much trouble at the command line with pkg, I decided to try out the Package Manager GUI. It allowed me to just select the latest version of pkg and install it. Everything processed successfully. I was excited! I closed the Package Manager GUI and went to the command line to try out my new and improved version of pkg. It didn’t work. Even worse, I started having issues with ls and every other command I tried. Core dumps were running wild on “the ugliest laptop in the world.” From another machine, I went to google and started searching to see if other people had encountered similar issues. I found one post that lead me to believe I had “updated too much.” I couldn’t find any posts that described how to recover from this. Determined not to give up on OpenSolaris, I started trying to get my laptop back in order. I didn’t want to lose my home directory. I have tons of valuable code snippets, settings, documents, and huge subversion checkouts of various projects and branches of those projects (about 80GB of data total). So, I’m including the steps I followed to get my laptop running again (along with all of the data in my home folder) below. There may be a better way to do this, but this worked for me.

Step #1: Boot from an OpenSolaris Live CD Boot up with an OpenSolaris CD. We’re going to use the live CD to help us backup the home directory. Step #2: Backup your home folder Open up a terminal and execute the command:

pfexec zpool import -f -R /tmp/rpool rpool
Then take a snapshot of your important data:
pfexec zfs snapshot rpool/export/home@pre-reinstall
I didn’t have an external drive with enough free storage space, so I shipped the backup over to another machine via ssh:
pfexec zfs send rpool/export/home@pre-reinstall | ssh user@myhost.com " \
          cat > ~/homedir.snapshot"
Step #3: Use the OpenSolaris Live CD to do a Full install of OpenSolaris With my home directory safely backed up, I wiped the machine and did a reinstall of OpenSolaris. Step #4: Boot into single user mode (login as root)
ssh user@myhost.com "cat ~/homedir.snapshot" | \
pfexec zfs recv -F rpool/export/home
Your home directory should be ready to go now. Reboot and enjoy.

Update: I recently used pfexec pkg image-update to update my 2008.05 installation to 2008.11. OpenSolaris 2008.11 is awesome! I’m loving the Time Slider functionality. The pkg image-update worked flawlessly. My upgrade was a complete success. None of my tools or applications were broken during the upgrade. The folks working on OpenSolaris have really been putting in some hard work to resolve a lot of the early issues that I experienced.

DjangoCon 2008 Videos

I’ve been reading Simon Willison’s blog for quite a while now. He frequently posts interesting ideas and links. Yesterday, I noticed that he had a link to videos from DjangoCon 2008 on YouTube. So far, I’ve watched Schema Evolution and Reusable Apps. I learned a lot from both videos. I’ve only been working with Django for a few months (mostly for this blog) and I’m really enjoying it. I think it’s really cool that they’ve posted videos from the Django conference so people that couldn’t attend (the conference or a particular talk) can check them out (and learn something). Living in rural South Carolina, there are not (currently) a lot of local opportunities to exchange ideas with other python developers. I hope that more (python related) conferences follow Django’s lead and post conference videos. Great job!

Rocking Time Machine

Recently, the hard drive in my trusty Mac Mini decided it was going to have problems. Running some diagnostic tests revealed that it has some bad sectors. I had another firewire drive on the shelf, so I plugged it in and booted from my Leopard DVD. The Leopard Installer allows you to access several utilities including the Time Machine recovery functionality. So, I selected my Time Machine drive and asked the utility to recover my machine to my spare firewire drive. In a little under two hours, my machine was up and running again — booting from that spare firewire drive. The recovery process was simple and worked flawlessly. I’ve never been very good about properly backing up my data. Thanks to Time Machine, I don’t have to worry about it any more.