gendocs

Autodoc is a great tool for automatic documentation generation for your clojure code (the clojure api itself uses it).

If you are using github-pages to publish the docs, here’s a simple little gendocs sh script to dump into your bin folder to do all the work in one go:

#!/bin/sh
 
if [ -d "autodoc" ]
then
echo "generating docs..."
lein autodoc
echo "pushing to github..."
cd autodoc
git add -A
git commit -m "Documentation update"
git push origin gh-pages
cd ..
else
echo "No autodoc dir!  Run this from your project"
fi

Upgrading postgres on Snow Leopard (Mac OS X 10.6)

Well, I too have gone down the rabbit hole of having to upgrade compiled-from-source apps to 64bit architecture after moving to Snow Leopard.  The hardest by far was postgres.  The sad thing is that 32bit version works just fine, but the adapter gems for rails don’t, hence the need for the recompile.

Mostly I followed this blog post, but it assumes that you had previously installed postgres using his instructions for Leopard which I hadn’t.

My previous installation was at /usr/local/postgres and these instructions end up installing it at /usr/local/pgsql, so my task also includes getting the data from my previous installation to the new on.

I also took some some hints from this post.

Here’s the blow by blow:

Make a backup of all my data from the 32bit version:

pg_dumpall > /tmp/32-bit-dump.sql

Switch to super user, make a directory for the source (if you haven’t already), download and extract it:

sudo su
mkdir /usr/local/src
cd /usr/local/src
curl -O http://ftp9.us.postgresql.org/pub/mirrors/postgresql/source/v8.3.8/postgresql-8.3.8.tar.gz
tar -zvxf postgresql-8.3.8.tar.gz
rm postgresql-8.3.8.tar.gz

Now configure, make and install it:

cd postgresql-8.3.8
./configure --enable-thread-safety --with-bonjour
make
make install

Then I followed the instructions from the above mentioned blog on how to make a postgres user, but I did them in a different terminal window because remember the other one we were logged in as root:

“First, you’ll need to find an unused user and group ID. Use the following commands to list the IDs for the users and groups on your system.”

dscl . -list /Groups PrimaryGroupID | awk '{print $2}' | sort -n
dscl . -list /Users UniqueID | awk '{print $2}' | sort -n

“For the purposes of this tutorial, let’s assume an ID of 113 for both the user and the group. Since the convention is to prefix system accounts with an underscore, use the following commands to create a user called _postgres:”

sudo dscl . create /Users/_postgres UniqueID 113
sudo dscl . create /Users/_postgres PrimaryGroupID 113
sudo dscl . create /Users/_postgres NFSHomeDirectory /usr/local/pgsql/
sudo dscl . create /Users/_postgres RealName "PostgreSQL Server"
sudo dscl . create /Users/_postgres Password "*"
sudo dscl . append /Users/_postgres RecordName postgres

“Then, create the _postgres group:”

sudo dscl . create /Groups/_postgres
sudo dscl . create /Groups/_postgres PrimaryGroupID 113
sudo dscl . append /Groups/_postgres RecordName postgres
sudo dscl . create /Groups/_postgres RealName "PostgreSQL Users"

So at this point the binaries are installed and there’s a user to run it under, but I needed to initialize a new database and copy back in my saved data. First create the data and log directories and set perms:

sudo mkdir /usr/local/pgsql/data
sudo chown postgres:postgres /usr/local/pgsql/data
sudo mkdir /usr/local/pgsql/log
sudo chown postgres:postgres /usr/local/pgsql/log

Then I logged in as the _postgres user:

sudo su
su - _postgres

And initialize database files and start up the database:

/usr/local/pgsql/bin/initdb -E UTF8 -D /usr/local/pgsql/data/
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data/ -l /usr/local/pgsql/log/postgresql.log start

Finally I restored the data from my initial pg_dumpall

/usr/local/pgsql/bin/psql -U postgres  -f /tmp/32-bit-dump.sql

I’ve also added these lines into my .profile to add the commands to my path and to simplify starting and stopping the database:

export PATH=$PATH:/usr/local/pgsql/bin
export MANPATH=$MANPATH:/usr/local/pgsql/man
alias pg_stop='sudo -u postgres pg_ctl -D /usr/local/pgsql/data stop'
alias pg_start='sudo -u postgres pg_ctl -D /usr/local/pgsql/data -l /usr/local/pgsql/log/posgtres.log start'

And then finally I could install the postgres rails gem (which was the whole point of this silly excercise):

sudo env ARCHFLAGS="-arch x86_64" gem install pg

wordpress update time & syntax coloring

So I’ve just spent a couple hours updating wordpress to 2.8.4 (it’s been a long time since I’ve done an upgrade) and I’m trying to pick from the myriad syntax coloring plugins.  I tried using SyntaxHighlighter Plus which has nicer configuration options. But it doesn’t look as good as wp-syntax

Note that to get the SyntaxHighlighter Plus configuration options to work on my php4 box (I was seeing this error: Call to undefined function: scandir()) I had to replace this call:

$themes = scandir(ABSPATH . PLUGINDIR . '/syntaxhighlighter-plus/syntaxhighlighter/styles/');

with this:

$dir = ABSPATH . PLUGINDIR . '/syntaxhighlighter-plus/syntaxhighlighter/styles/';
$dh = opendir($dir);
 while (false !== ($filename = readdir($dh))) {
$themes[] = $filename;
}

I actually like the way SyntaxHighlighter Plus works better than wp-syntax in that it uses a custom tag [sourcecode] rather than using <pre> which means that it handles embedded angle braces better. But I just think that it looks much worse than wp-syntax!

MacBook Pro trackpad clicking intermittently broken

So when I got my new MacBook Pro (late 2008 edition) with the fancy new trackpad that is an integrated mouse button, it had an incredibly annoying problem:  every 4th or 5th click, didn’t click!  So I’d be clicking on a window behind the current one, or clicking on an icon in the dock, and it would sometimes take two or three clicks to switch to the window or app.  After checking in with Apple (and unfortunately 2 hours on the phone walking through all sorts of different options), they ended up sending me out a new MacBook Pro.  The new one arrived yesterday and after a fairly straightforward migration (only the printer driver for my Canon MX850 didn’t automatically migrate), I now have laptop with a properly clicking trackpad.So, if you have this problem, you at least have my experience telling that it’s a hardware not a software problem.

git me some solutions

Well, git definitely takes some gitting used to.

My situation is using git with three team members and a private shared repository that we all pull from and push too.  Additionally our project has a submodule that lives on a public git-hub repository (metaform).

So here are some things I’ve learned:

  • Use rebase. Here’s how:
    1. Rebase doesn’t work on “dirty” working tree. So you must, either:
      1. Add and commit all you changes.git commit -a -m 'all my changes' (assuming that your ok committing them in a single batch). or
      2. Stash your changes awaygit stash (But don’t use stash if you have made changes in your submodule ! It’ll stash the changes away, but it gets very grumpy when unstashing later.)
    2. Fetch the changes:git fetch this should copy the changes from the remote branch (I assume your tracking the defaults here from the clone origin)
    3. Now to rebase: git rebase origin/master If you do a git log you should now see your checked in changes at the top of the tree, not somewhere near the bottom where they would be if you had just done a pull.
    4. If you stashed above, then you need to unstash with git stash apply
  • Submodules that are in active development can be a pain. Here’s a gotcha that gotme: When you have made a change to a submodule, checked it in and pushed it, you still need to add this change into your containing repository and commit that, and then do a git submodule update This is all well documented, but lets take a concrete example. My submodule is a rails plugin. So just after committing the change in my submodlue git status shows that vendor/plugins/myplugin is modified. So I use my shell’s file completion to add that folder. This gets me: git add vendor/plugins/myplugin/ notice the trailing slash. This is the gotcha. That causes git add to add all of the contents of the directory as if you wanted to track them directly instead of through the submodule. Erase that trailing slash!

ubuntu gutsy on a xen virtual host

Hey googlers looking for tech-support:

I was trying to install various packages (emacs, etc) from universe on Ubuntu Gutsy (7.10), and I kept getting weird segmentation faults (Setting up emacsen-common (1.4.17) Segmentation fault). Turns out that the problem was that my server was being hosted on a VPS running XEN for virtualization, and you have to first install libc6-xen: apt-get install libc6-xen

Hope this saves someone the half day that it cost me…