Tad in Texas
Random thoughts and observations about freedom, politics, technology and anything else interesting.
Thursday, November 03, 2011
Selecting Alternate Desktops in RHEL 6 with GDM
The developers of Gnome have been shedding functionality in an attempt to make Gnome simpler. One of the things that has gone missing is the ability of GDM to select a different desktop. How this is a good thing is beyond me, but regardless, it's the way it is and it needs a workaround. At my job, we install CentOS onto commodity machines along with our software and ship them to our customers' sites. We have one application that runs without any window manager at all via the /home/username/.Xclients script. When we moved to CentOS 6.0, this suddenly stopped working. After I determined that the .Xclients script wasn't being run, a big of googling found this page which has a very elegant workaround. This script allows an individual user's .Xclients script to override the default selection of Gnome, but doesn't force other users to use .Xclients in order to get Gnome. Everyone wins! At least until the next time Gnome get stupider, er, simpler.
Thursday, October 13, 2011
Formatting Source Code for Blogging
When pasting source code into a blog, it is nice to have the formatting preserved. There is now a site that makes this easy: formatmysourcecode.blogspot.com
Monday, September 26, 2011
3D Acceleration in VirtualBox
When adding the VirtualBox Guest Extensions to a VM running Linux, make sure that you have 3D acceleration enabled in the VM's settings before you install them. If you do not, the extensions will be compiled without the acceleration and you won't get the benefit thereof. I was pleasantly surprised to see that recent Linux distributions will dynamically size their desktops to the window size of the VM once the extensions are properly installed.
Thursday, September 22, 2011
How to Change the GDM 2 Background
In the past, Gnome GDM's appearance could be changed with themes. This was changed when GDM was rewritten for Gnome 2. GDM now uses gconf and the keys are documented in the Gnome Library. At first I was having little luck with these as I was naively running gconftool-2 as root. You have to run the gconftool-2 as gdm:
sudo -u gdm gconftool-2 -t str -s /desktop/gnome/background/picture_filename /full/path/to/your/background.png
Tuesday, September 20, 2011
How to Restore Control-Alt-Backspace in Red Hat Derived Distros
The disabling of Ctrl-Alt-Backspace has finally made it into Red Hat Enterprise and derived distributions as of RHEL 6.0. To restore it without having to resort to GUI clikery, add this to /etc/X11/xinit/xinitrc-common:
setxkbmap -option terminate:ctrl_alt_bksp
setxkbmap -option terminate:ctrl_alt_bksp
Thursday, December 02, 2010
Ephemeralization
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.
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:
https://www.eff.org/deeplinks/2010/11/supreme-court-decide-standard-proving-invalidity
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.
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:
https://www.eff.org/deeplinks/2010/11/supreme-court-decide-standard-proving-invalidity
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.
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.
#!/bin/sh
#
# The IP address in this example is simply harcoded.
# In actual use, I read and write this from a file.
#
# 192.168.1.100
ipint=3232235876
MASKA=0xFF000000
MASKB=0x00FF0000
MASKC=0x0000FF00
MASKD=0x000000FF
a=$(( ($ipint & $MASKA) >> 24 ))
b=$(( ($ipint & $MASKB) >> 16 ))
c=$(( ($ipint & $MASKC) >> 8 ))
d=$(( $ipint & $MASKD ))
ipstr="$a.$b.$c.$d"
echo "The IP Address is ${ipaddr}."
#
# The IP address in this example is simply harcoded.
# In actual use, I read and write this from a file.
#
# 192.168.1.100
ipint=3232235876
MASKA=0xFF000000
MASKB=0x00FF0000
MASKC=0x0000FF00
MASKD=0x000000FF
a=$(( ($ipint & $MASKA) >> 24 ))
b=$(( ($ipint & $MASKB) >> 16 ))
c=$(( ($ipint & $MASKC) >> 8 ))
d=$(( $ipint & $MASKD ))
ipstr="$a.$b.$c.$d"
echo "The IP Address is ${ipaddr}."
Wednesday, March 03, 2010
The New Microsoft Tax
Apparently Microsoft now wants to expand the Microsoft Tax to cover everyone. That's pretty clever, now isn't it?
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:
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.
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:
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:
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 . I simply could not figure out a single expression that would replace a variable number of spaces with a corresponding quantity of , 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.
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
}
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, ' ');
divs[i].innerHTML = str;
}
}
</script>
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, ' ');
divs[i].innerHTML = str;
}
}
</script>
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 . I simply could not figure out a single expression that would replace a variable number of spaces with a corresponding quantity of , 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:
I then remembered that I didn't have to specify the =~ or $_, Perl being able to assume that for you, my revised version is:
1 This is entirely unlike mechanically separated chicken.
#!/usr/bin/perl -w
$in_xml = 0;
while (<>&) {
if ($in_xml) {
print $_;
if ($_ =~ /^--- End/) {
$in_xml = 0;
}
} else {
if ($_ =~ /^--- XML/) {
print $_;
$in_xml = 1;
}
}
}
$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;
}
}
}
$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:
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:
When is Java going to grow up and get destructors?
public void foo() {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().
ResourceIntensiveClass ric = new ResourceIntensiveClass("have bugs");
ric.initiateResourceLockingStuff();
ric.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 {Twelve lines to the first example's five lines. More typing and more opportunities for programmer induced bugs.
ResourceIntensiveClass ric = null;
try {
ric = new ResourceIntensiveClass("have bugs");
ric.initiateResourceLockingStuff();
ric.exceptionRiddledFunction();
} finally {
if (ric != null) {
ric.manuallyCalledCleanupMethod();
}
}
}
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:
Then you will need one or more housekeeping task classes. I create one class per discrete task. A trivial example is:
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.
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() {
super();
// 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.housekeeperTimer.cancel();
me = null;
}
}
}
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() {
super();
// 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.housekeeperTimer.cancel();
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. */ @Override 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.
Monday, May 18, 2009
You Cannot be a Programmer Without Understanding Computers
In The Perils of JavaSchools, Joel Spolsky pretty accurately describes the problems with a lot of programmers who are coming out of colleges today. Back in the mid to late 1980s when I was in college, C++ was brand new and Java didn't yet exist. Most classes still used Pascal, though C was becoming more and more popular. The thing is, our classes back then mostly taught concepts, not languages. I even had to take a hardware digital logic class. (Much fun!) The only classes I really remember are Assembler (IBM 370 assembler at that!), Data Structures (taught by Jeff Harris, who last I heard, went off to a very well paying job at Motorola after being let go (!) by a university that obviously didn't appreciate the tremendous value of his teaching), Systems Design, where we wrote a software coputer and then later an assembler and linker for it. Everything else was fun, but just entertainment. Those three classes are the ones where I learned stuff that became the foundation for everything I've done since then. The sad thing is now, none of those classes are even offered, much less required.
Thursday, February 05, 2009
This is Certainly a First
A friend sent me a link Well, That Certainly Didn’t Take Long and told me, "read this article...and pretend like Limbaugh or Noonan wrote it. I'm in somewhat of a state of shock." I generally don't read columns from the likes of Maureen Dowd. As a matter of fact, I had to ask my friend who she is. His response was, "ultra-ultra-ultra lefty; Huffington crowd".
Well, that was certainly interesting. Now I'm in a state of shock. Happy, but still shocked. Some leftist acknowledgment that there's a lot of liberal agenda in the stimulus bill as is and that even some Democrats are getting disillusioned is very refreshing.
Well, that was certainly interesting. Now I'm in a state of shock. Happy, but still shocked. Some leftist acknowledgment that there's a lot of liberal agenda in the stimulus bill as is and that even some Democrats are getting disillusioned is very refreshing.
Wednesday, February 04, 2009
Libertarian Frustration
A friend pointed to me to an excellent article by John Hasnas, Associate Professor in the McDonough School of Business at Georgetown University. In this short article, titled What It Feels Like To Be A Libertarian, Mr. Hasnas accuratly sums up the frustration felt by Libertarians, as they watch markets be manipulated by politicians who later declare that free markets don't work. The frustration that comes from watching "fixes" that make the problems worse.
Tuesday, February 03, 2009
Righteous Politicians
I'm already tired of the righteousness I'm perceiving from the Democrats in Congress. I'd like to remind them that they rode into office on the coattails of a man for whom people voted for not primarily for his policies. The reasons I believe many people voted for Barack Obama are, in order:
I am still hopeful that Mr. Obama can guide his party to a higher standard, but I have my doubts, considering what he has to work with. Despite all of the Democratic complaints during the past eight years of the Bush administration, they seem to be willing to act in the same ways they complained about now that they are in power. I'm hoping for better, but not expecting it.
1) I hate the word bipartisan as it implies their is something inherently "right" about a bipolar system. I believe that our cyclical tit-for-tat approach to politics does far more harm than good.
- He's not George W. Bush.
- Sarah Palin was perceived to not be qualified for a job she was not even running for. I'm still scratching my head over this one.
- His race. I'm sorry to say this, but I really do think that for some voters at least, the color of his skin was more important than the content of his character. Hopefully someday Dr. King's dream will be achieved, but I don't believe it was this time.
- His policies.
I am still hopeful that Mr. Obama can guide his party to a higher standard, but I have my doubts, considering what he has to work with. Despite all of the Democratic complaints during the past eight years of the Bush administration, they seem to be willing to act in the same ways they complained about now that they are in power. I'm hoping for better, but not expecting it.
1) I hate the word bipartisan as it implies their is something inherently "right" about a bipolar system. I believe that our cyclical tit-for-tat approach to politics does far more harm than good.
Monday, December 08, 2008
New in Java 7
Java 5 was the first version of Java that I found usable after years of developing in C and C++. The inclusion of generics and other syntax enhancements combined with the appearance of Eclipse made developing in Java finally much less tedious and more productive. Java 6 seemed like more of a maintenance release, though it did provide some nice enhancements such as a better JAXB. I am particularly excited about some of the things promised in Java 7, including closures, BigDecimal operator support, type inference, improved catch clauses, and other fixes that will make working with collections more natural. I still wish they would just give us real operator overloading. The one that has me scratching my head, though, is automatic resource block management. In an attempt to rid Java code of most finally code, they have come up with:
These new blocks are an improvement I suppose, but they still suffer the fatal flaw of resource management in Java which is that it is dependent upon the programmer to always remember to free up resources. My real world experience has also taught me that the less that you have to have programmers do manually, the less problems you'll have. I'll gladly accept the new features of Java 7, but I'm still waiting for a truly automatic solution to resource management in Java.
do (BufferedInputStream bis = new BufferedInputStream(is); BufferedOutputStream bos = BufferedOutputStream(os)) {Which is certainly an improvement, but I just don't understand why we can't get a real destructor in Java. My nearly twenty years of OO programming have convinced me that if a language has a constructor, it should have a destructor. Exceptions are academic languages and pseudo code, both of which are free of resource concerns. Real world programming is almost always working with some sort of a finite resource, such as database connections. It is not just good form to clean these up the moment you are done with them, but often simply necessary to make things work in a busy production system.
// do stuff with bis and bos
}
These new blocks are an improvement I suppose, but they still suffer the fatal flaw of resource management in Java which is that it is dependent upon the programmer to always remember to free up resources. My real world experience has also taught me that the less that you have to have programmers do manually, the less problems you'll have. I'll gladly accept the new features of Java 7, but I'm still waiting for a truly automatic solution to resource management in Java.
Monday, December 01, 2008
Don't Just Stand There, DO Something!
Finally, an article that quantifies what I have often felt but didn't know how to explain concerning the inefficiencies of big corporations: They become inefficient because they have too much process, or, as Paul Graham explains, because they are too careful.
On a smaller scale, I've realized that it is often better to simply DO something rather than spend too much time thinking, or really, agonizing, about how it should be done. If you're not sure how to proceed, then simply exclude any stupid directions and pick randomly from what is left. If you happen to have chosen the right path, then you are done. If you chose wrong, then you have effectively reduced the number of choices and can perhaps even use the experienced gained to choose better between those that are left. Often you can go through several cycles of trial and error before you could have made a decision simply by thinking about it.
You may say there are some endeavors where this does not work such as spaceflight or safety systems, but I suggest you can use this same principle there. Not that you won't have failure, but if you are working in engineering, you should be working with test harnesses and other simulators. In software, this has led to "agile development" or "test driven development". If you're not doing this, start.
On a smaller scale, I've realized that it is often better to simply DO something rather than spend too much time thinking, or really, agonizing, about how it should be done. If you're not sure how to proceed, then simply exclude any stupid directions and pick randomly from what is left. If you happen to have chosen the right path, then you are done. If you chose wrong, then you have effectively reduced the number of choices and can perhaps even use the experienced gained to choose better between those that are left. Often you can go through several cycles of trial and error before you could have made a decision simply by thinking about it.
You may say there are some endeavors where this does not work such as spaceflight or safety systems, but I suggest you can use this same principle there. Not that you won't have failure, but if you are working in engineering, you should be working with test harnesses and other simulators. In software, this has led to "agile development" or "test driven development". If you're not doing this, start.
Monday, November 10, 2008
No Way Can We Be Alone
Consider this image taken by the European Southern Observatory deep into the universe. Those aren't stars. They're galaxies. Tens of thousands of them. Each containing billions of stars. Even if earth-like worlds are one in a billion, there must be tens of thousands of earths in this photo. There is no way that there isn't intelligent life somewhere out there.
To those who say intelligent life elsewhere is too unlikely, I say you're just not capable of grasping just how huge the universe is.
To those who say intelligent life elsewhere is too unlikely, I say you're just not capable of grasping just how huge the universe is.
Copyright vs. Culture
I found a very well written summary of the conflict between copyright and culture by Cory Doctorow on Locus Online.
Wednesday, October 22, 2008
JD Wallpapers
You can find some nice Jack Daniels wallpapers on the Jack Daniels website. No wide screen variants, unfortunately.
Friday, May 02, 2008
Rush in Dallas
A friend bought several good tickets for several of his friends, including me. It was a great show. I've only seen Rush twice, though I've been a fan of theirs for over 20 years. They're simply good at what they do, and it's obvious that they enjoy it. The fact that they are devoid of the drama that a lot of other artists have only adds to their appeal. I won't try to review the show. I was enjoying it too much to pay attention to the set list or other details. I'll leave the review for someone who paid more attention the details and is more eloquent than myself, but you can go look at my photos from the concert.
Tuesday, October 23, 2007
Old Fashioned Blogging
In the dark ages before computers, people actually wrote on paper with pen and ink. Most journals were probably just diaries that nobody but their author ever read. The nice thing about such a journal is that paper survives power outages, hard drive crashes and sorts of other catastrophes that affect digital words. Sure, a notebook can be lost in a fire, but it takes a heck of a fire to actually burn a book up completely. Try it sometime; you'll be surprised at how long a book can be in a fire and still be readable. Only if it's closed tightly, though.
After meaning to do it for most of my 40 years, I've decided to finally try to keep a journal or diary and towards that end I have discovered Moleskine notebooks. I chose one of these rather than a cheaper made in China alternative, partially because I don't want to buy any more from China than I have to and partially because I don't expect to get any sort of quality out of any thing mass produced in China.
I did find a funny article talking about the proper pronunciation of the name. I think it really doesn't matter what you call it.
Why did I finally decide to get started on this after so long? I read an article in Tin House magazine about a fellow by the name of Lee Meriwether. As a young man he went to Europe on a shoestring budget and wrote about it in a book called A Tramp Trip: How to See Europe on Fifty Cents a Day. Besides the fact that Mr. Meriwether was such an interesting person throughout his entire life, his travel journal is simply interesting. It shows how interesting a simple daily report of events can be over a century later. Hopefully someone will be interested to read my journals someday.
After meaning to do it for most of my 40 years, I've decided to finally try to keep a journal or diary and towards that end I have discovered Moleskine notebooks. I chose one of these rather than a cheaper made in China alternative, partially because I don't want to buy any more from China than I have to and partially because I don't expect to get any sort of quality out of any thing mass produced in China.
I did find a funny article talking about the proper pronunciation of the name. I think it really doesn't matter what you call it.
Why did I finally decide to get started on this after so long? I read an article in Tin House magazine about a fellow by the name of Lee Meriwether. As a young man he went to Europe on a shoestring budget and wrote about it in a book called A Tramp Trip: How to See Europe on Fifty Cents a Day. Besides the fact that Mr. Meriwether was such an interesting person throughout his entire life, his travel journal is simply interesting. It shows how interesting a simple daily report of events can be over a century later. Hopefully someone will be interested to read my journals someday.
Thursday, May 03, 2007
The Lesson of Vietnam
The other day I was driving to work listening to some reporters on the radio talking about Iraq. Of course the usual subjects were being covered: The false pretenses for the war; Washington politics; The costs of the war; The comparisons with the Vietnam War. It was that last one that put me into a white-hot anger, and that is why I am writing this a couple of weeks later because I didn't want to write mad.
The particular point that angered me was that one of the speakers was opining about what event might be analogous to Vietnam's Tet Offensive as the point at which the war became unwinnable. Let me be very clear: The Tet Offensive was the moment in Vietnam when the media lost the Vietnam war. Despite how it is remembered, the Tet Offensive was one of the most spectacular military victories in American history which was squandered away as a lost opportunity.
Tet, or Tết Nguyên Đán, "is the is the most important and popular and festival in Vietnam". The Tet Offensive was timed to start on the night of January 30-31, 1968. Due to the importance of this holiday, it was believed that the chances for any significant NVA or VC attacks during this time were minute, so much of ARVN was on leave and even U.S. military forces were at a low level of alert. The attacks were a total surprise as earlier hints of the attacks were dismissed by intelligence agencies as disinformation. Despite this, within only a few days, most of the attacks had been repulsed and the North suffered heavy losses.
By the end of the offensive, the VC was all but obliterated. Formerly secret operatives had exposed themselves during the attack and were then captured or killed. The NVA also suffered heavy losses. Some sources quote northern losses at nearly fifty times that of American losses. All military parts of the planned offensive failed. Even the hot spots at Hue and Khe Sanh were finished a few weeks after the offensive started.
The North's plans included a general uprising by the population which never occurred. According to several captured VC commanders, most mid-level VC commanders didn't expect any uprising in their area to occur, but they said nothing and followed through with the plan on hopes that it would occur in someone else's area. Apparently the North was blinded by its own communist ideology. I'm sure the widespread atrocities committed by the North did nothing to help foment this expected rebellion.
The true genius of General Giap wasn't his military plan, but rather his shrewd reckoning that a major attack would sway American public opinion against the war. He may have been more successful in this than he expected as he received a huge help in this way from Walter Cronkite and his "Cronkite Moment" when Mr. Cronkite declared the war unwinnable and stated that America must leave Vietnam. I belive Mr. Cronkite owes me and every other American an apology. I grew up in the 1970s thinking that the Tet Offensive was a huge military defeat for U.S. and allied forces until I became interested in history just before my teenage years and eventually learned the truth about Tet.
And now we have reporters looking for an Iraqi Tet, or perhaps more accurately, an Iraqi "Cronkite Moment". All we hear from the media is how horrible it is that America is in Iraq. We hear terms such as "civil war", yet the Iraqi coalition government is still in place with all major Iraqi ethnicities participating. We hear that American forces are taking a beating in Iraq despite the fact that we have never lost an engagement that involves a unit of platoon size or larger. We hear about every bad thing that a soldier does, but we seldom hear of how any American soldier has helped or befriended anyone.
And what about those the U.S. is fighting? Christians are terrorized routinely all over the muslim world, insurgents behead children, insurgents have children beheading people, all in the name of Allah. Where is the media outrage over these sorts of events? These are not the sort of people you can have a dialogue with. These people simply have to be killed because they are a threat to everyone.
The media needs to stop trying to teach what they believe is the lesson of Vietnam, and learn the real lesson themselves. That lesson is that they are the ones who lost the war and they are trying very hard to do it again.
References:
Give 'Em Surrender Harry Finds His Tet Offensive
Is 'Cronkite Moment' Just a Media Myth?
The Tet Offensive at Wikipedia
The Tet Offensive at Digger History
The Tet Offensive at Ashbrook Center
More About the 1968 Tet Offensive
The Tet Offensive at Vets With a Mission
The particular point that angered me was that one of the speakers was opining about what event might be analogous to Vietnam's Tet Offensive as the point at which the war became unwinnable. Let me be very clear: The Tet Offensive was the moment in Vietnam when the media lost the Vietnam war. Despite how it is remembered, the Tet Offensive was one of the most spectacular military victories in American history which was squandered away as a lost opportunity.
Tet, or Tết Nguyên Đán, "is the is the most important and popular and festival in Vietnam". The Tet Offensive was timed to start on the night of January 30-31, 1968. Due to the importance of this holiday, it was believed that the chances for any significant NVA or VC attacks during this time were minute, so much of ARVN was on leave and even U.S. military forces were at a low level of alert. The attacks were a total surprise as earlier hints of the attacks were dismissed by intelligence agencies as disinformation. Despite this, within only a few days, most of the attacks had been repulsed and the North suffered heavy losses.
By the end of the offensive, the VC was all but obliterated. Formerly secret operatives had exposed themselves during the attack and were then captured or killed. The NVA also suffered heavy losses. Some sources quote northern losses at nearly fifty times that of American losses. All military parts of the planned offensive failed. Even the hot spots at Hue and Khe Sanh were finished a few weeks after the offensive started.
The North's plans included a general uprising by the population which never occurred. According to several captured VC commanders, most mid-level VC commanders didn't expect any uprising in their area to occur, but they said nothing and followed through with the plan on hopes that it would occur in someone else's area. Apparently the North was blinded by its own communist ideology. I'm sure the widespread atrocities committed by the North did nothing to help foment this expected rebellion.
The true genius of General Giap wasn't his military plan, but rather his shrewd reckoning that a major attack would sway American public opinion against the war. He may have been more successful in this than he expected as he received a huge help in this way from Walter Cronkite and his "Cronkite Moment" when Mr. Cronkite declared the war unwinnable and stated that America must leave Vietnam. I belive Mr. Cronkite owes me and every other American an apology. I grew up in the 1970s thinking that the Tet Offensive was a huge military defeat for U.S. and allied forces until I became interested in history just before my teenage years and eventually learned the truth about Tet.
And now we have reporters looking for an Iraqi Tet, or perhaps more accurately, an Iraqi "Cronkite Moment". All we hear from the media is how horrible it is that America is in Iraq. We hear terms such as "civil war", yet the Iraqi coalition government is still in place with all major Iraqi ethnicities participating. We hear that American forces are taking a beating in Iraq despite the fact that we have never lost an engagement that involves a unit of platoon size or larger. We hear about every bad thing that a soldier does, but we seldom hear of how any American soldier has helped or befriended anyone.
And what about those the U.S. is fighting? Christians are terrorized routinely all over the muslim world, insurgents behead children, insurgents have children beheading people, all in the name of Allah. Where is the media outrage over these sorts of events? These are not the sort of people you can have a dialogue with. These people simply have to be killed because they are a threat to everyone.
The media needs to stop trying to teach what they believe is the lesson of Vietnam, and learn the real lesson themselves. That lesson is that they are the ones who lost the war and they are trying very hard to do it again.
References:
Give 'Em Surrender Harry Finds His Tet Offensive
Is 'Cronkite Moment' Just a Media Myth?
The Tet Offensive at Wikipedia
The Tet Offensive at Digger History
The Tet Offensive at Ashbrook Center
More About the 1968 Tet Offensive
The Tet Offensive at Vets With a Mission
Monday, February 12, 2007
Truth
"It is difficult to get a man to understand something when his salary depends upon his not understanding it." -- Upton Sinclair
Wednesday, January 24, 2007
College Sports is Entertainment, Not Academics
On the way to work today, I heard an editorial by Frank Deford of Sports Illustrated. He explains that worrying about money spent on college sports was pointless because it's not going to stop. The better way to look at college sports is that they are entertainment, not academics and should all be moved to a new Department of Entertainment.
I couldn't agree more. College sports are big money entertainment and have nothing to do with academics. Certainly they have money spent on them well beyond their intrinsic value, but it's unclear if this money really takes away from what is available for academia. It may, but then again, it's quite possible that such money would only go to some other form of big entertainment if big name college sports didn't exist. If the commercial sports entertainment programs at colleges were distanced from academia, it might be possible for academic budgets to operate without any question of effect from sports.
I couldn't agree more. College sports are big money entertainment and have nothing to do with academics. Certainly they have money spent on them well beyond their intrinsic value, but it's unclear if this money really takes away from what is available for academia. It may, but then again, it's quite possible that such money would only go to some other form of big entertainment if big name college sports didn't exist. If the commercial sports entertainment programs at colleges were distanced from academia, it might be possible for academic budgets to operate without any question of effect from sports.
The World is Insane
How can we ever have a rational, safe, functional world when, in the 21st century, people are murdered for practicing sorcery? And how is it that some people seem to think that a tortured confession is worth something?
Friday, December 08, 2006
George Washington, Whiskey Maker
I was happily surprised to learn that George Washington was a distiller of whiskey in his later years. Even better, his distillery is being recreated.
Friday, October 06, 2006
Everyone is Always Offended
According to CNN, a "senior British Cabinet minister has sparked fury by saying that Muslim women who wore full veils made community relations more difficult." Apparently a lot of people are offended by his comments, but there is some truth in what he says. What about those who are offended by the veils? Why is offending them acceptable, but offending the wearers of the veils not acceptable?
Subscribe to:
Posts (Atom)