Author Archives: alwold

Nerd bucket list

I’ve been doing pretty much straight Java programming for the last 4 years and it has not escaped my attention that Java seems to be falling out of favor in the programming community.  Anyway, I’m currently spending some time branching out and learning a few other languages/frameworks/etc.  I’ve also been going on a tour of the various nerd meetings in Phoenix, seeing what the user communities are up to and which are most vibrant.  I made a semi-prioritized list of things I want to learn, which is based on stuff I’ve read online, what’s cool locally, and personal preference, so here it is:

  1. ruby/rails
  2. iphone/objective c
  3. scala
  4. javascript (already familiar, but become a master)
  5. node.js
  6. haskell
  7. groovy/grails
  8. python

Java and overcomplication


When I first started working with Java to do real work, the servlet spec was pretty immature, and I was coming from a world of cgi-lib.pl and PHP.  Things were quite simple.  You wrote a class that had a method that received GET and POSTs, called some simple methods to get the decoded query string parameters, and printed out the results.  It was easy to learn, but the code was not pretty or well organized.  Calls to the database were simple, ugly, and prone to connection leaks.  They were easy to write, however.

Fast forward to 10 years later, and in order to write a “clean” Java web app, you need to be using an MVC framework, persistence APIs, etc. This involves pulling in a complicated tree of JAR dependencies, composing complicated XML configuration, and implementing highly abstracted interfaces which require quite a bit of thinking to get your head around.  I can’t help but think if I were just getting into Java right now, I’d be intimidated almost to the point of giving up.

Java is still pretty solidly established in the “enterprise” space, so I don’t see it disappearing anytime soon. If you want to look to the future, however, it is probably wise to take a look at what the smaller companies and startups are doing.  They have the benefit of starting fresh and being able to use the technologies that most effectively support their goals, without having to port existing stuff/retrain staff.  Java is present in those environments, but other technologies seem to be far more well represented.  I wonder how much this has to do with the Java community’s progression over the last several years to the point where it is highly complicated and difficult to learn.

File associations

Today I double clicked on a CSV file on my Mac, and I proceeded to watch the Excel icon bounce up and down in my dock for about 15 minutes while it churned on the document.  I was then presented with a spreadsheet with all of the data contained in one column.  Excel had blown it.  I was upset.  I hate Microsoft Office, and it totally sucks.  I don’t want it to defile my computer with its presence unless circumstances are dire.  But, it has asserted to the operating system its great ability to open CSV files.  Unfortunately, that ability is limited to the “import” function in the file menu, and it is not smart enough to perform an import when it overconfidently attempts to open a file through the Finder.  This led me to reflect on the annoying feature that is file associations (or whatever your platform chooses to call them).

File associations have always been annoying.  Programs fight over them and they always end up being what you don’t want, but changing them to what you do want is a giant farkle festival that would only be enjoyable to the most serious nerds.  So, in my frustration I came up with an idea.  Programs should be registered according to their ability as well as their “goodness” at opening files.  For example, Microsoft Office’s ability to open a docx file might be 9/10, whereas OpenOffice would be like 5/10.  In this case, when a user clicks on a docx file, the computer decides to go with Microsoft Office.

Obviously, overconfident software vendors like Microsoft and Adobe would always set their values to 10/10 for every file time.  That’s where the power of the Internet comes in.  A community based web site could be created to rate the abilities of programs to open files.  Maybe on a spectrum of different characteristics (correctness, annoyingness, memory hogging, etc.).

Cool program

I purchased one of the new MacBook Pro’s that were released in April, and I’ve been really liking it.  Mostly it just offers improvements to some things that were getting annoying about my old one.  It has more memory, a higher resolution display, and the unibody case is cool.  In any case, the battery life is nowhere even close to the 8-9 hours they advertise.  As a result, I was curious about how often it was using the high powered discrete NVidia graphics chip, so I started looking with system profiler, and it was pretty much always running.  With some experimenting, I found out it was mostly because of Google Chrome.  It would be cool if Apple released some tools to fine tune the graphics switching, and I imagine they eventually will, but for now there is this cool program, gfxCardStatus, which has really advanced quickly since it was released.  One thing that is really cool now is that it shows a list of programs that are causing the system to use the high powered chip.

Cisco AnyConnect with Ubuntu server

Cisco has a VPN client called AnyConnect which is used with its SSL VPN products. I don’t know that much about the details of their product line, but I happened to be attempting to use it in a weird situation and ran into some trouble. I’m running an Ubuntu server AMI on Amazon EC2, so it’s a quite minimal install. It seems that pretty much every error with the program comes up as the following:

>> error: Connection attempt has failed due to server certificate problem.

In my case, there were several issues. First of all, it requires several shared libraries. If you run the following, it should take care of all of the shared library requirements missing in the default install:

$ sudo apt-get install libnss3-1d

Next, it actually expects Firefox to be installed, because it apparently messes around with the firefox config store. I installed Firefox to no avail (which downloaded about 300 MB of packages), so I will save you the time and let you know that that was both unnecessary and useless to solve the problem. All you need is a Firefox profile for it to stick some new cert info in. This command (executed from the user’s home dir) should do the trick:

$ mkdir -p .mozilla/firefox/anything.default

And one more thing to mention, various forum posts I saw mentioned not to run the “vpn” program (used to manage the VPN state) as root. So, I ran it as my normal user.

Once I did all of that, everything worked great. Cool.

JDBC connections under an oppressive regime

If you are using tomcat in an environment where you are not allowed to view the data source configurations, it can be frustrating.  Fortunately, when you need to debug, there’s a programmatic way to get the configuration.  Here’s a sample:

<%@page import="javax.naming.InitialContext" %>
<%@page import="javax.naming.Context" %>
<%@page import="javax.naming.NamingEnumeration" %>
<%@page import="javax.naming.NameClassPair" %>
<%@page import="org.apache.tomcat.dbcp.dbcp.BasicDataSource" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <body>
      <ul>
      <%
      if ("alwold".equals(request.getRemoteUser())) {
        InitialContext ic = new InitialContext();
        NamingEnumeration<NameClassPair> ne = ic.list("java:comp/env/jdbc");
        while (ne.hasMore()) {
          NameClassPair ncp = ne.next();
          Object o = ic.lookup("java:comp/env/jdbc/"+ncp.getName());
          if (o instanceof BasicDataSource) {
            BasicDataSource ds = (BasicDataSource) o;
            out.println("<li>"+ncp.getName()+"</li><ul>");
            out.println("<li>"+ds.getUrl()+"</li>");
            out.println("<li>"+ds.getUsername()+"</li>");
            out.println("<li>"+ds.getPassword()+"</li>");
            out.println("</ul>");
          } else {
            out.println("<li>found odd object "+ncp.getName()+" of type "+o.getClass().getName());
          }
        }
        }

      %>
      </ul>
    </body>
</html>

It’s particularly important to have the part that checks for remote user, because this thing is printing out passwords to the screen. You’ll have to put some sort of filter to set the remote user and then replace my username with yours (or come up with some entirely different protection mechanism).

Apache Commons

If you are a Java developer, and you don’t know about Apache Commons, you should take a minute to check it out.  A lot of times when you need to write some mundane code to do something, and you are thinking to yourself, “I’m sure a million other people have had to write this code”, you should take a quick look at commons to see if they did it.  A lot of times they have it packaged up in a nice library.  One of my favorites is the IOUtils class in commons-io, which can pull an InputStream into a String object in one line of code, but they have a bunch of other stuff that is useful as well.

Deleting SQLite database in android

If you are in the process of developing an android app that uses SQLite, you probably have found yourself in the situation where you wanted to restructure the database.  Instead of bumping the version on the helper class and putting in upgrade logic, it is best to just start over with a fresh database when you haven’t yet released your new version of the app.  Here’s how you zap your database in the emulator’s file system.

First, find out the serial number of the emulator as it is running:

$ adb devices
List of devices attached
emulator-5554    device

Now, connect a shell and delete the file from the filesystem:

$ adb emulator-5554 shell
# rm /data/data/<yourpackage>/databases/<databaseName>
# exit

After that, your database should be gone and will be recreated next time you run the helper to get a connection.

Maven is like apt-get for Java

When I first learned Linux, I used Slackware 3.0.  In those days, if you wanted to install extra software, you pretty much had to compile it yourself.  And they didn’t even have configure scripts back then, if I recall correctly.  Eventually, Redhat took over, and software was easier to install via RPM packages.  At first, RPMs weren’t available for everything, so you still had to compile some stuff, but eventually they became pretty ubiquitous.  Dependencies could be a big pain though.  You download one RPM you want, and you find out you need to download five more that it depends on.  And those five each depend on five others.  Remember rpmfind.net?  Then came yum and apt-get, and those trouble were alleviated.

Now, building Java apps is almost like managing a Linux system.  There are so many great third party libraries available, you can find ones to do almost any common task you need, saving lots of time when coding stuff.  But, the people that write those libraries also use other libraries.  Things like Hibernate have a lot of dependencies.  Getting all of the jars for the libraries you need can be somewhat like the old RPM hunt.  This is where Maven comes in.  Just tell it you need Hibernate and it will make sure you have everything else you need.  It’s pretty awesome, and it can completely eliminate those sessions where you waste a lot of time looking for jar files.