Leopard Weblog Needs MySQL

I suppose most people would know this, but I didn’t: if you turn MySQL off, Leopard weblogs stop working. During a review of what was going on with my Leopard OS X Server, I found that MySQL was running. Thinking “I don’t use MySQL for anything,” I turned it off.

Fortunately for me, I needed to access a note here a couple of days later, but was greeted with a “Service Not Available” error. A couple of moments later I recalled that I had just turned MySQL off, so I turned it back on. Still no weblogs. Stop/Start the web server and Leopard put up a very helpful dialog, informing me that there may be firewall issues. A quick trip to the firewall settings and now I know: turning MySQL on via the “Select the services to configure on this server” list in the main server settings window does not reopen the necessary firewall port.

Date Unknown (June 1, 2010)

google_pluslinkedingoogle_pluslinkedinby feather

Setting Up Ruby on Snow Leopard Server

I had the opportunity to configure a new Snow Leopard Server for a customer who is running a Ruby application. Despite Apple’s claim that Snow Leopard Server is ready “out of the box” it turns out it isn’t quite “all” ready. Below are the extra things I had to do. Special thanks to Ryan Wilcox (Wilcox Development) who found the pertinent Apple KnowledgeBase page.

  1. Visit http://support.apple.com/kb/TA25017 (MySQL header files available for download)
  2. Follow the link to the current header files
  3. Download the MySQL binary. Here the instructions on Apple’s page (for Leopard) fall apart. Since Snow Leopard automatically un-zips the download, all you have to do now is:
  4. sudo tar -zxvf <downloaded_file> -C /

That did it.

Not quite. Later on I got word that a ‘migrate.db’ failed. Searching about found this page from TechLiberty and this page from rubyonrails.org — both provide useful information buried in stuff I didn’t need, as they are dealing with the ‘regular’ version of Snow Leopard.

Bottom line: MySQL has to be installed as a 64-bit application. On Snow Leopard Server, the magic incantation is:

sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/bin/mysql_config

(Note the path to mysql_config is different than those pages; this is the ‘server’ difference.)


Another very nice thing Ryan showed me was the Unix “Locate” command. But first you have to build the locate database by issuing this command:

sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist

The complete archive of the iChat between Ryan and myself is found in the iChat transcripts and in the “Internet related” folder on my main machine.

And the ‘locate’ database is rebuilt nightly, so don’t expect real-time updates.

May 27, 2010 12:52 PM

google_pluslinkedingoogle_pluslinkedinby feather

AppleScript Opaqueness in InDesign CS3

I was scripting InDesign CS3 and wanted to show what was happening on screen. How to do this is quite opaque and took me about an hour to figure out. Here it is:

tell application "Adobe InDesign CS3"
  set myWin to (layout window 1)
  set targetSpread to (parent of parent of theOrderHeader) -- spread -> page -> text frame
  tell myWin
    set active spread to targetSpread
    zoom myWin given fit spread
  end tell
end tell

In this sample, ‘theOrderHeader’ is a text frame that was just updated.

There must be a better way to do this, but whatever it is, it eluded me.

Mar 6, 2010 12:32 PM

google_pluslinkedingoogle_pluslinkedinby feather

AppleScript Speed Stunner: Round vs. Mod & Div

I was working on a routine the other day and, quite by accident discovered that the round() function is extremely slow. How slow? Compared to a routine that uses DIV and MOD functions, round() is significantly slower.

Here’s my Timing Test script, fitted with two different ways to round the results of a division to the nearest integer:

set theDivisor to 256
set theLoopCount to 20
set {theDividendStart, theDividendStop} to {120, 130}
 --bracket values around tipping points to show equivalent results

set t1 to the ticks
repeat theLoopCount times
    set resA to {}
    repeat with theDividend from theDividendStart to theDividendStop
        set theQuotient to round (theDividend / theDivisor)
        copy {theDividend, theQuotient} to end of resA
    end repeat
end repeat

set t2 to the ticks
repeat theLoopCount times
    set resB to {}
    repeat with theDividend from theDividendStart to theDividendStop
        if ((theDividend mod theDivisor) > (theDivisor div 2)) then
            set extra to 1
        else
            set extra to 0
        end if
        set theQuotient to (theDividend div theDivisor) + extra
        copy {theDividend, theQuotient} to end of resB
    end repeat
end repeat
set t3 to (the ticks) - t2

set {LoopA, LoopB} to {(t2 - t1) / theLoopCount, t3 / theLoopCount}
get {LoopA, LoopB, LoopA / LoopB, resA, resB}

On my old G4/733, round() is about 30 times slower.

There is even more of a disparity when you add “Rounding up|down” to the mix. The code for rounding up:

set theDivisor to 256
set theLoopCount to 100
set {TheDividendStart, theDividendStop} to {250, 260}

set t1 to the ticks
repeat theLoopCount times
    set resA to {}
    repeat with theDividend from TheDividendStart to theDividendStop
        set theQuotient to round (theDividend / theDivisor) rounding up
        copy {theDividend, theQuotient} to end of resA
    end repeat
end repeat
set t2 to the ticks

repeat theLoopCount times
    set resB to {}
    repeat with theDividend from TheDividendStart to theDividendStop
        if ((theDividend mod theDivisor) = 0) then
            set extra to 0
        else
            set extra to 1
        end if
        set theQuotient to (theDividend div theDivisor) + extra
        copy {theDividend, theQuotient} to end of resB
    end repeat
end repeat
set t3 to (the ticks) - t2

set {LoopA, LoopB} to {(t2 - t1) / theLoopCount, t3 / theLoopCount}
get {LoopA, LoopB, LoopA / LoopB, resA, resB}

And rounding down is even simpler:

set theDivisor to 256
set theLoopCount to 100
set {TheDividendStart, theDividendStop} to {250, 260}

set t1 to the ticks
repeat theLoopCount times
    set resA to {}
    repeat with theDividend from TheDividendStart to theDividendStop
        set theQuotient to round (theDividend / theDivisor) rounding down
        copy {theDividend, theQuotient} to end of resA
    end repeat
end repeat

set t2 to the ticks
repeat theLoopCount times
    set resB to {}
    repeat with theDividend from TheDividendStart to theDividendStop
        set theQuotient to (theDividend div theDivisor)
        copy {theDividend, theQuotient} to end of resB
    end repeat
end repeat
set t3 to (the ticks) - t2

set {LoopA, LoopB} to {(t2 - t1) / theLoopCount, t3 / theLoopCount}
get {LoopA, LoopB, LoopA / LoopB, resA, resB}

In these tests, Round() rounding up|down runs about 50 times slower than the same function written with DIV and MOD.

At this point I am curious about two things. First: is round() any faster on Intel? Second: what sort of timings would you get for equivalent routines written in C (or its variants)?

Apr 18, 2009 1:00 PM

google_pluslinkedingoogle_pluslinkedinby feather