Its taking some kicking around, but here is the fruit of my labour… using core foundation over the RC bridge.



require 'osx/cocoa'

loginItems = OSX::CFPreferencesCopyValue(
      "AutoLaunchedApplicationDictionary", 
      "loginwindow", 
      OSX::KCFPreferencesCurrentUser, 
      OSX::KCFPreferencesAnyHost)

application_path = File.expand_path("~/path/to/your.app")
application_hidden = false

loginItems << OSX::NSDictionary.dictionaryWithObjects_forKeys(
    [ application_path, application_hidden ], 
    [ :Path, :Hide ])

# puts loginItems

OSX::CFPreferencesSetValue(
    "AutoLaunchedApplicationDictionary", 
    loginItems, 
    "loginwindow", 
    OSX::KCFPreferencesCurrentUser, 
    OSX::KCFPreferencesAnyHost)

OSX::CFPreferencesSynchronize("loginwindow", 
        OSX::KCFPreferencesCurrentUser, 
        OSX::KCFPreferencesAnyHost)

With any luck this might help someone :-)

I know, I know, I know - I just couldnt help myself but I needed to post about Lepoard!

It was a smooth upgrade on the whole, bar some funny issue with the DNS that couldnt resolve some external items; switching to openDNS worked like a charm.

Anyway, I wont bang on about time machine et al as thats been done to death!

Recently spatial calculations have fascinated me. Hardly what most people would consider fascinating, but hey!

Most of the modern enterprise (I use that term loosely as someone is bound to comment complaining that some of this list are not ‘enterprise’ enough) RDBMS have spatial GIS extensions. This allows them to conduct exteamly complex calculations about size, posistion and location in a three dimensional way – pretty freaking cool! Common databases that have GIS extensions are:

PostGRE – PostGIS

Oracle – Oracle spatial

DB2IBM Spatial

MySQL – MySQL spatial entensions

there are lots more… just google for your specific backend.

Anyway… for this article we’ll focus on PostGRE PostGIS, and running it on OSX.

Step 1

You will need to (download a whole bunch of frameworks from here)[http://www.kyngchaos.com/software/unixport/frameworks] and run the installer. That will give you some of the base libs and frameworks that PostGIS requires; such as GEOS, GDAL etc etc

Step 2

Add a new user on your system and make sure its short name is postgres – this is the user you will run the database server as. See below from my box:

Step 3

Download the latest PostGRE installer from here. This will load up PostGRE in /usr/local/pgsql; while your there i’d install the startup item so you dont have to load the server manually evertime you restart your mac.

Once installed you need to do some editing of the conf files. For me, I just needed a local development server, so I loaded up /usr/local/pgsql/data/postgresql.conf and changed the line

#listen_addresses = ‘

to

listen_addresses = ‘

This will ensure that our server binds to all the interfaces the box has. If you want to be more specific, just enter the IP of your machine.

Next, you need to edit the pg_hba.conf file to add a generic host like so:

host all all 0.0.0.0/0 md5

This lets anyone from any IP/subnet connect as any user. I must stress that this was for development purposes so you might want to be a bit more explicit for a production enviroment.

Step 4

Now you have PostGRE installed and configured, run the PostGIS installer – this will PostGIS to your install. We now need to create a new database and add the spatial extensions to it so that our querys will work… but before we can do that we’ll need to enable PL/SQL like so:

CREATE LANGUAGE 'plpgsql' HANDLER plpgsql_call_handler LANCOMPILER 'PL/pgSQL'

Then, from PgAdmin3, open the query tool, and browse to /usr/local/pgsql/share/lwpostgis.sql – run that query, and dont worry about the output (unless its an error!) and refresh the view in PgAdmin3, you should then see the functions list gone from 0 for 600+ – thats all your spatial extensions loaded up ready for use.

That should be it – check out Boston GIS for more on GIS querys and so on – its exteamly complex and out of scope for this article. Happy geocoding people….

Following on from setting up Django on your local system for dev purposes, I thought id just do an article about how to set up apache to use mod_python for when you want to roll your Django app out to the big bad world.

Before you start, you will NEED to have completed the other post about installing Django, as you need to have the mac python installer in and configured properly for this to work.

Step 1

First of all we’ve got to get Apache 2.2 working, as Apple only ship 1.3 with OSX (I wonder if this will change in Lepord? Lets hope so!). You can download the source here.

Extract the archive and cd into the new directory. We need to configure it with some options so that we have proxying (which you might want for rails etc) and just some other candy you might find usefull at a later date.

Set the CFLAGS:

export CFLAGS=”-arch i386″

Run this configure command:

./configure \
  --prefix=/Library/Apache-2.2.6 \
  -–enable-so \
  --enable-mods-shared=all \
  --with-mpm=prefork \
  --enable-dav \
  --enable-cache \
  --enable-proxy \
  --enable-shared \
  --disable-static \
  --disable-unique-id \
  --disableipv6 \
  --enable-logio \
  --enable-deflate \
  --with-ldap \
  --with-ldap-include=/usr/include \
  --with-ldap-lib=/usr/lib 
  --with-included-apr 
  --enable-ldap \
  --enable-auth-ldap \
  --enable-cgi 
  --enable-cgid \
  --enable-suexec

Let it do its business then run the usual:

make

then

make install (NB: we dont use sudo here as that way apache is compiled with permisions that let you edit the conf files and so on without needing to be an admin which is just ‘nicer’ for local dev)

Step 2

Configure your httpd.conf file as you see fit. I only really felt the need to change the following:

Change user and group to your user name (or any other one you want) Change ServerAdmin email to an appropriate one Uncomment “Include conf/extra/httpd-mpm.conf” Uncomment “Include conf/extra/httpd-default.conf” Add “NameVirtualHost *” for virtual hosting

My personal preference is then to have an “applications” folder in the apache conf dir, for which I then add a directive to httpd.conf to load in per-application virtual hosting configurations. It just keeps it nice and clean that way.

mkdir /Library/Apache-2.2.6/conf/applications

Include conf/applications in httpd.conf (in your httpd.conf)

Step 3

If you havent already, grab mod_python from here. Extract, it and cd into the directory.

You’ll then need to configure it with the following command:

./configure -–with-apxs=/Library/Apache-2.2.6/bin/apxs \
  -–with-python=/Library/Frameworks/Python.framework/Versions/Current/bin/python

Then do make and sudo make install

Provided you got no errors upon compilation, all should be well. You just need to add another line to your httpd conf:

LoadModule python_module modules/mod_python.so

Step 4

Poor yourself a nice cuppa!