Archive for the 'solutions' Category

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…

rails capistrano deploy script OS X to Ubuntu

Ok, so in a previous post I described the rabit-hole which is switching to rails. Below’s my capistrano deploy script which solves a number of problems:

  1. The production server needs a mongrel cluster configuration file added.
  2. Deployment requires restarting the mongrel cluster.
  3. On Ubuntu the database.yaml spec has to be modified to because you need to specify a mysql socket path differently from OS X.

So here’s what I added to make it work:

desc "Restart the web server and mongrel cluster"
 
task :restart, :roles =&gt; :app do
  sudo "echo 'fish'" #bogus command to make sudo work in the run command
  run "cd #{current_path} &amp;&amp; sudo mongrel_rails cluster::restart"
  sudo "/usr/local/apache/bin/apachectl graceful"
end
 
desc &lt;&lt;-DESC
configure the mongrel cluster
DESC
 
task :configure_mongrel do
  run "cd #{current_path} &amp;&amp; mongrel_rails cluster::configure -e
  development -p 9000 -a 127.0.0.1 -P #{shared_path}/pids/mongrel.pid
    -c #{current_path} -N 2 --user om --group om"
end
 
desc &lt;&lt;-DESC
configure the mongrel cluster
DESC
 
task :configure_database do
  db_config = "#{shared_path}/config/database.yml"
  run "cp #{db_config} #{current_path}/config/database.yml"
end
 
desc &lt;&lt;-DESC
after updating we need to add back in the mongrel configuration file so that when restart is called
it will be appropriatly launched.  We also need to update the database config file
DESC
 
task :after_update, :roles =&gt; :app do
  configure_mongrel
  configure_database
end

A “list items won’t wrap” Firefox css fix!

The last few days working on the openmoney.info website, I’ve had a major hassle dealing with what appears to be a bug in the html renderer in Firefox.

The issue is that in Firefox, text in a list item won’t wrap around a right floated image; like this:

  1. Lorem ipsum dolor sit amet, consectetur adipisicing elit,
  2. sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

Code:

<ol style="border: 1px solid #cccccc; width: 300px">
  <img src="/images/eric.png" style="float: right" />
  <li>Lorem ipsum dolor sit amet, consectetur adipisicing elit,</li>
  <li>sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
  Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi
  ut aliquip ex ea commodo consequat.</li>
</ol>

In Safari & Opera the text in the second list item wraps just fine. After an hour of searching the web and trying various things with clear, and in-line, I discovered that the solution was to set the list item width to 100%. In other words, list items take on the width that they start at by default! Crazy. The solution:

<ol style="border: 1px solid #cccccc; width: 300px">
  <img src="/images/eric.png" style="float: right" />
  <li>Lorem ipsum dolor sit amet, consectetur adipisicing elit,</li>
  <li style="width:100%">sed do eiusmod tempor incididunt ut labore et
  dolore magna aliqua.  Ut enim ad minim veniam, quis nostrud exercitation
  ullamco laboris nisi ut aliquip ex ea commodo consequat.</li>
</ol>

yields nice wrapping text for the second list item:

  1. Lorem ipsum dolor sit amet, consectetur adipisicing elit,
  2. sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
    Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

If you aren’t viewing this on Firefox, the above two may look identical. That’s the whole point!

[tags]css,firefox,list item,wrap[/tags]

down the rails rabbit hole

The last month has been quite a trip down the rabbit hole into the new reality of ruby on rails! The promise of a powerful and well designed web application framework was just too much for me to resist, so I decided to leave my own yawaf framework behind (though it has certainly served me well).

So I’m posting this entry for those just starting down this path so you can see what might be on the path ahead of you and what I did to make my way over the learning curve.

  1. I purchased both the Programming Ruby and Agile Web Development with Rails books, and read them cover to cover. Both books are good. Dave Thomas really can write a good programming book.
  2. I dove into finally wrapping my head around the REST approach, which I also knew I wanted to switch to and was part of the reason I choose rails in the first place. To this end I found this great tutorial: RESTful Rails Development which expands on and gives clarity to the REST chapters in Dave Thomas’s book.
  3. Then it was time to install the creature on my PowerBook. The instructions in Dave’s book are pretty good, but the real place to go is hivelogic
  4. Once I had rails up I got my feet wet by implementing the bare essentials of the two projects that are the reason for switching to rails: the MANA stats project and, of course, open money.
  5. Since another reason for switching to rails was to be using an open source framework that others are well familiar with, and because open money is an open source project, and I want to get it out sooner rather than later, it was time to figure out where it should live. I find source-forge unbearably ugly, and though there are some other nice FLOSS platforms (launchpad, freshmeat), I settled on rubyforge for obvious reasons. So I spent a number hours learning my way around rubyforge (an instance of gForge) and setting up the open money project there. I realized pretty quickly that rubyforge is the right place to put up the releases of the projects and I may even use their svn repositories for a while, but gForge doesn’t cut it as a project development environment.
  6. So there I was off into another tunnel of the rabbit hole, which project development tool. So many of them… I see that lots of people, including the rubyonrails folks themselves, use Trac. However, I read many accounts of how difficult it was to install and get running, plus, I really felt that I wanted my project management tool to be in rails, to thereby leverage all my learning curve. I knew also that I was going to be modifying it out the wazoo, so it didn’t make any sense to learn yet another whole system. Dittio for various php bug-trackers, etc. After more hours of research, my options were then down to three: collaboa, retrospectiva (which is a fork of collaboa), and devalot. The first two are much more feature rich. But I ended up choosing Devalot, after talking with it’s author, Peter Jones (who seems like a real great guy) mostly because it just feels better than the others, but also because I like where it’s headed.
  7. Then I started to scratch my head about how in the heck I was going to deploy these apps. Yawaf is Perl base and deployable as plain CGI and works quite well for small sites. I’ve always known that I could switch to mod_perl if traffic increased enough to warrant it. Rails is another matter. You need to start out understanding deployment.
  8. So I read all that I could find, and tagged the good stuff for your reading pleasure on delicious. Upshot for me is apache 2.2.4 + mongrel + mod_prox_balancer + monit (not mongrel_cluster). [Update, after many hassles with monit, I ended up going back to mongrel_cluster (though I may add monit in later to monitor the cluster). See this e-mail exchange on the mongrel-users mailing list for details.]
  9. Then I realized that getting this to happen on my current VPS was going to be a nightmare, because it’s a DirectAdmin box, and getting apache upgraded to 2.2.4 was hard enough, but adding mod_proxy, etc was just not going to be doable while at the same time keeping it stable with my current apps live.
  10. So, then it was deeper down the rabbit hole into investigating Rails Hosting companies! Finding a hosting company in general is a huge pain and it is so variable according to your needs. Mine are complete control, hence VPS. Upshot: the company I wanted to go with, slicehost, is only taking reservations, and can’t fulfill orders for a month. Yow. (By the way, here’s a great writeup on rails hosting, and more delicious tagging of rails hosting in general.)
  11. So, now I’ve decided to do all this installation and testing of my future deployment environment on my basement Ubuntu server until slicehost comes through, or I find something better. For Ubuntu installation I’m taking some hints from these instructions which were missing one dependency for apache to compile for me (sudo apt-get install openssl libssl-dev). You may also want to check out this peepcode screen cast for another take on how to install the rails stack onto Ubuntu using deprec. It turned
  12. Once all the components are installed, the next challenge is configuring them to work right for your particular rails app. Enter bowtie, also by Peter Jones. Though still in development, this little utility produces configuration files for apache to use mod_proxy_balancer, and also for monit to launch and keep your mongrel instances up and running.
  13. Ok, so server is up and running, and I have a basic app on my development box, now I how do I deploy to the production server. Enter capistrano. Yet another learning curve. The trick is getting your deploy.rb script right to handle all the various problems… That will wait for a future post.
  14. Then, back into coding, I’ve realized that I just have to bite the bullet and start to use all the goodies built into ruby and rails for doing test driven development. So I started doing some background reading on good TDD practices which led me to behavior driven development which of course is why I’ve been putting of using TDD for so long because it’s BDD that actually makes sense. Here’s a great article by Dave Astels on BDD in the Ruby context. And fortunately there is rspec, a great implementation of BDD that integrates well into rails. The tutorial in the rspec documentation is very good for understanding it, and here’s the tutorial I used to get started using rspec in the rails context. Which led me to another helpful post by Dave Astels.

Solved: usb audio headphones muted when pugged in

Don’t you hate it in the computer field where something that was working fine for ages suddenly stops working? So this is what happened to me this time:

All of a sudden, when I plugged in my nice new Sennheiser USB headphones (PC165 USB) I couldn’t hear the sound. To get the sound to play, I’d have to go to the Audio MIDI Setup utility and toggle the mute button in the audio output settings. It had been working fine for a month, just plug it in and any audio output would just switch over from the speaker to th headphones.
So I called AppleCare tech support who said this was a Sennheiser problem, and I sent e-mail to Sennheiser who of course pointed back at Apple.

Well it turns out that to fix the problem, all I had to do was check the “Thru” checkbox on the audio input settings (in the Audio MIDI Setup Application). With that box checked, it works!

Go figure.

[tags]Mac OS X, USB, audio, headphones, mute, plug, Sennheiser, PC165 USB, Audio MIDI Setup[/tags]

tcsh: command not found

Have you ever gotten the tcsh: Command not found. error after installing some code? Well it happened to me today, and I couldn’t figure out what the problem was. I had already added the commands directory into my PATH, and set it to executable with chmod 755, but still the error kept coming up. The answer turned out to be that the command file (a shell script) that I had download had DOS line endings. Which, I quicly fixed using my trusty bbedit and bingo it worked fine.

Gnucash & Tiger

Another installment in the collective tech-support arena:
Gnucash wasn’t working under OS X Tiger (10.4.5); whenever I tried to run a report I kept getting the following cryptic error message in my terminal:

dyld: Symbol not found: _program_invocation_short_name
Referenced from: /sw/lib/libgnome.32.dylib
Expected in: flat namespace

A google search didn’t reveal anything with those error messages as keywords, so it was up to me to find the answer. Fourtunately my first stab in the dark worked! I did a fink selfupdate and then fink update-all (I’m using FinkCommander so I did those fink commands from the Source menu). I’m guessing that when I reinstalled gnucash after updating to Tiger, there were still some bugs in several of the libraries that were fixed by the fink update.
Be forewarned that this take a loooong time to complete (overnight for me on my G4 powerbook).
[tags]gnucash,fink,FinkCommander[/tags]

blogging and tech support

I’ve found that numerous times when I type into google a technical question, be it an error message that I’m seeing when installing some software package or some feature about a programming language, that where I often end up is in some person’s blog where they describe how they coped with exactly the same problem. This phenomenon seems to me a generalized solution to tech support, and also a wonderfully comunal and gift economy approach to problem solving. So I’ve decided to play the game too by creating a category for this blog called solutions, and, as often as I can, post my minor little breakthroughs in hopes that they will be helpful to someone else. And here’s my first:

I’ve been learning Smalltalk using squeak and I assumed that, like other object-oriented languages, there would be a constructor method that could take many parameters which would be used by the constructor to load up the values of instance variables. For example in perl a simplified constructure would look like:

sub new {
my $class = shift;
my $self = {};
bless $self, $class;
$self->{'FOO'} = shift; # save the constructor parameters into our data structure
$self->{'BAR'} = shift;
return $self;
}

which would be instantiated like this:
theObjectClassName->new('fish','dog');

In Smalltalk, it appears, you don’t do that. Instead you just create settors for your parameters and chain them to the new call. So you would have two methods:

setFoo: fooVal
foo := fooVal
setBar: barVal
bar := barVal

and your call to instantiate an object is then just:
theObjectClassName new setFoo:'fish' setBar:'dog'

because the first two words create the object and the the second two are just messages that get to the object after it is created, one at a time.

I love the beautiful parsimony of notions in Smalltalk.