aaron.harnly.net

The Future Is Now: Treasures in the Carbon docs

February 10th, 2008 by aaronharnly

Ran across these funny notes in the Carbon documentation:

This warning that “The Future” could arrive any day:

Important: In the future, individual application processes may not always share the same address space, so in general you should never attempt to access code or data in another process.

and this one is just precious:

Note: Because multitasking allows an operating system to attend to several different operations at the same time, these operations may appear to occur simultaneously on even a single-processor system, due to the speed of the processor.

You don’t say.

TextMate bundle for Scala

April 25th, 2007 by aaronharnly

I’ve put together a stub of a TextMate bundle for Scala.

At the moment, it just contains a bare-bones language definition, a template for Ant tasks, and a couple of snippets. I’d like to keep improving it, and would welcome suggestions and modifications.

I’ll be setting up anonymous SVN access one of these days (yeah, right), but for the moment, you can download the bundle directly:

ScalaAWH.tmbundle.zip

Sharing the wealth: My dotfiles

March 26th, 2007 by aaronharnly

It is the fashion these days to share your .bashrc, so I thought I’d do so.

Here is my .bashrc in all its glory.

And here is a typical prompt it produces:

The first little box there just displays the login information — whether I’m local or remote, and from which host. That’s handy if I’m bouncing between servers and have forgotten whether I’m connected to machine C via machine B, or directly from A, etc.

Also of interest there is an updated version of this MacOSXHints.com suggestion of mine, which lists available GNU screen sessions.

Some other little functions I use daily are pathappend, pathprepend, and try_export, which simply add a directory (if it exists) to the beginning or end of a given env variable, usually $PATH.

So, for example, I have these lines:

path_prepend $HOME/software/crossplatform/bin
try_export "/usr/local/java/java1.5" JAVA_HOME
try_export "/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Home/" JAVA_HOME

which I think makes for a much tidier way to conditionally set a variable depending on which platform I happen to be logged into. IMHO.

Anyway, enjoy.

Using snippets in Textmate templates

March 19th, 2007 by aaronharnly

Pursuant to the post below, I found myself creating a simple Scala bundle for Textmate, as there isn’t one at the moment. (Getting in on the ground floor!)

The Textmate snippet system is a wonderful creation — simple, delightful, and helpful. Unfortunately, the templating system is not nearly so nice — just a Perl one-liner to substitute in some environment variables, and no snappy tab-tab autofill magic.

Then I ran across this great post by Henrik Nyh, in which he scrapes together a little Applescript to create a Textmate template as a snippet.

However, I found myself wanting both some templated boilerplate, with variable substitution, and some snippetized text below. This proved a little trickier than I first thought, since the Applescript inserts at the top of the document, and it would require a nasty keypress script to insert the snippet below.

So, I came up with a slightly modified version of Henrik’s system, which supports a template_in.txt file with the usual variable substitutions, as well as a snippet below.

The template script looks like this: if [[ ! -f "$TMNEWFILE" ]]; then TMYEAR=date +%Y \ TMDATE=date +%Y-%m-%d \ TMUSERNAME=niutil -readprop / /users/\$USER realname \ TMTEMPLATEOUTPUT=$(mktemp “/tmp/tmtemplate_XXXXXX”)

perl -pe ’s/\${([^}]*)}/$ENV{$1}/g’ \ < templatein.txt > “$TMTEMPLATE_OUTPUT”

touch “$TMNEWFILE”

{ # Insert the template & snippet!
osascript "${TM_BUNDLE_SUPPORT}/load_snippet.scpt" "$TM_TEMPLATE_OUTPUT" "snippet.txt" 
} &>/dev/null &

fi

and the Applescript is modified to this: on run args set templateoutputfile to (item 1 of args) set snippet_file to (item 2 of args)

-- retrieve the template and snippet text
set existing_text to read (POSIX file (template_output_file)) as «class utf8»
set loaded_snippet to read (POSIX file (snippet_file)) as «class utf8»

-- insert both into the document
tell application "TextMate"
    insert existing_text
    insert loaded_snippet with as snippet
end tell

-- remove the temporary file
do shell script "rm \"" & template_output_file & "\""

end run

You can download Snipplate2 (AWH) here.

List all application versions

March 12th, 2007 by aaronharnly

Here’s a nice little one-liner for listing the current version and installation date of every application on your OS X system, using the wonders of Spotlight:

mdfind “kMDItemKind == ‘Application’” | perl -ne ‘chomp; print “\”$_\”\n” ‘ | xargs mdls -name kMDItemFSContentChangeDate -name kMDItemVersion -name kMDItemDisplayName -name kMDItemPath | perl -pe ’s/^\/.+/”-” x 20/e’

Sample output:

kMDItemDisplayName         = "MarsEdit.app"
kMDItemFSContentChangeDate = 2006-03-13 22:58:25 -0500
kMDItemPath                = "/Applications/3rdPartyApps/Write/MarsEdit.app"
kMDItemVersion             = "1.1.2"
--------------------
kMDItemDisplayName         = "OmniWeb.app"
kMDItemFSContentChangeDate = 2007-02-14 17:23:51 -0500
kMDItemPath                = "/Applications/3rdPartyApps/Connect/OmniWeb.app"
kMDItemVersion             = "5.5.4"
--------------------
kMDItemDisplayName         = "CandyBar.app"
kMDItemFSContentChangeDate = 2006-04-14 18:40:52 -0400
kMDItemPath                = "/Applications/3rdPartyApps/Tinker/prettify/CandyBar.app"
kMDItemVersion             = "2.6.1"
--------------------
kMDItemDisplayName         = "Vienna.app"
kMDItemFSContentChangeDate = 2007-01-27 13:38:17 -0500
kMDItemPath                = "/Applications/3rdPartyApps/Connect/Vienna.app"
kMDItemVersion             = "2.1.1.2109"

Triple-Quote to use a shell variable in awk

March 12th, 2007 by aaronharnly

Just a little note: Found myself wanting to print a shell variable as part of an ‘awk’ one-liner, but found it rather surprisingly difficult. Here’s the magic tickle required:

x="foo"
awk '{ print "'"$x"'" }'

That’s a ” followed by ‘ and then another “.

For the curious, the actual script was a one-liner for dumping out Mac OS X application version information:

for x in /Applications/*.app 
do mdls $x | awk -F \" '/kMDItemVersion/ { print "'"$(basename $x)"'", $2 }'
done

cheers.

A Widget-Toot

May 24th, 2005 by aaronharnly

So thanks to that widget-post below (or actually the original page here), yours truly found himself mentioned at length in this Boston Globe article condemning Apple for its security slipup. Both the true discoverer of the flaw, Stephan.com, and this elaborator upon its implications are quoted, though despite my protestations, my nom de birth rather than this nom de guerre is used.

Read the rest of this entry »

machine_info.pl: Getting your bearings on a new machine

May 10th, 2005 by aaronharnly

Continuing the spate of brain-dumps of scripts I use often, this is a favorite: machine_info.pl

I’m often hunting around for machines to run jobs on, and so log into a bunch of different machines to find one well-suited to my task. So when I log into a machine, I often want to get a quick sense of its capabilities. I got tired of trying to remember that Solaris uses /usr/sbin/psrinfo, while Linux uses /proc/cpuinfo, and which lines to grep for in each. So I wrote this script.

I also find this script handy for my duties as part-time administrator; it helps me keep tabs on which machines we’ve upgraded to how much RAM, etc.

Read the rest of this entry »