Sunday, May 31, 2009

Upgrading libxml on OS X from sources: DON'T!

I upgraded the libxml/libxslt libraries on my MBP. After ./configure && make && sudo make install the new libraries ended up in /usr/local which is fine. I renamed the existing libraries from /usr/lib and that was the end of it. I had to reboot from an external firewire backup to restore the files and get my system back.

The series of unfortunate events that leads to a broken OS are:

  • the libxml build process generates only i386 files
  • it is not obvious how to generate universal binary, or at least x86_64 with the libtool used in the libxml source
  • the sudo exe depends on a library that in turn depends on the x86_64 libxml
  • without libxml from the distribution there is no more sudo so you cannot rename the shared libraries back

Saturday, May 30, 2009

Rake1.9 gotcha

Note that if you installed ruby 1.9 in parallel with ruby 1.8 then you got a rake1.9 that you should use with the upgraded projects. Unfortunately rake1.9 does not call gem1.9, it falls back to gem when you run commands like rake1.9 gems:install RAILS_ENV=test. If you want to install gems for the 1.9 environment you need to use gem1.9 explicitly, for example


sudo gem1.9 install thoughtbot-factory_girl

Mysql ruby1.9 extensions on OS X / Ubuntu 9.0.4

If you get the errors below when installing the mysql gem for ruby 1.9 then just go to the link below and follow the instructions to compile the ruby extension manually. Remember to use ruby1.9 if you installed it in parallel with 1.8.6

http://www.tmtm.org/en/mysql/ruby/

The instructions worked for me both on OS X 10.5.6 and Ubuntu 9.0.4. Here are the errors I was getting with gem install mysql.


mysql.c:6:21: error: version.h: No such file or directory
mysql.c: In function ‘make_field_obj’:
mysql.c:185: warning: unused variable ‘hash’
mysql.c: In function ‘escape_string’:

Git on ubuntu 9.04 server

If you try to install git on ubuntu 9.04 server, without Tcl/TK, you will get an error similar to the following:


GITGUI_VERSION = 0.12.0.23.ga91be
* new locations or Tcl/Tk interpreter
GEN git-gui
INDEX lib/
* tclsh failed; using unoptimized loading
MSGFMT po/de.msg make[1]: *** [po/de.msg] Error 127


One fix is to not build the GITGUI extensions. A complete list of commands follows, replace 1.6.3.1 with the current stable version of git.


http://kernel.org/pub/software/scm/git/git-1.6.3.1.tar.bz2
tar xjf git-1.6.3.1.tar.bz2
cd git-1.6.3.1
./configure --without-tcltk
make
sudo make install

Wednesday, May 20, 2009

Python __new__ not called

I was trying to build a quick and dirty singleton in python 2.5. I defined a __new__ method for my class and returned the one and only instance in there of the desired subject. To my surprise __new__ was not called, at all. After some more digging it turns out that your class needs to inherit from object. See the example below.

class NoNew:
def __new__(cls):
print "New Called for NoNew"

class YesNew(object):
def __new__(cls):
print "New Called for YesNew"


NoNew()
YesNew()


Executing the above generates

$ python test.py
New Called for YesNew


As you can see there is no line with NoNew and you need to inherit from object to be able to override __new__.

Another interesting fact is that printing an object will output something that looks like a physical address and that can be used to ensure that your objects are a singleton. Writing unit test cases for this is harder and I decide it is not worth the time.

Monday, May 11, 2009

CocoaHeads Sacramento/Roseville/Davis

I am trying to start a CocoaHeads group in the CA Central Valley around Sacramento. Inaugural meeting this Thursday May 14th at 6:30pm. We are meeting at Common Grounds in Davis, CA. See you there if interested :)

Tuesday, May 5, 2009

Shipped my iPhone app

Checkout my iPhone app, see the links under http://windsesh.com. Some of the code is open sourced at github.

Friday, May 1, 2009

GeoRuby: can't convert nil into Float

If you get the error below one possible cause is that you are passing in a malformed array.


TypeError: can't convert nil into Float
vendor/gems/GeoRuby-1.3.4/lib/geo_ruby/simple_features/point.rb:133:in `pack'
vendor/gems/GeoRuby-1.3.4/lib/geo_ruby/simple_features/point.rb:133:in `binary_representation'
vendor/gems/GeoRuby-1.3.4/lib/geo_ruby/simple_features/line_string.rb:82:in `binary_representation'


For example in LineString.from_coordinates(bb) the bb argument needs to be an array of two arrays of two numbers each, like in [[0,0],[1,1]]. If you pass an array with just one member you will get the error above. For example the following input is bad [[0,0], [1.1]] - the second array contains the floating pount number 1.1 not the two numbers 1, 1.