Thursday, December 02, 2010


I didn't expect that a word that would describe physical things moving to software would have been coined in 1938. Paul Graham's blog today has an article discussing this. This is not a new trend, but one that is accelerating. It's been everywhere for a while and will just grow.

Tuesday, November 30, 2010

Where are My Pixels Going?

I have a Dell Inspirion 1520 that is more than three years old. Recently I've started thinking about a replacement. The 1520 is a 15.4" laptop with a 1680x1050 display. Don't ask me what meaningless combination of letters from the end of the alphabet describe this resolution. 1680x1050 means something. Something-GA means nothing. Anyway, this laptop cost me about $1,600.00, including tax and shipping because I bought ALL the options. Had I just taken a standard 1520 and added the better display, I'd have been well under $1K. Today I visited the Dell website and discovered that the only laptop that has better than a 1600x900 resolution display is in their Alienware line and starts at $1,700.

I use my laptop primarily for programming and system administration. Unlike 10 or 15 years ago, programming no longer requires anything resembling a top of the line computer. What I was hoping to find was a $600 or so 17" laptop, add a $100 display upgrade and have a better machine for something slightly over $700. Actually, I'm lying. I was thinking that there might be a chance that the $600 laptop might actually come with a better screen than was standard three years ago, giving me my 1920x1200 display in a stock machine. I never imagined even for a second that the best resolution available in a 17" laptop would not even match the first optional resolution from three years ago.

Furthermore, what's the deal with computer displays with TV resolutions? I know nobody who doesn't have at least three television sets that they can watch if they need to catch up on their shows. I also know nobody who wants to use their laptop as a primary or even secondary TV watching device. If you do any work on a computer, you are probably creating documents of some sort. Rather than a display with a 16:9 aspect ratio, computer users would be better served with a display with a vertically oriented aspect ratio of 2:3 or so. Since that would be a bit unwieldy, the old 4:3 is actually pretty good if there are enough vertical pixels, but I'll take the 16:10 displays as a reasonable compromise. 16:9 is just not the optimal aspect ratio for office productivity. Programming tools are a bit wider, so they can use some horizontal pixels, but source code files are even longer than office documents as they are not paper page oriented, but rather just long files of hundreds of lines or more in length. A display with the aspect ratio of a horizontal slit is just not appropriate for getting stuff done.

Please, laptop manufacturers, offer me a laptop with a display sized for working on documents, not for watching TV. I have a very nice 42" TV that I can use for watching the History Channel. It is much better than my laptop for that job.

Trivial Patents are Killing Our Economy

I have been a software developer for nearly 30 years. During this time, I have seen the number of software patents and business process patents increase by huge numbers. Rather than protect innovation, as is the intent of patents, these patents create a minefield for business, strangling innovation and severely weakening our economy. Most software and business process patents do not cover inventions that took any major effort or investment to create. Many, perhaps most, are nothing more than the obvious solution to a specific problem encountered by a programmer or engineer during the course of solving normal, daily business problems. Since we do live in a changing, technological world, it is natural that there are new problems to be solved. Generally, for an experienced technician, these solutions to these problems are obvious or at least easily arrived at after only a small amount of consideration. Worse still, it does occur that some of these patents are issued to an entity that did nothing more than document an existing solution that nobody else had previously bothered to patent.

Unfortunately, it is easy for the patent applications for these "inventions" to expand to many pages of eye watering technical jargon that disguises their triviality. As a result, the Patent Office generally grants these patents that seem counter to the standards of patentability to any honest and only slightly experienced technician. The problem of the existence of these patents is obvious without much investigation. However, the scope of the problem is many times greater than is obvious, as these patents are seldom invalidated even when they should be. The reason for this is the huge expense and effort involved in fighting them. Most businesses are in business to do business and avoid litigation as much as possible. Generally, companies either waste time coming up with new, slightly different solutions, or simply resign themselves to license deals they should not have to suffer. Paying a license fee, even one that should not exist, is usually much, much less expensive than litigation. More importantly, these invalid but all too real license fees are a known cost, whereas litigation cannot be predicted in either the dimensions of cost or outcome. Unfortunately, this environment serves only to strengthen invalid patents, causing them to drag on an industry for years.

This issue has been on my mind for years, but recently I read this article:

In short, the problem being decided is what effect the discovery of previously unknown prior art should have during patent litigation. To me, it is shocking that previously unknown prior art should even come up in litigation. Rather, there should be an administrative process by which an entity that has knowledge of prior art can simply provide this information to the Patent Office. The Patent Office will then consider this new information, and when appropriate, terminate a patent that should not have been issued. It is a horrible drag on our economy that the courts are the only venue that can be used to correct for the existence of an invalid patent when a patent clearly should never have been issued in the first place.

In these difficult economic times, serious patent reform that limits patents to their intended purpose of wholly new and revolutionary innovations would go far to helping our economy. Businesses would not have to suffer the taxes of litigation or license fees for trivial patents. The most important benefit, though, would be that the attention of businesses could be focused on doing business rather than worrying about these trivial patents. I believe the effect of this would be a surge in true innovation and a huge boost to the economy.

Wednesday, September 01, 2010

Converting an Integer to an IPv4 IP Address in Bash Using Bitwise Operations

I needed a script to automate the generation of statically assigned IP addresses, but I could not find any good example. It's a simple algorithm, so I decided I'd just write it up myself, but then I discovered that I could not find a good example of using bitwise operators in Bash. I found many pages where the operators are listed, but there is always the mention that they really aren't used in scripts all that often. Well, thanks for that, but how about one example of how to use them?

I came up with the following code, though I'm not sure if the $(( )) constructs are really necessary, but I simply could not make things work without them. Please let me know if you know a simpler syntax.

# The IP address in this example is simply harcoded.
# In actual use, I read and write this from a file.


a=$(( ($ipint & $MASKA) >> 24 ))
b=$(( ($ipint & $MASKB) >> 16 ))
c=$(( ($ipint & $MASKC) >> 8 ))
d=$(( $ipint & $MASKD ))


echo "The IP Address is ${ipaddr}."

Wednesday, March 03, 2010

Monday, February 22, 2010

Simple Filter to Extract Links from a Pidgin Log

I often trade political links via the Pidgin IM client with my friend Jeremiah. Last week, he had the idea that we should coauthor a blog about these links. Towards this end I decided I harvest all of the links from my Pidgin log. This script will do that:

grep http ~/.purple/logs/aim/yourimid/friendsimid/* | grep -v -E "content-type|funpic\.hu|funnyjunk" | sed -e "s/^.*href=\"//" -e "s/\">.*//" | grep -v "font color"

The first grep finds anything that looks like a link, the second filters out any sites you don't care about. You can add more to that list by adding more "|sitename" clauses to the regex. The sed command scours off the html that Pidgin puts around anything and the last grep kills off some oddball lines that made it through the filters.

I'm sure this could all be made more efficient, but it did the job and unless you had an enormous quantity of logs to search, it's efficient enough.

Thursday, February 18, 2010

Ditching the Euro?

I know it's a little premature to forecast the abandonment of the Euro and a return to national currencies, but I was surprised to find that some people are already discussing the topic.

Wednesday, February 17, 2010

Blogging, JavaScript and CSS

I've started posting little bits of code to my blog, and I thought it would be nice to have some sort of a code tag, similar to how blocks of code are set apart on Gentoo Forums. My first thought was that there must certainly already be something like that already for Blogger. Well, no. Then I decided to just start using <pre> tags. That works, but then you lose line wrapping. The then realized that I was going to have to write some CSS. I hate having to delve into CSS because despite the fact that I spend all day, every day coding in Java in Eclipse, I don't have much time for web programming and I find writing HTML or programming in loosely typed languages to be distasteful.

I won't go into all of the details, but even that has turned out to be more involved than I was hoping. At least to do it right. After trying several things, I've finally come up with a little bit of CSS and JavaScript that work together to do a mediocre job of what I want to accomplish. You'll see the results in this blog posting.

First, I created this CSS that I added directly to my Blogger template in Layout -> Edit HTML:

.code {
padding: .5em;
border-right: #d1d7dc 1px solid;
border-top: #d1d7dc 1px solid;
border-left: #d1d7dc 1px solid;
color: #000000;
border-bottom: #d1d7dc 1px solid;
font-family: 'Liberation Mono', Courier, 'Courier New', monospace;
font-style: bold;
background-color: #ffffcc

That gives me the block that I want, setting off the code from the article text. But then I noticed that any extra spaces were being lost as happens with HTML. That led to this bit of JavaScript added to the HTML/JavaScript block in Layout -> Page Elements:

<script type="text/javascript">
var divs = document.getElementsByTagName('div');
for(var i = 0; i < divs.length; i++) {
if(divs[i].className == 'code') {
str = divs[i].innerHTML;
str = str.replace(/ /g, '&nbsp;');
divs[i].innerHTML = str;

This is very sub-optimal, though, as the regex in replace() is overly simplistic. I tried several expressions, trying to get something better, but had no luck. What needs to happen is that all blocks of multiple spaces at the beginning of a code line need to be replaced with &nbsp;. I simply could not figure out a single expression that would replace a variable number of spaces with a corresponding quantity of &nbsp;, and only do it on the beginning of a line. If you can think of something that might work, let me know. Otherwise, I may just write some code to inspect the line and figure out what spaces need to be replaced.

I'll come back around to this when I have more time. Or, I might just use Alex Gorbatchev's Syntax Highlighter, but that was way more involved than I wanted to deal with today.

Monday, February 15, 2010

Awesome Steaks

My wife has some friends who are chefs who told me the way to cook a steak in an oven and have it come out excellent. Here is the procedure:
  • Ahead of time, whip butter with salt and pepper, fresh chopped thyme, a little fresh lemon juice, fold in roquefort cheese. Roll in wax paper into a cylinder shape and chill. The wax paper should be rolled around the butter like a tube, not rolled up with the butter like a newspaper.
  • Steaks should be at least 1" thick. I used 1.5".
  • Preheat oven to 375° to 400° F.
  • Pat steaks dry. Season to taste.
  • Heat a little oil in a pan over medium heat. When pepper dropped into the oil sizzles, add steaks. Sear on each side for 2 to 3 minutes. I went a little short because the steaks started looking done VERY fast. Do not be alarmed. Next time I'll do the entire 3 minutes on my thick steaks.
  • Place whole pan in oven for 3-5 minutes until the steaks are done to taste.
  • Cut butter cylinder into slices. Place butter slices on steaks while they are hot from the oven so the butter melts over the steak.
  • Eat.

Wednesday, February 10, 2010

Simple Filters in Perl

The other day I needed to pull some XML out of a log file. Some of the XML is in human readable format, spanning multiple lines. I changed my logging to spit out a tag before and after the XML to make it easy to mechanically separate the XML from the rest of the log.1 The tags I used were "--- XML Request" or "--- XML Response" at the beginning of the line before the XML and "--- End XML" at the beginning of the line after the end of the XML. The Perl I came up with to filter these logs is:

#!/usr/bin/perl -w

$in_xml = 0;

while (<>&) {
if ($in_xml) {
print $_;
if ($_ =~ /^--- End/) {
$in_xml = 0;
} else {
if ($_ =~ /^--- XML/) {
print $_;
$in_xml = 1;

I then remembered that I didn't have to specify the =~ or $_, Perl being able to assume that for you, my revised version is:

#!/usr/bin/perl -w

$in_xml = 0;

while (<>) {
if ($in_xml) {
print $_;
if (/^--- End/) {
$in_xml = 0;
} else {
if (/^--- XML/) {
print $_;
$in_xml = 1;

1 This is entirely unlike mechanically separated chicken.

Out of Scope

Why is it that every time I opine aloud that Java would benefit from a destructor, something that gets called the moment an object goes out of scope, people start whining about memory leaks and saying memory management is hard? I didn't say ditch the garbage collector. Since you have brought up the subject, let me say again that memory management is not hard.

Monday, February 01, 2010

Java Needs Destructors

I've been a Java programmer for seven years now. Java is no C++, but it's not a bad language, especially in it's Java 6 incarnation. There are just a few things about it, though, that continue to really get under my skin. This biggest is the lack of destructors in Java. In C++, you'll often see code like this:
public void foo() {
ResourceIntensiveClass ric = new ResourceIntensiveClass("have bugs");
And you can be comfortable that, if written correctly, ResourceIntesiveClass' destructor will be called and all resources freed when ric goes out of scope, regardless of whether it was under control or because of an exception thrown by ResourceIntensiveClass::exceptionRiddledFunction().

Unfortunately, when Java was being designed, the designers seem to want to get rid of every aspect of C++ that gave people trouble. Many people have trouble with destructors, so they are completely non-existent in Java. The only possible replacement, the finally clause to the try/catch block, requires the programmers who use a class to remember to call resource freeing methods of a class in their finally blocks. Every time. Without fail. Good luck. Java code is needlessly much more verbose for the same task than many other languages. Consider this Java equivalent to the code above:
public void foo() throws Exception {
ResourceIntensiveClass ric = null;
try {
ric = new ResourceIntensiveClass("have bugs");
} finally {
if (ric != null) {
Twelve lines to the first example's five lines. More typing and more opportunities for programmer induced bugs.

When is Java going to grow up and get destructors?

Ungovernable by Design

I often find myself saying that one form of tyranny is the tyranny of the majority electorate over the minority electorate. This is generally during a conversation discussing the Constitution and how the United States of America is a republic, not a democracy. There seem to be those with grand ideas about how the USA could be a "better" country who seem to find the Constitution and the, at least intended, weakness of the federal government to be a hindrance to their plans. Apparently one such person has even bemoaned that America has become ungovernable. Adam Graham has written an excellent article about how and why this is so. The point is, be glad that it is.

Wednesday, January 27, 2010

Java Timer for Running Recurrent Housekeeping Tasks

My company has several products which use long running Java programs. Occasionally, these programs need to do some sort of recurrent houskeeping tasks, such as deleting old files or some such task. I've found that the Java Timer class is very helpful for this. First, I create a class that I call a housekeeper to keep the Timer instance and load it with the houskeeping classes needed by the program. The housekeeper looks like this:
package net.tadland.examples.timer;

import java.util.Timer;

public class Housekeeper {

// The task delay is how many milliseconds transpire between the time
// that the task is scheduled and its first run. The task period is
// the time interval between runs.

private static final long TASK1DELAY = 10000;
private static final long TASK1PERIOD = 71 * 60 * 1000; // Run every 71 minutes;
private static final long TASK2DELAY = 60000;
private static final long TASK2PERIOD = 45 * 60 * 1000; // Run every 45 minutes;

private static Housekeeper me = new Housekeeper();

private Timer housekeeperTimer;

private Housekeeper() {

// The boolean parameter here indicates that the timer is
// to be run as a daemon. It will continue running, launching
// each TimerTask specified below, over and over, running
// each TimerTask every period milliseconds.

housekeeperTimer = new Timer("Housekeeper", true);
housekeeperTimer.schedule(new HousekeepingTask1(), TASK1DELAY, TASK1PERIOD);
housekeeperTimer.schedule(new HousekeepingTask2(), TASK2DELAY, TASK2PERIOD);

public static synchronized void stop() {
if (me != null) {
me = null;

Then you will need one or more housekeeping task classes. I create one class per discrete task. A trivial example is:
package net.tadland.examples.timer;

import java.util.TimerTask;

public class HousekeepingTask1 extends TimerTask {

* Since an instance of this class is created once when the daemon
* Housekeeper is created, don't store any transient data in class variables
* in this worker class. Data relative to a given run of this housekeeper
* should be in variables local to the run() method of this class.

public void run() {
// Do your housekeeping tasks here.

There are other ways to use the Timer and TimerTasks, including scheduling tasks to run once at a specific time. The way I've illustrated Timers here is how I've successfully used Timers and TimerTasks to perform recurring houskeeping chores in an unattended system which is deployed at many locations and which runs for months at a time.

Our Phony Economy

Harper's magazine has an interesting article about what they call our "Phony Economy". Maybe all growth isn't good, nor is lack of it bad.

Is Your Password Secure?

Weak passwords continue to be a major problem in IT. Even your Facebook account should not have a weak password.