OS X 10.6.5+ apachectl line 82

I was trying to play around with passenger under OS X Snow Leopard. After following the instructions on how to install passenger for apache I tried to restart it which resulted in the following error:

/usr/sbin/apachectl: line 82: ulimit: open files: cannot modify limit: Invalid argument

After searching the net for the error a solution was quickly found. Apple seems to have updated the Apache and thereby broke the apachectl script.

The following workaround worked for me; The referenced variable ULIMIT_MAX_FILES which is referenced a bit above, is defined as follows:

ULIMIT_MAX_FILES="ulimit -S -n `ulimit -H -n`"

redefining it as follows, solved my problem:

ULIMIT_MAX_FILES=""

Question remaining: What does ULIMIT_MAX_FILES stand for?

From MySql Schema to Rails migration file

After skimming some forums I found the answer must be quite obvious to Rails developers. Simply make sure that your database.yml file (found in the config/ folder), references to your database. Then execute the following command:

rake db:schema:dump

Now browse to your db folder in which you will find the complete schema of your database within the schema.rb file. Please note that the file will be overwritten so you may want to rename it or split it up into single migration files according to each table.

Please note that this is for development purposes, and not intended to run the generated migration onto a production database.

Static variables in JavaScript

Just to make this clear there is no static variable in the sence of which C#,Java or C/C++ (just to name a few..) offers, but there is a “workaround”. First thing to do is to define a function:


funciton gnabber() {
// Make sure variable is/was initialized
if(typeof gnabber.counter == 'undefined' ) {
gnabber.counter = 0;
}

// Increment and return the "static" variable
gnabber.counter++;
return counter;
}

Now if you call the function i.e.:


gnabber(); // returns 1
gnabber(); // returns 2
gnabber(); // returns 3

The return value will always be one higher. If you want to start the index from 0 you have to put the increment part into an else block:


funciton gnabber() {
// Make sure variable is/was initialized
if(typeof gnabber.counter == 'undefined' ) {
gnabber.counter = 0;
} else {
// If variable already was initialized increment it
gnabber.counter++;
}

return counter;
}

This will result in:


gnabber(); // returns 0
gnabber(); // returns 1
gnabber(); // returns 2

The main thing you are using here is the ability to extend an object in JavaScript, use this where ever you need a static variable with some logic instead of a global variable.