Django logo I’ve been working on a project using django, and I’ve got some great things to say about it. I also have some nasty things to say. I’m currently prototyping, which means the databases I work with get destroyed and recreated regularly. I normally have a set of test data that should always be present in the system. Database fixtures to the rescue!

The django documentation has a nice section on database fixtures and how to deal with them properly. You can even give your fixtures a special name (initial_data), and the syncdb command will automatically load your initial fixtures for you. The first thing that really struck me about these fixtures is the fact that you have to reference your model for every database row. Why not divide the fixtures into sections so you only have to type it out once? The fixtures could really benefit from that type of context.

The second thing I noticed, after typing out all my fixtures in YAML format, is that django claims to support YAML format, but doesn’t actually check for an initial_data.yml (or initial_data.yaml) file. That’s a big disappointment. Now am I supposed to translate that file back into xml or json? It picks up files with those names perfectly fine.

Continue reading »

Zend Framework logo Once you understand all the basic concepts of writing programs, the practice of software development can sometimes devolve into a simple exercise in pattern recognition. If you catch yourself writing the same code more than once or twice, you’re probably doing something wrong. Here’s an example that will apply particularly to those of us who use the Zend Framework.

Typically, in a web application following MVC design principles, there are patterns that emerge from your actions. Patterns like access control, detecting special requests and responding appropriately, preparing pagination controls, etc. The Zend Framework and other frameworks provide abstract classes to handle the basics, but they’re meant to be extended to suit your own application.

Make sure you have your own ./library folder within your application that’s on your php include path and create a directory structure for your extended action class beginning with a namespace of your choice. I’m using Crozz. Here’s a skeleton that I’ve paced in ./library/Crozz/Controller/Action.php:

Continue reading »

Eclipse PDT IDE After upgrading to Intrepid Ibex Alpha 5, I was presented with a familiar problem. I knew I had dealt with this at least a half-dozen times in the past, but I never seem to learn. It all happened when I tried to import a project I’d started from my subversion repository into eclipse on my laptop. I began to get very strange un-googlable Java errors that I knew I’d seen before. Here’s two of them:

java.lang.nullpointerexception
java.lang.NoClassDefFoundError: org.eclipse.emf.ecore.util.EcoreEMap$DelegateEObjectContainmentEList

When I made the distribution upgrade, I failed to notice that my symbolic link /etc/alternatives/java (pointed to by /usr/bin/java) had changed. Instead of using Sun Java, I was back to using GCJ. GCJ is a great effort, and if it could run PDT smoothly I would use it in a heartbeat. Until then, I’m forced to use Sun Java. Don’t bother changing the symbolic links by hand, Ubuntu has a handy tool to do that for you. It would have been nice to have preserved my original configuration though.

sudo update-java-alternatives --set java-6-sun

Next time I get these messages maybe I’ll remember to check which Java I’m using.

Continue reading »

We’re getting ready to launch a new college football site for the upcoming Fresno State Bulldogs season. The site uses a table to display a player roster. Adding sortable columns to the table is a snap with jQuery. All you have to do is load the tablesorter plugin, and call it up when the page loads. This makes every table you have sortable:

$(document).ready( function() {
  $('table').tablesorter();
});

For most tables that’s all you need to make it work beautifully, but in my case the plugin was having trouble sorting my height column. It looks like it was sorting that column as text, but that doesn’t work because in the US we like to see our football player’s heights in feet and inches such as 5’ 11” for five feet and eleven inches. Thankfully the table sorter plugin allows you to define your own column types which it can automatically detect and sort for you.

$(document).ready( function() {
  $.tablesorter.addParser({
    id: 'height',
    is: function(s) {
      //$.tablesorter uses this function to determine if this colum is of this type
      return s.match(new RegExp(/^\d{1}\' \d{1,2}\"/));
    },
    format: function(s) {
      //now we'll just return the number of inches and $.tablesorter will sort them as integers
      var matches = s.match(new RegExp(/^(\d{1})\' (\d{1,2})\"/), 'g');
      return parseInt(matches[1]) * 12 + parseInt(matches[2]);
    }
  });
  $('table').tablesorter();
});

Continue reading »

There’s something strangely satisfying about switching gears from a well structured language like Ruby all the way back to the days of actionscript 2. It brings me back a little. Actionscript 2 has a lot of intricacies and subtle nuances that you wouldn’t expect and that’s one thing that makes it fun. It’s fun because it doesn’t normally work as expected. You have to delve deep into the minds of the poor people who were forced to create it and outsmart them. It’s fun because when you finally get something to work, you can look at your code and say, “there’s no way that should work!” After a few hours of working with the language you begin to anticipate the worst possible scenario. You would think this for instance: If I want to create an array object called bar with 3 elements, I’d do it like this:

var bar:Array = new Array('a', 'b', 'c');

but if I wanted only one element in the array, I’d do it like this:

var bar:Array = new Array(['a']);

Of course! It’s so obvious. The square brackets are obvious because actionscript 2 wants to make doubly sure that bar will actually be an array and not just a string, whereas the commas give it away in the first example so adding square brackets there would just create an array containing an array.

Continue reading »