Monthly Archives: July 2008

Oakland to Yosemite

Google Maps provides a route from the San Francisco Bay Area to Yosemite National Park which runs along 580 to Highway 120. I find this route to be intolerably populated, unattractive, and often ground to a stop due to accidents or sheer traffic volume.

On a recent drive back, when I found traffic along 580 into Tracy at nearly a standstill, I cut north through the Delta and up to Concord. The contrast between the packed 580 versus the desolate back-roads was amazing.

Earlier, when Highway 120 led into Oakdale, I found that by cutting a single street North yielded a road which was almost entirely unused, had only the occasional stop sign, and featured beautiful views of fields and smelled of grass and cows instead of exhaust fumes.

According to Google Maps estimates, the standard 580/120 route only saves around 40 minutes versus a much more leisurely, scenic, and enjoyable route along Highway 4:

Posted in Backpacking, Climbing, Travel | Leave a comment

Weirdness With Echo and Parentheses Within Conditional Statements

The if command in Windows batch files has some strange implications. One problem is that parentheses take on special meaning.

I first ran into this problem because my batch file would terminate shortly after showing, “folder unexpected at this time“.

A very basic if command might look like this:

C:\>if exist C:\ ( echo The C drive exists )
The C drive exists

However, placing parentheses inside the echo statement will entirely confuse CMD:

C:\>if exist C:\ ( echo The C drive exists (no, really) )
) was unexpected at this time.

Well, that sort of makes sense. It becomes confusing when the last word in your echo command is something more general, like the word ‘folder’:

C:\>if exist C:\Windows ( echo Found the Windows (on C:) folder )
folder was unexpected at this time.

This is actually the classic %%i was unexpected at this time error.

One solution is to put double quotes around the message to be echoed:

C:\>if exist C:\Windows ( echo "Found the Windows (on C:) folder" )
"Found the Windows (on C:) folder"

The drawback here is that the double quotes appear in the output. A better option is to use the caret (^) escape character:

C:\>if exist C:\Windows ( echo Found the Windows ^(on C:^) folder )
Found the Windows (on C:) folder
Posted in Technology | Leave a comment

Organizing Files by Date Using Find

I had taken pictures using a friend’s SD card. He copied all the files to my flash drive, but this left me without a nice, tidy directory structure. Normally, I organize my photos like:

2008
   2008_06_27
   2008_06_28
   2008_06_29

First off, I needed to list the files by date:

ls -lt

This showed me that I had files from the 27th, 28th, and 29th in a single directory. So I created a directory for each date.

Next, I used find with the -newer and -exec switches to execute a move command on each file newer than a particular file.

By looking at the ls -lt output, I found the last photo taken on each day. IMG_6369.JPG was the last taken on the 28th, and IMG_6284.JPG was the last taken on the 27th.

To move all of the files taken on the 28th and 29th, I used this command:

find . -type f -newer IMG_6284.JPG -exec mv {} 2008_06_28 \;

Now, all files taken after the 27th are located in the 2008_06_28 directory. Now, I change into that directory, and execute:

find . -type f -newer IMG_6369.JPG -exec mv {} ../2008_06_29 \;

Now I’m left with all the photos from the 27th in the main directory. Those could easily be moved with:

find . -maxdepth 1 -type f -exec mv {} ../2008_06_27 \;

I’m sure there is a quicker, cleaner way to do this, but for the limited number of subdirectories I had to filter into, this was reasonably efficient.

Posted in Scripting, Technology | Leave a comment

Extracting a Version Number From a Text File Using Batch Files and Cygwin

We have a version.h file. It contains lines such as:

#define VERSION_MAJOR     3
#define VERSION_MINOR     1

By piping this through grep, I can get the line I’m looking for:

c:\>grep "VERSION_MAJOR" version.h
#define VERSION_MAJOR     3

But what I really want is the version number within the line, so I pipe this through sed:

c:\>grep "VERSION_MAJOR" version.h | sed -e "s/^.* VERSION_MAJOR\s*\([0-9]\+\)/\1/g"
3

So now we have extracted the version number corresponding to “VERSION_MAJOR”. However, in order to conditionally branch in our batch script, we need to get this value into an environmental variable. In bash, this would be accomplished with backticks. As it turns out, Windows batch files do provide similar functionality, but through a much clumsier means:

c:\>for /f "tokens=3" %i in ('grep " VERSION_MAJOR" version.h') do set MAJORVERSION=%i
c:\>echo %MAJORVERSION%
3
Posted in Scripting, Technology | Leave a comment

Installing Graphviz Dot Without Root Access

I want to install Graphviz on a machine in order to get access to the dot diagram generator. However, I don’t have root access on this box, so I want to install it in my home directory, under ~/bin/graphviz. To do this, call the configure script with a few arguments to change the installation directory:

./configure --exec_prefix=$HOME/bin/graphviz/ --mandir=$HOME/man \
--prefix=$HOME/bin/graphviz/

Then make, and install:

make
make install

Even though make install gives me an error, “/usr/bin/ld: cannot find -lperl“, I find that Graphviz now appears under ~/bin/graphviz:

ls ~/bin/graphviz/
bin/  include/  lib/  share/

On a different box, I was unable to get this far. I received this error:

libtool: install: error: cannot install `libgraph.la' to a directory not ending in /usr/local/lib

This is caused by an out-of-date libtool.

libtool --version
ltmain.sh (GNU libtool) 1.4 (1.920 2001/04/24 23:26:18)
Posted in Technology | 3 Comments

Linking to XML Stylesheet Stored on Local Server in Firefox

Problem

I created an XML stylesheet which I wanted to place on a local Samba share. In the XML file to be transformed, I placed a file:// URI in the xml-stylesheet tag, but it wouldn’t work in Firefox. Internet Explorer would happily format the content as expected, but Firefox simply displayed a rather uninformative error:

Error loading stylesheet: (null)

Cause

As it turns out, I was formatting the URI incorrectly.

Solution

Proper URI formatting for the file protocol requires three slashes to establish an empty authority or host segment, followed by the full path, with all backslashes converted to forward slashes. Since it was a path to a file on a local Samba server, which normally begins with two backslashes, this means I needed a total of five forward slashes following file:!

So, given a Windows-style path such as:

\\myserver\mypath\mystylesheet.xslt

The corresponding URI would be:

file://///myserver/mypath/mystylesheet.xslt

Yielding an xml-stylesheet tag like

<?xml-stylesheet type="text/xsl"
                 href="file://///myserver/mypath/mystylesheet.xslt">

Reference

MozillaZine: Links to local pages don’t work

Posted in Technology | Leave a comment