podcasting is about to happen

There’s a brilliant article by Rex Hammock over at rexblog.com entitled How Apple will change everything about Podcasting, #2 — How much could Howard Stern make podcasting via iTunes vs. broadcasting via Sirius?. The world of podcasting is about to leap out of the its small pond and into the ocean, or at least the Great Lakes, via Apple’s imminent integration of podcasting into the Apple iTunes Music Store. Disclosure: Rex uses my wife Candace’s podcast, The Nashville Nobody Knows, throughout the article, which only adds to the brilliance of the piece.

blognashville

Candace and I had a great time at Blognashville this weekend. It was very exciting actually. Attended by many blogosphere luminaries including, Glenn Reynolds, Dave Winer (creator of the RSS feed), Mark Glaser (main writer for Online Journalism Review), Bill Hobbs, Mark Tapscott (Director of Media and Public Policy at the Heritage Foundation), Dan Gillmor, Ed Cone, Henry Copeland of Blogads, and on and on. A bunch of very geeky, very smart, passionate, adventurous loudmouths. Candace got to say her piece at the podcasting discussion. We both did, but mostly her. And we got to hang out and drink wine at length with Mark Glaser and with Dave Winer, and had a great time talking to Brendan Greely, Mike Kelley, Jim & Lynnette Walczak, Mick Wright, Doug Petch, Nick Levay, and many others . It felt like the old days in what is now Silicon Valley, when microcomputers were young and still in the hands of the community of aficionados. It had that same nerds on acid buzz. Not to imply that anyone there really was on acid.

traversing directory trees in perl

I spent a whole day trying to traverse a directory tree using Perl, and grab all the directories that met certain criteria, and put them in an array. It sounds relatively simple, but it isn’t, and I got pretty frustrated. Finally I went to Google and typed in “perl traverse directory tree”. The first link that came up took me here. Lo and behold there is already a Perl module that will do it. The link has the info, but I still had to figure out how to use it for my own purposes. Here is some sample code that puts it into practice:

use File::Find;

sub traverse {
$options{‘wanted’} = &wanted; # this option specifies a subroutine to process the results.
$options{‘no_chdir’} = 1; # this option tells the module to not change the current default directory.
# there are many more options described in the link above.
find(%options, @accounts); # this command traverses the directories listed in the @accounts array.
# now you have a list of all the traversed directories, do what you want
foreach $dir (@directories) {
&doDirectory ($dir);
}

sub wanted {
local($file) = $File::Find::name;
if ( $file =~ /^\\./ ) { return; } # get rid of files or directories that begin with a period.
if ( (-d $File::Find::name) ) { # just grab directories, not files.
push @directories, $File::Find::name; # put them in an array.
}

That’s all there is to it.

bug in Sqlite

I highly recommend the marvelous, free, relational database engine Sqlite. It is not only free of a commercial license, it is also free of the restrictions imposed by the Free Software Foundation GNU GPL license, i.e., you can do whatever you want with it, incorporate it into your application, whether your app is free, or, dare I say it, costs money. However there is a bug, which I discovered recently. The ISNULL() function doesn’t work the way it is supposed to, or the way you would expect it to. If you have a field in your database file that may be NULL, and you want to do a select statement that substitutes some string (‘blah’) in the case where the field is NULL, you would expect to be able to do something like this:

SELECT field1,field2,ISNULL(‘blah’,field3) FROM tablename;

But that won’t work, because of the bug. Instead say this:

SELECT field1,field2,(CASE WHEN field3 ISNULL THEN ‘blah’ ELSE field3 END) FROM tablename;

And it will work exactly the way you expect it to. If field3 is NULL it will substitute the string ‘blah’. If field 3 is not NULL, it will select the contents of field3.

Cocoa, Objective-C, and Perl

All computer languages have their advantages and disadvantages. Perl is a great language for parsing and massaging text. If you are writing a Cocoa, Objective-C program, and you need to parse and massage text, you may want to hand that task off to some Perl code. This can be easily done. OS X comes with Perl installed, and you can have a Perl program as one of the resources in your Cocoa application. Following is some sample Objective-C code and Perl code that illustrates how to launch a Perl program that will write a temporary file that can then be read by your Objective-C code:

Here is the Objective-C code to set up and launch the perl program:

// define your temp file
FILE *fp;
NSMutableString *tmpPath = [[NSMutableString alloc] initWithString:@””];
[tmpPath setString:@”tempfilepath/tempfilename”];

// this is the path to your perl program
plPath = [thisBundle pathForResource:@”perlpgm” ofType:@”pl”];

// array to pass arguments to your perl program
NSMutableArray *argArray = [[NSMutableArray alloc] initWithObjects:plPath,tmpPath,nil];
// launch the perl program & wait for it to finish
[[NSTask launchedTaskWithLaunchPath:[NSString stringWithFormat:@”/usr/bin/nice”] arguments:argArray] waitUntilExit];

// open the temp file that has been written by the perl program
fp = fopen([tmpPath UTF8String], “r”);

// process the contents of the temp file here

fclose(fp);

// remove the temp file when you’re done
NSFileManager *manager = [NSFileManager defaultManager]
[manager removeFileAtPath:tmpPath handler:nil];

And here is what the code in your perl program will look like:

$tempFile = shift;
open ( TMPFILE, “$tempFile” ) || print STDERR “problem opening $tempFile\\n”;

# do your text massaging here and write the temp file.

close TMPFILE;

Of course you can also use STDIN and STDOUT if you don’t want to write a temporary file.

multiple causes of error

In my 35+ years of programming computers of all kinds, using many different computer languages, and developing many different kinds of applications, I have noticed a recurring phenomenon that, I believe, is a universal principle of the human psyche, which is to say, of reality.

When I’ve finished the code for a particular feature in a program, I always run the program to test it and make sure it works like it should. But something is wrong. Some error occurs. So I go back and pore over the code until I discover the error in logic that is obviously causing the problem. Then I run it again, and, lo and behold, the exact same error occurs. How can this be? I know for a certainty that the thing I fixed would cause this error, and I have fixed it, and the error continues to happen. Same error, different source of error. So I perform the same process over again. This happens so frequently, I have come to expect it. There is almost always another, completely unrelated, glitch in the logic of the program, that causes the exact same error. Often there will even be one or two more such completely unrelated bugs, all causing the same result.

This same circumstance arises in our lives. We have some recurring problem that keeps coming up. So, we get therapy or read a self-help book, or just engage in self examination, and Eureka! We discover what it is we are doing that is making this happen over and over. We change, we fix it, and we feel better. And it doesn’t make any difference. The problem, whatever it is, doesn’t go away. It continues to plague us. When this happens, it means there is some other, completely unrelated, twist in our soul that must also be untangled.

The universe is constructed of bits that can be either zero or one. At least that’s what Marvin Minsky believes. But it is an idea as old as the hills, that runs through all science and religion. Positive and negative, good and evil, male and female, yin and yang. The universe is composed of a duality of opposites, no matter what you call them. This means that the process of programming a computer, which is ultimately a manipulation of bits of information that can be either 1 or 0, is a mini version of the process of Creation itself. That’s why geeks find it so addictive. There is a God-like feeling to it.

Unfortunately, the lessons learned from programming computers don’t seem to make computer programmers any better at solving their own problems than anyone else. This is either because they don’t apply their skills to other aspects of their life, or because they do, but that only fixes one cause. There is something else being overlooked.

when good disks go bad

Recently the internal hard drive on my 3 year old iMac started getting trippy. I had to reboot more often, and when I did, the iMac wouldn’t reboot until I did a disk repair on the drive. The only way to do this, of course, is to boot from the original OS X install cd, run the Disk Utility, do a repair, and then restart. In order to do this I had to boot while holding down the mouse button so as to get the cd drive to open up, insert the OS X cd, shut down using the power button, and boot up again holding down the ‘C’ key so as to boot from the cd. I had to do this every time. This made me very nervous since I have over 30 gigabytes of applications and data on my hard drive that I didn’t want to lose. I would imagine that this is a problem that many iMac owners are already having, or will be having in the future, since hard drives have a finite lifespan.

So, here’s what I did to fix this problem. I have an external firewire hard drive, so I decided that the thing to do was to somehow clone my internal hard drive onto the external drive, and change the boot drive to the external drive. Here are the steps:

1. Download this most excellent utility Carbon Copy Cloner by Mike Bombich. This is a donation-ware program (uncrippled shareware) and it’s very very good. If you use it, send Mike a donation.

2. Make sure there is enough space on the external drive to contain a clone of the internal drive.

3. Set the preferences in Carbon Copy Cloner to “Repair permissions before cloning” and “Make disk bootable”. You may also want to check “Delete directories before overwriting”.

4. Set the source disk to your internal drive and the target disk to your external drive.

5. Click on the little padlock icon and enter your administrative password, and then click on the Clone button.

6. Carbon Copy Cloner will then create a carbon copy of your internal drive onto your external drive, without disturbing any other data you happen to have on the external drive.

7. Once the disk has been cloned, restart while holding down the option key. This will bring up a dialog that allows you to specify the startup disk. Choose the external drive.

That’s it. You now have a new startup drive and all of your applications and data have been saved. Once I had done this, after checking a bunch of things to make sure everything worked the way it should, I erased the internal hard drive, and have been using it for backups. It has not given me any trouble since I erased it. Another benefit of the switch is that my external firewire drive is twice as fast as the internal drive, so applications load much faster, and things in general are snappier.