render :action in :rails

Although the Rails Guides say it is a newcomers issue, I also get sometimes confused with the render command:

"Using render with :action is a frequent source of confusion for Rails newcomers. The specified action is used to determine which view to render, but Rails does not run any of the code for that action in the controller. Any instance variables that you require in the view must be set up in the current action before calling render."

My first ever ruby gem (pre-alpha)

Today I released my first-ever ruby gem, still pre-alpha but maybe of use for someone. The gem adds a climate classification parameter to a location object based upon observed or projected climate data. It is based upon the Köppen climate classification, one of the most widely used climate classification systems.

Test it: https://github.com/tpunkt/koeppen-geiger

Map Application Performance Tuning - Part 2

An advice for optimizing the performance of Mapserver was to use FastCGI.

1. I installed the FastCGI library with yast and downloaded the Apache2 module mod_fastcgi-2.4.6.tar.gz. After extracting it, I followed the configure, make, make install dance as described. Unfortunately the compiler complained about some missing stuff and I couldn´t figure out how to get the module installed. I gave it up and tried the mod_fcgid module from Apache itself that seemed to be quite similar.

3. I extracted mod_fcgid-2.3.4.tar.gz to my home directory and followed the steps described in the README:
# APXS=/usr/sbin/apxs2 ./configure.apxs
# and following 'make'

The compiler returned the same problem and complained about a missing mpm.h and mpm_default.h in /usr/include/apache2.

I came around the problem by symlinking both files using:
ln -s ../apache2-prefork/mpm.h mpm.h
ln -s ../apache2-prefork/mpm_default.h mpm_default.h

After doing that both modules were build successfully into /usr/lib64/apache2.

4. I added a configuration file to load the module in /etc/apache2/conf.d with the following entry:

LoadModule fastcgi_module /usr/lib64/apache2/mod_fastcgi.so

5. I restarted Apache with apache2ctl restart. The error_log in /var/log/apache2/ indicates that the module was loaded successfully:

Apache/2.2.10 (Linux/SUSE) mod_ssl/2.2.10 OpenSSL/0.9.8h mod_fastcgi/2.4.6 Phusion_Passenger/2.2.5 configured -- resuming normal operations

Map Application Performance Tuning - Part 1

My current task is to improve the performance of a web application that runs on Apache 2.2.10 on OpenSuse 10.6, 64bit. It is a map application that works with Google Maps JavaScript API, OpenLayers JavaScript API on the client side and a Mapserver on the server side.

After discovering that the response time of my server was sometimes quite long (using firebug), I decided to start optimizing the server side application first.

1. First step I did was installing Tilecache, a Python-based server that caches tiles from different sources on disk. Installation is easy and straightforward. The test run worked correctly.

2. Figuring out how my application or better a OpenLayers.Layer.WMS object could request tiles via Tilecache that were formerly requested from Mapserver was a little bit harder. First I had to install Python MapScript (to enable communication between Tilecache and Mapserver). which I managed by following the advices "Building and Installing Python MapScript" in Chapter 7 from the "Beginning MapServer" book from Bill Kropla. As far as I know now, each map that should be cached by and requested via Tilecache has to have a correct entry in tilecache.cfg.

Example:
[worldtest]
layers = country
spherical_mercator = yes
extension = png
mapfile = mapfile.map
data_extent = -198.0,-115.542749339,198.0,109.146905833
type = MapServer
metatile = no
srs = EPSG:4326
metabuffer = 10,10
bbox = -198.0,-115.542749339,198.0,109.146905833
metasize = 5,5
extent_type=loose

This layer can requested via an OpenLayers.Layer.WMS object as follows:

var layer = new OpenLayers.Layer.WMS("name",
  "http://localhost/cgi-bin/tilecache/tilecache.cgi", {
  maxExtent:new OpenLayers.Bounds(1,2,3,4),
  maxResolution:156543.0339,
  layers:"worldtest",
  transparent:true
});

gem server

Great tip! Running "gem server' fires up a server page on localhost:8808 that lets you crawl rdocs of all locally installed gems.

Introduction to SCRUM

While searching for a methodology to get some kind of structure into my software development process, I remembered SCRUM. This video is an excellent introduction to this agile project methodology. Still have to figure out how to make this work in our special team and development situation.

Installing MySQL and mysql gem on Snow Leopard

It´s really a hard job figuring out how to get MySQL and mysql gem up and running on Snow Leopard 10.6.2. I followed the instructions of various posts but was not successful yet:

First I followed this instruction http://hivelogic.com/articles/compiling-mysql-on-snow-leopard/" and build MySQL Version 5.1.39 from source. It installed successfully. When trying to login using (mysql -u root -p) mysql returned the following error: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2), that obviously meant that the MySQL Server (mysqld) was not running (ps -axf | grep mysqld).

which mysql: /usr/local/mysql/bin/mysql
which ruby: ruby 1.8.7 (2009-04-08 patchlevel 160) [i686-darwin9])
gem -v: 1.3.5
mysql: Server version: 5.1.39 MySQL Community Server (GPL)

After a lot of googling around, I found out that

1. this command can start mysqld:
sudo /usr/local/mysql/bin/mysqld_safe --user=mysql &

2. The Preference Pane MySQL Tool is probably broken in Mac OS X 10.5 and higher

3. This command should install the mysql gem correctly on Snow Leopard:
sudo gem uninstall mysql
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
(See this post: http://stackoverflow.com/questions/1366746/gem-install-mysql-failure-in-snow-leopard

It ended up that I got the following error using something like rake db:create:
dyld: lazy symbol binding failed: Symbol not found: _mysql_init Referenced from: /opt/local/lib/ruby/gems/1.8/gems/mysql-2.8.1/lib/mysql_api.bundle Expected in: flat namespace dyld: Symbol not found: _mysql_init Referenced from: /opt/local/lib/ruby/gems/1.8/gems/mysql-2.8.1/lib/mysql_api.bundle Expected in: flat namespace

This error led me to the following post: http://cho.hapgoods.com/wordpress/?p=158, that basically tells me that the Ruby Version that came together with XCode 3.0 does not work in 64bit environments and a solution could be to install the 32bit version. Arrrgghh!

The first answer to my post @ stackoverflowled me to the right track, doing the stuff with macports.

The way I finally solved this issue was uninstalling / reinstalling XCode and all my ports as described here:
http://trac.macports.org/wiki/Migration

MacBook Pro Trackpad Fix

Das Trackpad beim neuen MacBook kann z.B. bei der Arbeit im Browser sehr nervig sein, wenn man mit beiden statt mit einem Finger scrollen will und sich dadurch ständig die Seite verkleinert bzw. vergrößert. Nach langem Suchen bin ich heute endlich auf einen einfachen Fix gestoßen: http://cubeyellow.blogspot.com/2009/01/mac-book-pro-trackpad-zooming-and.html