Getting PostgreSQL Running on OS X 10.6

So…

I’m getting ready to deploy some new web applications and, normally, I’d just go ahead and use the installed mySQL server on our CentOS based servers and that would be that.

Except that we’re not going to be running on one of those…

So I figured I’d take some time to just install PostgreSQL.

That turned out to be pretty darn slick.

Get the binary installer from here, run the installer, and voilà!

After installation, it brings you to an installer that will let you install a few handy add-ons like a full Apache 2.2.x, Drupal, ODBC and JDBC drivers, some performance tuning tools, replication, and such.

I used the installer to install Apache 2.2.14 (latest stable 2.2 branch), Drupal, phpPgAdmin 4.2.2, and the JDBC driver. Damn handy, that.

One small wrinkle that I’ve not quite worked out but have worked around.

When you install phpPgAdmin, the postgres (root) user is not allowed to log in so you have to go into the config file way the heck down in:

/Library/PostgreSQL/EnterpriseDB-ApachePhp/apache/www/phpPgAdmin/conf

and tweak the:

 $conf['extra_login_security'] = false; #  true;

setting to false from true.

Then you can login with the postgres user. To add users, just go into the pgsql command, using the postgres user.

There are some more fun things to do at the Apple link for PostgreSQL which I’ll get to later.

To get the Python driver recommended for use with Django, I went to the ugly site pointed to by the Django documentation. Not sure what’s up with that.

Anyway, that’s what it took, I’ll write more after I do a bit more poking around…

Getting Validator S.A.C. Running Under Snow Leopard

I’m using the Validator quit a lot lately, for reasons which will become apparent soon enough.

In order to run the stand-alone validator on an OS X machine, just download from the link above, and install the app normally.

Open it up, and you’ve got a validator right there on your computer that works much faster than the online one, and it can also validate local files (as long as they’re straight HTML).

The other cool thing you can do, is set it up to respond to local requests via the Web Service API.

To do this, you just have to leverage the Apache already running on your machine by following the instructions right on the home page. The instructions for 10.5 worked in 10.6 for me:

 # cd /Applications/Validator-SAC.app/Contents/Resources
 # sudo cp validator/httpd/conf/validator-SAC-10.5.conf /etc/apache2/other
 # sudo apachectl graceful

After that, a quick test using curl proves that the install is working:

 # curl http://localhost/w3c-validator

And out comes the HTML for the validator homepage (which I’ve given up trying to get MarsEdit to allow me to show any of in this document).

At any rate, you can now use the validator right on your machine without hitting the net except for getting the page to validate.

Cool!

JavaScript Command Line Shell OS X

So…

I was writing a whole bunch of JavaScript recently and was getting incredibly tired of having to refresh the browser to see if things were working.

Yes, I have FireBug and such but what I really want is a command-line JavaScript interpreter like my iPython.

To make a long story short, none of the instructions I found for building SpiderMonkey worked on OS X and I couldn’t find a binary so I went to plan B: Rhino.

Download and unzip. What you’ll get is a directory named `rhino1_7R2`.

So, once you have that, just go get jLine. It’s a single .jar file, stick that into your `rhino1_7R2` directory. Mine is named `jline-0_9_5.jar`.

Make sure you’re in your `rhino1_7R2` directory where you should see something like this if you do an `ls`:

(~/rhino1_7R2)# ls *.jar
-rw-r--r--@ 1 ssteiner  staff    46424 Dec  6 09:00 jline-0_9_5.jar
-rw-r--r--  1 ssteiner  staff  1164702 Mar 22  2009 js-14.jar
-rw-r--r--  1 ssteiner  staff   871260 Mar 22  2009 js.jar

then type the oh-so-completely-obvious command:

(~/rhino1_7R2)# java -classpath js.jar:jline-0_9_5.jar jline.ConsoleRunner
 org.mozilla.javascript.tools.shell.Main

You’ll see the `js>` prompt and there you are; a full JavaScript command line to try things out in.

I got some great help from this article when I was first starting this exploration and he goes into mixing Java and JavaScript code a little bit which is of no interest to me, at this point.

Sure is nice to have a command line to whack around to try out regular expressions and such though…

How to find open files on a volume

This shows what files are open on volumename.

Handy if you’re trying to unmount volumename and it won’t unmount due to open files.

	# sudo lsof | grep /Volumes/volumename

TextMate Trim Trailing Whitespace, Finally!

I’ve been using TextMate for several years now and it has always annoyed me that it doesn’t have a way of automatically trimming trailing whitespace on save.

I tried the instructions in the documentation, and found another reference to the same ruby method on another blog but they only worked once. The second time I tried to save the file, I got a ruby traceback:

OSERROR: -10000
MESSAGE: Apple event handler failed.
COMMAND: app(”/Applications/TextMate.app”).documents[0].save({:in=>MacTypes::Alias.path(”~/file_that_has_changed_in_textmate”)})
from /opt/local/lib/ruby/gems/1.8/gems/rb-appscript-0.5.1/lib/appscript.rb:642:in `method_missing’
from strip.rb:16:in `save_current’
from strip.rb:26

Apparently some other people did too and the blogger said he’d look into it but that was in December of 2008 and he’s never posted a solution, nor have I found one elsewhere.

Finally, I found this simpler, but less obvious way to accomplish the same thing and it works like a charm.

Yay!

Compress .sparseimages

I use SuperDuper! to make sparse image backups of all of my physical hard drives.

Only thing is that, even if you clean up a hard drive so there’s less to backup, the .sparseimage files never shrink to reflect the reclaimed space.

To reclaim space, just make sure the image is not mounted, pull up a terminal window, and:

hdiutil compact /the/path/to/your.sparseimage

This will squish all the air out of the sparseimage bundle.

Make a backup first, obviously, and make sure there's enough room on the drive to make a copy of the image since I'm pretty sure it works by making a copy, then deleting the original.

Transmit Favorites

I was working on syncing my laptop with my desktop in a ‘deeper’ sort of way this morning as things have gotten a bit random with all the new apps I’ve been installing (1Password rocks!).

I went into the .Mac sync panel (MobileMe just makes me want to puke) and the Transmit favorites weren’t there to sync.

A quick visit to the Panic site yielded this:

I no longer use Transmit. How can I remove Transmit from my .Mac Sync preferences?
Awkwardly, Apple doesn’t provide a way to remove these items. But, if you’re running Transmit 3.5.1 or newer, type this into Terminal:

# ~/Library/Application\ Support/Transmit/TransmitSync.app/Contents/MacOS/TransmitSync --unregisterClient

That should remove Transmit from the list.

Well, I figured that, since I had the opposite problem, I should just remove the ‘un’ from the –unregister… and that’d do it.

Did. Yay.

Setting up Perforce command line

Set up your client (Mac OS X)

If you’ve been following along, you’re running a publicly accessible server

To set up the client on your local machine (mine’s OS X).

Add the following lines to the end of .bash_profile.

# Perforce Settings
export P4PORT=yourdomain.com:1666
export P4CLIENT=a_workspace_you_ve_set_up
export P4USER=your_user_name

Quit and restart terminal and type p4.

You shouldn’t get any errors, just a helpful list of commands you might want to use.

Mac OS X Conveniences

These are a few of the things I’ve installed on my desktop and laptop that I consider pretty indispensable.

  • Firefox
  • ExpanDrive
  • TextMate
  • Transmit (though much less used since ExpanDrive)

Essential add-ons: