Keeping It DRY – Automation of Repetitive Tasks

February 26th, 2010

I’m woking on a “legacy” Java app that’s written in Struts and uses EJBs. No Jetty or Tomcat for me – gotta use a “real” J2EE container – in this case, JBoss.

Unfortunately, I haven’t figured out a good way to run JBoss against my sources, as I would if using something like the jetty or tomcat plugins for maven.  So I find myself redeploying the app frequently when working on the UI.

Of course, JBoss is only good for a handful of redeployment cycles before it goes four paws up with a “java.lang.OutOfMemoryError: PermGen space” error. And when it does this, the processes must be killed. On Linux, this involves doing a “ps” command to find the process ids, and then using the “kill” command to kill them. Easy stuff, but very repetitive.

I’m a big fan of the “Pragmatic Programmer” Series of Books, so I quickly thought of the “Don’t Repeat Yourself” (DRY) principle put forth there.

The result? A simple shell script for killing JBoss:

ps -ef | grep jboss | grep -v grep | awk '{print $2}' | xargs kill -9

Relative Cost of Printing On Different Printers

January 2nd, 2010

I have an ancient, yet trustworthy HP6L black-and-white laser printer that I bought back in 19??

About a year ago, I replaced the last of a long line of crappy ink-jet color printers with an HP-CP1815ni color laser printer.

I assumed that for printing in black-and-white, the 6L, being black-and-white only, would be cheaper. I just looked up the prices of the toner cartridges, and their yields.

Turns out that the color laser has a lower per-page cost for black-and-white than the b&w.
A toner cartridge for the 6L is around $75, and is rated for 2,500 pages, while the color printer’s black cartridge is about $90, but yields 5,000 pages.

Lesson for the day – check your assumptions!

VirtualBox vs. VMware on Ubuntu 9.10 Karmic Koala

November 3rd, 2009

I updated my server to the 9.10 “Karmic Koala” release of Ubuntu.
Unlike my recent laptop upgrade, I upgraded instead of doing a fresh install – I have too much software installed there to go through re-installation if I don’t have to.

As I have mentioned here before, one of the things that I run on that server is a virtual instance of Windows XP, to support QuickBooks. For our business accounting needs, we then simply RDP to the virtual Windows XP instance to use QuickBooks.

I’ve been running that virtual machine on VMware. I like VMware. It works well, is well-polished, and the “Server” version is free. The one problem is that every time there’s a change to the Linux kernel, parts of VMWare have to be recompiled against the new kernel. This happens just often enough to be an annoyance, but until now, has not been a deal-breaker.

VMware has typically been slow to catch up to major kernel changes, and this upgrade was no exception.
Usually, someone comes out with a patch to the installer fairly quickly. This time, there is a patch, but it didn’t work for me.
I was able to get VMWare started, but unable to keep it running. It would crash, and then when I tried to run it again, it would tell me that it needed to be recompiled. After a couple of cycles of this nonsense, I decided to look elsewhere.

I’ve been using Sun’s VirtualBox at work for some time now, and it’s been very stable, though not quite as polished as VMWare.  VirtualBox also supports and installs the DKMS (Dynamic Kernel Module Support), which promises to automatically recompile the VirtualBox driver when the kernel gets updated. Theoretically, this means that with VirtualBox, I won’t have to deal with this problem any more.

So, I set up VirtualBox, installed XP and QuickBooks, and everything is working fine.
I was pleased to see that the newest version of VirtualBox also supports bridged networking as part of the “normal” VM creation, via the GUI.

BTW, for the curious, I keep the QuickBooks file on the Linux host’s file system, and expose it to XP via a Samba share.
This makes it ridiculously easy to back up the file, and, as with the current switch-over from VMware to VirtualBox, I don’t have to worry about losing it in some virtual machine disaster.

One last thought. VMware, even when it is working, has lately taken the really annoying approach of re-implementing their console as a web application. If ever there was an application that should not be a web app, it’s a virtual machine console.
Of course, you can’t really implement the VM’s window in a web app, so they then go to a browser plugin. This works sometimes, but this is a silly way to do things, with a lot of overhead. I can see where it would be useful sometimes, but it shouldn’t be the only way to administer VMs. Also, the VMware console uses it’s own instance of Tomcat, but comes configured so that it conflicts with all other default installations of Tomcat (the shutdown port is left to it’s default value).
This is an amateur mistake, and has gone unfixed for quite some time.  VirtualBox, on the other hand, has a nice, sane, desktop console. +1 for Sun!

Ubuntu 9.10 Karmic Koala on Dell Inspiron 6000

October 31st, 2009

Ubuntu’s 9.10 Karmic Koala release dropped yesterday, and I dove right in, downloaded it (via BitTorrent), and installed it on my aging Dell Inspiron 6000 laptop.

I didn’t do an upgrade, I reformatted my primary partition, and installed it clean. I keep my /home directory on a separate partition precisely so that I can do this easily, every 6 months as a new release comes out.

Installation was quick and easy, and so far, I’ve seen no major problems.

Notes so far:

  • As expected, the “Extra” visual effects (Compiz) does not work properly (the laptop has an ATI Mobility Radeon X300). “Normal” visual effects mode works fine.
  • The base installation is missing just about every useful codec. This blog post is a nice guide to installing all of the media “goodies” in Karmic.When I first installed all of the packages listed here, none of the video codecs seemed to work properly, including “Movie Player” crashing whenever I tried to open a video of any type. I figured that I’d either have to uninstall the packages, or maybe just re-install Karmic, and then install one package at a time, until I found the culprit. Fortunately, at this point, I powered the laptop off. When I started it again, everything worked fine, and has continued to do so.
  • I was seriously impressed with the short boot time in Jaunty Jackalope, and Karmic’s boot time is even faster. All I can say is, “Wow!”
  • Karmic has a new login screen, that lists the user names, and has you pick one. Frankly, I don’t care for it. First, my fingers are “trained” to type my user name and password to log in, and now I frequently type my user name in the password field. Second, not that I need to worry about it so much on my home laptop, but displaying a list of the user names lowers the barrier for someone attempting to log in who shouldn’t be able to. Third, I think that the new screen is very ugly. I like Ubuntu, but their themes always seem to suck bigtime. Brown themes, black login page with blocky graphics…ugh. Fortunately, this stuff is easy to change.
  • I don’t do a wide variety of things with this laptop – basically web browsing and Java programming. Occaisional audio editing. Occaisional image editing. Not too much else, so I can’t really comment on the range of applications that ship with this version. I’ll report more as I find anything interesting.

iPhone app development with Linux

October 4th, 2009

My employer, Chariot Solutions, held an in-house, week-long iPhone development course, taught by the folks at Big Nerd Ranch.

The course was great, we all learned a lot, and several of our folks are working on some apps, including one that they announced recently at JBoss World.

80% or more of our consultants have MacBook Pros, however, I opted for a Dell with Ubuntu when I joined Chariot about a year and a half ago.
I borrowed a MacBook for the course (thanks, Ken!), but have been feeling a bit left out since then, as the official Apple development tools (XCode and Interface Builder) only run on OS X.

I had previously whined about the fact that the official toolchain uses GCC under the covers, and that therefore, someone who knows GCC well (as in not me) ought to be able to get something working on Linux. Since then, I’ve seen a few pages on the web with instructions for getting arm-apple-darwin9-gcc working on Linux, but none seemed to have complete instructions on how to get the development environment working.

Well, yesterday, I decided to look harder, and found a site that explains setup of an iPhone development environment on Linux in detail.
With the help of the instructions there, I was able to get the toolchain working under Linux, and with some information gleaned from other websites as well, was able to compile an iPhone app, install it on my phone, and run it. I can stop whining now:-)

So, I’m putting all of the information that I have about this process here, in one place, where I can find it again later – if you have read this far, then I hope it helps you too.

What you need:

  • A computer running Linux
  • A Jailbroken iPhone (see my previous blog post for instructions)
  • A Wifi network to enable your computer to communicate with your iPhone
  • A copy of the phone’s firmware – since you just jailbroke your phone, you have a copy of this – it’s the .ipsw file
  • The IPhone 3.0 SDK (see http://developer.apple.com/iphone/)

The steps:

  • Make sure that the Cydia package manager is installed on your iPhone – if you followed the instructions linked above, it should have been installed as part of the jailbreaking process.
  • Use Cydia to install OpenSSH – this installs an SSH Daemon on your phone, so that you can ssh into the phone from your computer. Your makefiles will include ssh and scp commands to get the app to your phone and install it properly. Before moving on to the next step, make sure that you can get OpenSSH running, and can successfully ssh into your phone as root, and get a shell prompt. If you need help with this, look here.
  • Use Cydia to install Apt. Sometimes things are just easier from the command-line.
  • Use Apt (or Cydia) to install the “ldid” package. Some makefiles that you will encounter will use this to pseudo-sign the app directly on the phone.
  • Follow the instructions at http://code.google.com/p/iphonedevonlinux/wiki/Installation to install the toolchain, including installation of the packages listed there.
  • Follow the instructions to download and build the HelloToolchain application. Note: make sure that your phone and computer are both connected to the same wifi network, that the SSH daemon is running on your phone, and that you know your phone’s IP address. To make things easier on myself, I set up my wifi router to recognize the iPhone’s mac address, and to always give it the same IP address. Now, I can use a shell script to invoke make with the proper address, and I don’t have to check the phone’s address each time.

Once that simple app builds, installs, and runs, you are almost in business. The major issue is that HelloToolchain, being a simple test app, doesn’t show you how to structure things for a “real” application. And if you’re not a Makefile geek, it may not even be obvious how to build an app that consists of more than one source file. So, go to http://code.google.com/p/apiexplorer/ and download the iPhone API Explorer project. It demos just about every user interface object, and has a really well-thought-out Makefile (be sure to use Makefile.linux) that shows how to build a complex project.

If you have gotten this far, you are probably tired by now of typing in the password for your phone three or four times for each build.
To set up public key authentication for your phone:

  • ssh into your phone, use apt to install vim if necessary, and then use it to edit /etc/ssh/sshd_config
    • uncomment the line: PubkeyAuthentication yes
    • use the ssh-copy-id script to copy your public key to the phone.

That should do it. Happy iPhone programming!

Why I Won’t Be Downloading The CNN iPhone App

October 4th, 2009

CNN released it’s new iPhone app with a big splash last week.

It’s a paid app – $1.99 at the App Store. The rub is, it apparently has in-application advertising too.

Apparently quite a number of people are just fine with this, but I find it pretty appalling. You can either charge me for your app, or push advertising to me when I use your app – but not both. CNN does this on cable t.v. too. I don’t care much for that either, but at least I can timeshift that with my DVR, and then fast-forward through the commercials.

I would imagine that CNN will get most of it’s revenue from the advertising, and relatively much less from the $1.99 app purchase price.. I would prefer that they, like the New York Times and MSNBC,  make their app free – and I’m voting with my wallet.

Switching J2EE Application Servers

September 12th, 2009

I’ve seen a lot of articles lately that talk about the nuts and bolts of moving from one J2EE server to another.

I’ve also seen that a number of companies are struggling with this issue, sometimes even just when upgrading to a newer version from the same vendor.

Umm…folks…J2EE is supposed to be a standard.

Remember, “write once, run anywhere” ? That was supposed to be especially easy on the server side.
Well, actually it is, if you resist the temptation to use proprietary, non-standard features.

I have never willingly written a line of vendor-specific J2EE code or configuration – and I suggest that you don’t either.
There’s almost always a standards-compliant, or at least portable way to do whatever you need.
If you’re having an issue moving your J2EE application to a different server, you’ve probably done something horribly wrong. Frankly, this is true of databases as well (see my “stupidity rant” from earlier today).

Ok, so you have a legacy app that uses vendor-specific features. Maybe you didn’t write it – you’re just stuck maintaining it.
Remember this when you are rewritng your legacy app – stay away from vendor-specific features this time, and don’t create another instant-legacy app.

Infinite Stupidity

September 12th, 2009

As Albert Einstein has been quoted as saying, “Two things are infinite: the universe and human stupidity; and I’m not sure about the universe.”

*** Warning: this blog entry is a rant. The opinions expressed here are entirely mine, and do not necessarily represent the opinions of my employer, whose website links here.

The more I observe human behavior, the more I agree with Einstein on this issue.
I’m not, as you might expect, just talking about the domain of software engineering, but of course, that’s included too :-)

Here are some of my favorite recent examples:

- The current healthcare reform “debate” in the U.S. – many people who have insufficient health care coverage or who are a single medical event away from potential bankruptcy argue vehemently against reform of healthcare delivery and insurance. This is in direct opposition to their own self interests, and seemingly serves no-one but the insurance companies. In the expression of their opposition, they do radical things, like continually repeating bald-faced lies, and verbally assualting the President during a formal address, on live television. Yet they call themselves “conseratives”, and so does the Media. All of these actions seem to me to be blatantly stupid.

- Several years ago, I worked for a small software consultancy (not my current employer), where I “inherited” the maintainence and continuing development of a custom application for a State agency. The application had been written as a one-off “solution”, was written in MS Visual Basic, and used an Oracle database. The VB code was hard to maintain, which tended to drive up the cost of maintainence and new feature development, and after a year or so, the customer also noticed that the Oracle license was costing them a huge pile of cash each year, as was the Windows Server license. They asked if we could switch to a different database. Unfortunately, the cost of doing so was prohibitive, because much of the business logic was in Oracle stored procedures. About a year later, the consultancy signed contracts with the equivalent agencies in two other states, to provide them with software with functionality similar to that in the software for the previously mentioned agency. It wasn’t workable to modify the original software, both because it was so specific to that particular customer (again, it was a custom “solution”), and because of the same issues that made it hard to maintain. A ground-up approach was in order. Lessons learned would be applied. I led a team that wrote a framework for the general problem domain, and then customized implementations on top of that framework for both new customers. We used Java, and ran it on Tomcat on Linux. We used Hibernate, and put all of the business logic in a coherent, well-designed “business tier” of the Java application. We were able to switch databases effortlessly, and did so. The application ran on mySQL, Oracle, and SQL Server, with only a simple change to one configuration file. No vendor lock-in required. No licenses required. All “free” software. Success! Fast-forward a few years – I recently heard that the original state agency (the one with the VB app.) finally got together the funding to completely re-write their application. My former employer did it in C#, no doubt with SQL Server, on Windows Server. Cost – unknown. Vendor lock-in – complete. Stupidity – infinite.

- On my current consulting project, the customer is already heavily invested in the Seam framework, so the new application that we are writing for them is also using Seam. I’ve never worked in Seam before, so I’m just coming up to speed – reading documentation, looking at sample code, etc. I’m mostly working on JPA code, but within the Seam environment. Yesterday, I wrote code to satisfy the first few use-cases. Domain objects, services, and some database access via JPA. Ok, now it’s time to test that code. I read the Seam documentation – it shows how easy it is to test Seam components, even JSF functionality. I wrote up my first test (subclassing SeamTest, as shown), and…the test won’t run. It looks like the SeamTest has failed to set up the JPA environment, and it’s looking for an “InitialContext” so that it can get the transaction manager from JNDI. Ok, that’s not too surprising – so I go back to the documentation to find out how to set up a test that includes JPA – except that there apparently isn’t any. A trip to Google-land shows about what I expected – hundreds of individuals asking about how to solve this problem, and not one single coherent, step-by-step answer. Further reading turned up the gem from the Seam folks that they don’t believe in unit testing, only integration testing. Looks like they believe that integration testing means “slap all of your code together, from all tiers, untested, deploy it, and try out things from the user interface”. Apparently, they think that this approach makes software development faster. The point that they clearly missed is that actual contruction of software (i.e. writing code) is typically a very small percentage of the time and cost involved in the total software lifecycle. The real costs come over time, after initial deployment, when the code has to be maintained, and new functionality added. That’s when unit and integration tests are priceless. Even in that initial construction phase, on-time delivery of a quality product still demands good design, good planning, and early, frequent, comprehensive testing at all levels – and this includes both unit and integration testing. The Seam folks and their adherents think that they are saving time by not testing properly. This makes about as much sense as re-writing your application exclusively using Microsoft technologies because you have been burnt in the past by vendor lock-in. It makes about as much sense as poor people arguing against reform of the healthcare industry, or for big tax breaks for the rich.

Stupidity is indeed infinite.

MULE Classpath

August 13th, 2009

Working with the Mule open source ESB project today, I was struck by the need to deploy project-specific jar files to Mule’s lib/user directory. This is fine if your Mule installation only needs to support a single instance of Mule, or multiple instances using the same jars.

Mulesource’s recommendation for supporting multiple instances is to run their bin/setup_local_instance script, which essentially copies the bin and conf directories to a new location, and then creates a new lib/user directory in that new location.

This certainly works, and is probably the best thing to do in a production envrionment. However, in a development environment, deploying your jar(s) to mule’s directory is an extra step. For instance, in this case, I was using Maven to build my Mule project. I like Maven quite a bit, and find it preferable to ANT, but, following it’s convention over configuration approach, it puts it’s packaged binary in your project’s target directory, and there’s no simple way to have it copied somewhere else. You can, of course, modify your POM, and do some fairly arcane stuff to get it copied, but ultimately, deployment to a server environment isn’t Maven’s thing.

Other solutions are possible, including sym-linking Maven’s target directory insto Mule’s lib/user directory, using an external deploy script, etc., etc. One thing that does not work is simply setting the classpath before invoking Mule, as the Mule startup script sets it’s own classpath.

It’s not well documented, nor recommended for production use, but it turns out that Mule supports a MULE_LIB environment variable, the contents of which get appended to Mule’s custom classpath, the same as if they were in lib/user.

Jailbreaking the iPhone 3G via Linux

July 16th, 2009

redsn0w linux

I recently succumbed to the call of the iPhone.
I’ve had it for about a week, and I like it a lot.
All except for the fact that it’s tied to Apple’s App Store.

There’s a whole world of third-party apps out there, but they’re not available in the App Store.
So, I decided to take a chance, and “Jailbreak” my phone, which involves using third-party software
to patch the iPhone’s firmware.

Information on how to do this from Windows or OS X is pretty easy to find, but instructions for doing
it on Linux are sparse.

Generally speaking, you can find the instructions for downloading and using redsn0w to jailbreak your phone here.

The missing instruction for Linux users is that you must run redsn0w using “sudo”.
If you run it as a “regular” user, it will hang when it first says, “waiting for reboot”.
I didn’t investigate very deeply, but my guess is that a non-root user doesn’t have permission to write to the usb device.

Once I ran “sudo redsn0W”, it ran as advertised, worked perfectly, and installed Cydia.
Now I’m off to play in a new universe of apps!