Alvin Alexander | Java, Scala, Unix, Perl, Mac OS X

Writing software is a funny thing. You do something one day and you think it's really cool, then come back another day and go "WTF was I thinking?", so you tear it apart and rewrite it.

Today I ran the JRat Java profiler (Runtime Analysis Toolkit) on some code I wrote about 10 days ago, and it showed that I was looking for a pixel 10,000,000+ times on a 1024x768 resolution image.

Linux wget command FAQ: Can you share an example of a wget command used in a Linux shell script?

Here's a Unix/Linux shell script that I created to download a specific URL on the internet every day using the wget command. Note that I also use the date command to create a dynamic filename, which I'll describe shortly.

Cygwin crontab FAQ: How do I get the crontab system started when using Cygwin?

I can't remember where I found it, but using this series of commands from the Cygwin prompt got the Cygwin crontab system enabled for me. First this command:

cygrunsrv -I cron -p /usr/sbin/cron -a -D

followed by:

net start cron

I haven't used this cygwin feature before, so it feels weird knowing that crontab is running on my Windows system under cygwin.

The grand experiment has begun. The problem: I've been on a project developing a very deep application for four years now, and lately it's become so complex and intertwined that things are starting to break. Developers have been known to say "The application is smarter than I am." I'm just a wee bit concerned about our software quality.

Throughout all of this I started to notice that many of these bugs could be found if we had ... (drumroll) ... automated GUI tests.

I still have a lot to learn about Ruby, but here's a Ruby script that runs a series of system commands (Kernel.system()), which in my case means calling a series of JRuby scripts. I send all of the output from this script and from the system calls to a file by (a) writing directly to the file using Ruby and (b) redirecting STDOUT when making each system() call. I think this is a hack, but I can't find a better way to redirect STDOUT.

I'm doing some crazy things at the moment, basically calling JRuby from a Ruby script on a Windows 2000 system. I'm doing this because there are a bunch of JRuby scripts that I want to run sequentially, and I also want to check for errors after each run, so what better way to invoke them and look for resulting errors than with Ruby, especially on a Windows system? :)

Here's some sample JRuby code that I just used to take a screenshot of my desktop. It uses the Toolkit and Robot classes from Java to make it all happen. It could probably be a little shorter, but I don't know much about JRuby yet. I also had a problem getting the Java File class to work properly, and referencing it as shown was the only way I could get it to work.

Here's some sample code that demonstrates how to use the Java JOptionPane showConfirmDialog method. I've included the method call in the context of a real containing method (doExitAction()) so you can see how it might be used in real-world code.

Here's another one of those postings that are just here to help my bad memory. I currently travel a fair amount, work on different systems and projects, and can't remember the Java syntax for adding a Java ActionListener to a JButton, so here's a little sample code to help me remember:

This isn't the most high-tech way to do things, but I thought I'd share these Windows (DOS) shell scripts that I'm currently using to compile a Java application, create a Jar file to distribute the application, and finally run the application. I ended up creating these scripts because of configuration problems on my Windows PC, but I thought they might be useful samples for others.

Here's a "Java clipboard" method I use when writing a Java/Swing program that needs to place plain text (a String) on the system clipboard:

Earlier tonight I installed JRuby on a Windows XP system, and it was about as easy as anything I've installed. Here were the steps on my computer:

You know what will really screw with your mind? When there is a 1.4.2 version of a java.exe file in the C:\Windows\System32 directory of your Windows XP system, and you're trying to compile and run a Java 1.5 program from the command line. I kept getting this error message and couldn't figure it out, even though I knew what it meant(!):

This is just my second JRuby program, but I thought I might as well go for the gusto. This Ruby/JRuby program creates an instance of a Java Robot class (java.awt.Robot), then moves the mouse to a position where it clicks the Minimize button on a full-screen window (assuming a display resolution of 1024x768). Warning: if you have something else in that location it will click that instead!

Here's the Ruby/JRuby code:

Nothing too major today, I just wanted to note this site that features stylized line drawings. I like this form of art, and didn't want to forget the name/type, as well as this artist.

 

(Note: This article was originally written in 2005.) As far as design goes, products like the Mac, TextMate, and JFormDesigner have really opened my eyes to the possibilities of great design, and it's impact on people (I was going to say "users", but that say more inhuman than ever before), and my personal feelings about using these products. At the moment I don't really ever want to go back to using a Windows PC ever again, in spite of the few things I don't like about Mac OS X.

After a fairly large number of emails I've started working on my type-ahead, predictive text editor project. In support of this effort I'm looking at different algorithms to best predict the word the user next wants to type. The first part of this is looking at documents I've written in the past, and analyzing the frequency of word occurrences within those documents.

I recently needed to print the information in a Ruby hash, with the results sorted by value. Here's a general recipe on how to print the hash results sorted by value. I've created a sample hash, and populated the hash with sample data, to show how this works.

First, here's the sample code, using the first name of each person as the key, and the last name as the value of the key/value pair:

There are a lot of commands for navigating through a file with the vi editor (or, more recently, the vim editor), but the reality is that I've used various forms of Unix (Ultrix, AIX, CLIX, SCO Unix, etc.), Linux, and more recently Mac OS X, and there are only a few vi commands that I use for moving around in a file.

So I thought I'd list those here, the most common vi commands.

In a heavy day of JFormDesigner use, I just learned how to create a JComboBox in a column in a JTable, using only JFormDesigner.

First, create your JTable in JFormDesigner. I'll skip the details here, hoping that process is easy enough. Then, click the ellipsis button for the model property in the Properties list. This brings up the JTable model editor.