Category Archives: nerd

Another post about my favorite database

Relational databases are really cool. When you get experienced with them, you can leverage all sorts of features to make sure your data is solid. A good database schema will provide a good check against buggy code trying to mess up your data. One of my favorite ways to enforce integrity is the usage of NOT NULL constraints. I recently added some to a MySQL database I’m working on, and I noticed something unusual…

mysql> alter table SERVICES add SERVICE_KEY varchar(64) NOT NULL UNIQUE;
Query OK, 1 row affected (0.16 sec)
Records: 1 Duplicates: 0 Warnings: 0

mysql> describe SERVICES;
+------------------+---------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------------+---------------+------+-----+---------+----------------+
| SERVICE_ID | bigint(20) | NO | PRI | NULL | auto_increment |
| DESCRIPTION | varchar(128) | YES | | NULL | |
| COMMENTS | varchar(64) | YES | | NULL | |
| ACTIVE | varchar(3) | YES | | NULL | |
| CREATED_BY | varchar(128) | YES | | NULL | |
| CREATED_DATE | datetime | YES | | NULL | |
| UPDATED_BY | varchar(128) | YES | | NULL | |
| UPDATED_DATE | datetime | YES | | NULL | |
| TYPE | varchar(4) | YES | | NULL | |
| URL | varchar(1024) | YES | | NULL | |
| MAX_TRAN_THREADS | smallint(6) | YES | | NULL | |
| MAX_SYNC_THREADS | smallint(6) | YES | | NULL | |
| SERVICE_KEY | varchar(64) | NO | UNI | | |
+------------------+---------------+------+-----+---------+----------------+

As you may notice, the default value is somewhat nebulous on this new column. Normally the default will show NULL, which is good. In this case, it looks like it is either “nothing” which I would equate to NULL, or ”, which is horrible because it breaks the whole purpose of having the constraint. Since I trust MySQL to generally do the wrong thing, I test it:

mysql> insert into SERVICES (SERVICE_ID) values (NULL);
Query OK, 1 row affected, 1 warning (0.00 sec)

And of course, it is taking my null SERVICE_KEY value and turning it into ”. So now, if my app is broken and trying to insert null into SERVICE_KEY, MySQL will save the day and “fix” the data, completely eliminating any errors from being produced that would have revealed the bug in my code.

To quote the famous fashion designer Mugatu, I feel like I’m taking crazy pills! Everyone seems to love MySQL, but it seems completely obvious to me that it is not even a candidate to be considered when writing anything moderately serious.

A2DP in Leopard

One of the features I was looking forward to in Leopard is support for Stereo Bluetooth headphones. I am happy to report that it works, and the UI is much better than ones I’ve used in Windows (obviously, right?). Unfortunately, I seem to pick up a lot of interference. When I first tried them at home, I didn’t notice it, so there might just be a lot of interference in my office on campus. I can see like 5 wireless networks, so it makes sense. I wonder if I’d have the same problem with a PC. Maybe I should build a tinfoil box to sit in.

Two more gripes about mysql

First, this:
mysql> grant all on confluence_2_6_0 to dmitsuper@’%’ identified by ‘xxx’;
[alwold@bug ~]$ gunzip -c confluence_2_3_0.dump.gz | mysql -u dmitsuper -p confluence_2_6_0
Enter password: 
ERROR 1044 (42000): Access denied for user ‘dmitsuper’@’%’ to database ‘confluence_2_6_0’
Second, when I go to fix it (change confluence_2_6_0 to confluence_2_6_0.*), I can use the history in the mysql client to recall the grant line containing the password (so the password is stored in a file somewhere).

Headless Fedora tips

Being a computer nerd makes you write ridiculous things like “headless fedora”.  If you look up those words in the dictionary, you would think I was talking about hats for people with no head.  Anyway, it seems like a lot of system admin tasks on Fedora, if you look them up on google, refer to the graphical utilities included with it.  Many times it is advantageous to forgo the use of the graphical stuff (like in a headless setup).  Here are a few tips for how to do some things without the gui tools:

Configure the network
The gui tool system-config-network will recognize the lack of an X display, and present you with a nice curses (no, not like evil curses, another dumb computer word) based interface.
Change firewall rules
Run the command system-config-securitylevel.  The curses version of this program is a little confusing, but you have to go to the Customize button to change firewall rules.  Reloading them remotely is trickier, and I haven’t found a great way.
Change startup services
There is a command which has come with Redhat for a long time called ntsysv.  Just run that and check the boxes for the ones you want.  You can also use the chkconfig command to do it in a more laborious process.
Update: you can reload the firewall rules without disrupting your ssh session by running /etc/init.d/iptables restart…awesome

iPhone Tech Talk

This week, I had the opportunity to go to a talk at the University of Washington about developing apps for the iPhone. At the moment, development is restricted to web apps, but there is an SDK that is supposed to come out in February which should open up more development avenues. For now, we are restricted to web apps, so the talk was about that. As a side note, it is possible to develop apps natively, but it is completely unsupported by Apple.

The day after the talk, Apple released most of the presentation materials on their iPhone dev site, so you can check it out there as well. You have to sign up for an online ADC account, but that is free (although their “security questions” policy is highly obnoxious).

So, on to the meat of the presentations… The talk was basically broken down into three sections. First was a discussion of the capabilities of the iPhone web browser. Next they discussed data (mostly video) capabilities on the iPhone. Finally, they concluded with a session on designing good looking apps for the iPhone.

The web browser built into the iPhone is based on Safari 3, which is currently in beta on Windows/Mac, but it will be fully released along with Leopard tomorrow. Safari is based on WebKit, which has an open source version. Three levels of web support were defined: Compatibility, Optimization and iPhone apps. Basically, the first step to making your web site work with the iPhone is making sure the regular version works with Safari 3 and the limits of the iPhone. Optimization involves making your site work better with the I/O methods of the iPhone, and iPhone apps use specific Javascript/CSS features of the iPhone.

The first part, compatibility, basically gives tips on how to keep your CSS and Javascript compatible with standards, rather than just making sure they work with the mainstream browsers. They mentioned things like using Javascript object detection instead of user agent strings. Generally, if your site works with Safari 3, you will probably be in good shape.

The second part is optimization. There are various tricks you can use to make sure your web site looks good on the iPhone. For example, the iPhone pretends to be a 980×1091 display and then shrinks the web page, so you can test that on the desktop. There are also some custom CSS things that set whether or not your web site should be zoomable, or what CSS file to use based on the characteristics of the browser (like screen size). The CSS media queries are a standard CSS thing, so they will work in other browsers as well.

Finally, if you are going to try to make a web site specifically for the iPhone, they have some additional recommendations. You should make use of AJAX, so the app is responsive and interactive, and try to emulate the layouts and styles they use in native iPhone apps. One of the more interesting things they mentioned was the use of the Canvas object, which is built into most web browsers (excluding IE), and allows drawing custom things on the fly on the screen.

In the data presentation, the basic flow of data to and from the iPhone was described, most of which is pretty obvious. Things like calendar data flowing to the phone via iTunes were described. They also went into some depth about optimizing video for the iPhone. There are some encoding settings built into Quicktime for the iPhone in Wifi and EDGE modes. You can encode your video for the various data rates, and create a “Quicktime reference movie” which links to the various copies of the video. The iPhone will choose the proper video when it is directed to a reference movie on the web.

The design presentation went over some concepts of how to design your app to match up with the iPhone’s native apps. Most of it was pretty basic stuff. They did iterate one important point, which is to keep in mind the goal of facilitating what your user wants to achieve. Getting wrapped up in the details can lead to feature creep and make the flow of the application confusing. I thought this was a good design concept in general which applies to all applications.

All in all, the talk was an interesting overview of the dev environment available today, and gave some background into some of the “vibe” of the iPhone. There were a couple cool things to pick up on, but a lot of noise as well. While the current environment does provide the tools to achieve quite a bit, I look forward to what might come in the February release of the new iPhone SDK.

Blackberry dev gripes

I’ve been working on a project to port a GPS enabled MIDP app to the Blackberry 8800. This is the first Blackberry work I’ve done since the Nextel blackberry 7520 and 7100i’s. Things have changed a bit, but not that much. The dev environment works pretty well, but I do have a couple gripes. I think some of my issues have to do with not using the “JDE” they provide. RIM should really come to grips with the reality that people write apps for many MIDP devices, and it would rarely be practical to use a Blackberry specific IDE. Anyway, here’s my list at the moment:

  • The 8800 randomly reboots sometimes when you use javaloader to install an app. I’ve heard that something similar happens on the 8820, but it prompts you before rebooting. This really slows down the turnaround on the compile-install-test cycle.
  • The 4.2.1 JDE comes with a JDWP debugger, which apparently lets you do on-device debugging. I’ve gotten it to attach to a device via Eclipse, but it doesn’t stop on my breakpoints. It does output the System.out.println()s to the console though.
  • Over the air provisioning is clunky on Blackberry. You have to provide a JAD (which you don’t for cable loading, so why is it needed here?), and you have to split the COD file into a bunch of little ones (which I guess explains the need for a JAD).

I think I have a few others, but I can’t remember them now. I’ll have to add them later…

Java is better than .NET

Back at Trimble, I wanted to write some unit tests for our DAO stuff, so I came up with this crazy scheme to run a test SQL server on the local machine. I had all this custom code set up to prep the database for the test, then run the tests.

In Java, I am using a HypersonicSQL (is it even called that anymore?) in-memory database to do testing. It’s really fast since it doesn’t write to disk, and every time you run the tests, you have a fresh database. You just inject the HSQL config into the HibernateUtil class and run the tests.

Push email for Treo 650

It has been out for a while now, but I just got around to installing the push email update for the Treo 650. I had to upgrade Versamail, so it cost about $12 total to get it working. Once it was installed, it was really easy to connect it to my Exchange account and the push email works, as well as calendar synchronization. Pretty cool. It has crashed the Treo once so far, but it crashes a lot, so I wasn’t too surprised. Also, if your exchange server is heavily firewalled, like my previous employer, you may not have much luck, I imagine.

Anyway, get it here.

I noticed they also have Blackberry connect for the Treo 650, which probably achieves generally the same thing, but I bet you have to do more work on the server side, plus something on the carrier. This required nothing on the server and works with a regular data plan.

Performance vs. Maintenance

I’ve been writing software as a job for a few years now, and I think there is one common theme that seems to recur. There is never enough time to get everything done. The proper solution to this problem is one or a combination of three basic ideas: bring in more resources, come to a compromise, or increase productivity. The first two alternatives are not very appealing because businesses generally want to offer a good product and not spend a lot of money building it. Increasing productivity, therefore, seems to always be a good goal to keep in mind.

When writing software, one of the things we are all taught to do is pay attention to performance. We analyze algorithms, figure out their big-O complexity in terms of computing and memory usage and pick the best one. I always hated that part of school with a passion. Perhaps that makes me biased. I agree, however, that you need to keep performance in mind.

For me, performance has always been just that. Something on my mind, but not usually directly applied. I prefer to pay attention to elegance and the architecture that supports the code. I think, in general, if you pay attention to the architecture and keep things simple, the performance works itself out. You do have to think about performance, but don’t let it compromise the elegance of your code. Once the application is deployed and/or load tested (depending on the flexibility of redeployment), you can fix any performance problems, and sacrifice elegance if it comes down to it.

The tangled web of JSF

Despite the fact that all of the web apps at my current job are .NET, I have spent a lot of time working with web apps in the Java world. I have experimented a bit with some of the web frameworks and never really found anything I really like that much. My preferred method has been to just generate XML in the app and use XSL to transform it, but there is still not an ideal separation of logic and presentation. Since JSF is (was) kind of a new thing and seems to try to copy some of the neat things about ASP.NET, I decided to do a little side project in it at work. This really would have been an ideal candidate for Ruby on Rails, but I think Ruby is a little out there in terms of having other people maintain it.

Anyway, I spent a few hours reading up on JSF in my idle time. It seemed really complicated, and nobody really explained it very well. I eventually just dived in, and ran into a bunch of problems. Eventually, I got a page to list a bunch of entries out of a database. The problem is, the DAO needs to be pretty much a pure Java Bean which means you can’t really manage connections very well. I used Hibernate to do the data access, so you need to handle creation and closing of the session object. Listing rows is simple enough to just open, list, close, but updating will get hairy. Apparently, “the way” to solve this is by using Spring Framework. I’m not really sure how it works, but apparently spring handles all the session management for you. I have been interested in Spring since first hearing about it a couple years ago, so I guess this is an opportunity to learn that as well. In any case, I am now about 3 days into the project with no real results. Way to go Java, always overcomplicating things. I hope it is worth it.