a glob of nerdishness

July 25, 2007

Burn Spotlight index onto a DVD

written by natevw @ 8:30 pm

I’ve got a folder containing thousands of files, mostly PDFs and webarchives. I’d like to burn them on DVD so I can get them off my computer, but when I stick the disc back in I want to search them in a jiffy with the OS X Spotlight utility introduced in Tiger. Fortunately, it is possible to burn a Spotlight index onto a CD or DVD disc.

Create a disk image in Disk Utility

Open Disk Utility and make a “New Image” of appropriate size for what you intend to burn. The following instructions work with both “read/write” and “sparse” disk image formats. After Disk Utility creates the disk image, it will automatically mount it on your desktop, ready to use.

Copy files into the new image, leaving some space

Now you can fill your new image with the files you want to burn. But wait! Leave some space free for the index itself. My first test on about 250MB of PDFs and web files yielded about 12MB of data. Depending on how that scales, that could mean around 200MB for a DVD. This will vary based on what’s in your files, and Spotlight does seem to be able to prune its index to fit into lesser free space if necessary.

Use mdutil and mdimport to index disk

Open up Terminal for the juicy part of this whole how-to. Type sudo mdutil -i on , with a trailing space. Don’t hit enter just yet, there’s still one more piece to add. Let’s go over what we have so far first. To run Apple’s metadata utility, we need administrator rights, so we start with ’sudo’. (For more information about these tools, you can open a new Terminal window and type man sudo or man mdutil.) The ‘-i on’ tells mdutil to turn Spotlight indexing on for the path we’re about to add.

The easiest way to add the necessary volume’s path is to drag the mounted disk image icon (the white device with the slot on the front, not the document with the silver hard disk) into the Terminal window. You should end up with something like this: sudo mdutil -i on /Volumes/Image\ Name. Now you can hit return on this command, and enter your password to enable administrator rights.

To ensure that your disk image gets indexed right away you can should enter mdimport /Volumes/Image\ Name and then sudo mdutil -p /Volumes/Image\ Name. The first command forces an index-while-you-wait. The second makes sure the index data is actually on the drive.

Burn the disc

At this point you can unmount (eject) the disk image. If it’s not open anymore, open the image file (the one with the silver hard drive this time) with Disk Utility. Select the image file in the source list on the left, and click Burn. In a few minutes you should be enjoying a Spotlight indexed archive disc!

June 16, 2007

Global C++ Exception Handling

written by natevw @ 12:01 pm

It’s easy to handle uncaught exceptions at a global level in a C++ program. Most compilers, if not all, provide a function called std::set_terminate(). This lets you register a function that gets called when the program terminates unexpectedly due to an error. This function does not take any arguments, but can re-throw any current exception:


void catch_global() {
 try {
  throw;
 }
 catch (const YourPrintableException& e) {
  std::cerr << "Exiting due to error: " << e << std::endl;
 }
 catch (...) {
  std::cerr << "XQI ERROR -42: UNEXPECTED OCCURRENCE" << std::endl;
 }
 abort();
}

int main() {
 std::set_terminate(catch_global);
 if (true) throw "up";
 else return 0;
}

While this shouldn't replace good error handling practices throughout your code, it can be a handy way for your program to put some last words on the record before it kicks the bucket.

One disclaimer: I'm not completely sure that set_terminate() is an official part of the C++ standard. It's in Thinking in C++ but not the C++ FAQ-Lite, the big C++ reference or the light C++ reference. Official standard or not, it seems to be widespread. You can find documentation on set_terminate() via GNU, IBM or MSDN.

May 25, 2007

Apache-less SVN: Subversion between two Macs via SSH

written by natevw @ 6:55 pm

My first Mac, an original G4 mini, hasn’t seen much use since my new iMac arrived last summer. Hoping to start “spare-time” developing again, and now addicted to version control through work, I made it my goal one afternoon to get Subversion running between the old and the new. Eventually I’d like to expand this beyond source code to a home directory or even a .Mac backend, depending on what Leopard ends up offering.

Apple has an article on compiling a full SVN stack on OS X for use with Xcode. This looked a little bit more painful than I was aiming for, for some reason involving hand-patching Apache 2.0 and plenty of configuration. That route is spelled out nicely (1), but I wanted something even simpler.

Enter Martin Ott and his ready-made Subversion installer packages. Here’s how you can set up your own low-carb Subversion system, hopefully in less than 30 minutes.

Install SVN

Download the SVN package and install it on both your server and your client machines. It will ask you for your password, and then install several binary utilities in /usr/local/bin. This does not include any Apache modules but it does include a standalone daemon named ’svnserve’. This means no WebDAV access, but you can easily use svnserve with ssh to access your data securely across a network.

Configure paths

Unfortunately, programs in /usr/local/bin aren’t easily used by default. The next step is to get the utilities into your Terminal path. On your client machine, just add export PATH=$PATH:/usr/local/bin to your ~/.bash_profile file. For access via SSH to work, the server needs that same line but added the machine-wide /etc/bashrc configuration instead of your user’s profile. For this, you will need administrator privileges, something like sudo pico /etc/bashrc should do the trick. (Alternatively, you could cd /usr/bin/; sudo ln -s /usr/local/bin/svnserve to avoid editing bash’s global configuration. In this case, also configure your user account on the server just as you did the client, because in the next step we use another utility via that path.)

Make a repository

The repository is where all your past and present data will be stored on the server, accessed via the SVN tools. Pick a spot where you don’t mind an extra folder sitting around, and execute on the server machine: svnadmin create ~/repository. Feel free to change the path, as given it will make a new “repository” directory in your home folder and fill it with files. These internal files should generally not be used directly, we’ll test the SVN commands in the next step.

Accessing the repository

Make sure you have “Remote Login” enabled in System Preferences > Sharing on the server machine. If not, enable it, and you should be ready to go back to the client machine. “Check out” your new (empty) repository with this command: svn checkout svn+ssh://your-machine-name.local/Users/yourname/repository new_local_folder. After giving your ssh password a few times, you should find “new_local_folder” copied into the current path.

Beyond…

If you’re not familiar with SVN commands themselves, the maintainers provide a top-notch Subversion Book that is both tutorial and reference. Also by now, you’re probably sick of typing your ssh password. You can improve this by using authorized keys and ssh-agent. The previously linked Apple article finishes with a section titled “Xcode and Subversion”, though there might be an incompatibility between Xcode and the latest SVN software. Let me know how it goes if you make it that far, or get stuck along the way!


  1. Unlike the error messages from Fink trying to update a previous Apache2/SVN install. I gave Fink the ‘rm -rf /sw’ treatment, and now I feel better.

May 23, 2007

Xcode Regular Expression replacement

written by natevw @ 7:55 pm

Thanks to “Search and Replace in Xcode” at Noodlesoft’s blog, I learned how to use RegEx grouping in Xcode’s Search and Replace. In short: \1 instead of $1. Now I can convert the wiki-formatted tables of Kyōiku kanji into a Quisition flash card pack.

February 10, 2007

Overzealous iTunes podcast organization

written by natevw @ 5:34 pm

My iTunes library seems to collect all sorts of media from all sorts of places. I try to keep it fairly clean, so when I noticed I had a number of neglected video podcasts I set to work. Some video podcasts weren’t interesting enough to warrant keeping around, and some weren’t actually podcasts but rather one-off files packaged in feeds anyway. For example, I had downloaded Rob Carlton’s dry and witty “CARMICHAEL & shane” via an sidebar-ed iTMS link. I wanted this file to show up as a nice thumbnail in the “Movies” section, instead of being nested under “Podcasts”. So I dragged the file to another folder, deleted the podcast, and re-imported the video file into iTunes — only to find it back where it started, under podcasts again!

Long story (including a trip into Hex Fiend to replace all instances of “podcast” into “nodcast”) short, it turns out the Quicktime container that it was in (.mp4/.m4v) contains a bit of metadata which flags the file as a podcast, and another piece containing the feed URL. Lostify does not (yet, anyway) have a way to change these flags, but its underlying utility, AtomicParsley, does. A quick AtomicParsley VideoName.mp4 --podcastFlag false in Terminal, a little time spent thinking, and it spit out a second file with a random “-temp-12345″ infixed into the name. Voilà! “CARMICHAEL & shane” is now a first class movie!

« Previous Page