Joseph Heller anecdote

Reminds me of the evergreen Joseph Heller anecdote:

"At a party given by a billionaire on Shelter Island, Kurt Vonnegut informs his pal, Joseph Heller, that their host, a hedge fund manager, had made more money in a single day than Heller had earned from his wildly popular novel Catch 22 over its whole history. Heller responds, 'Yes, but I have something he will never have . . . Enough.'"

via: http://news.ycombinator.com/item?id=2365373

get around not having "if exists" to add users in an init script mysql

"A good workaround is to grant a harmless privilege to the user before dropping it.  This
will create the user if it doesn't exist, so that it can be dropped safely, like so:

   GRANT USAGE ON *.* TO 'username'@'localhost';
   DROP USER 'username'@'localhost';
"

via: http://bugs.mysql.com/bug.php?id=19166

error logs are located at

/var/log/nginx/error.log

via: http://www.pubbs.net/nginx/200906/39004/

there are other logs in there as well. If you want to rotate logs e very now and then, see:
http://stackoverflow.com/questions/1349291/nginx-log-rotation

If you want the php logs, search for "error_log" in the php.ini to see where they get placed

building a db driver plugin in symfony

this turned out to be harder than I expected due to the lack of documentation on how to build a database driver since I guess people that use Symfony are happy with either Propel or Doctrine.

The first problem I had was how to get configuration info to my new custom ORM. I started with databases.yml:

===== the databases.yml file =====
ENVIRONMENT:
  propel:
    param:
      classname:  DebugPDO
      dsn:        mysql:dbname=ENVIRONMENT;host=localhost
      username:   USERNAME
      password:   PASSWORD
  OTHER_ORM:
    param:
      name:       DB_NAME
      host:       localhost
      username:   USERNAME
      password:   PASSWORD

all:
  propel:
    class:        sfPropelDatabase
    param:
      phptype:    mysql
      classname:  PropelPDO
      encoding:   utf8
      persistent: true
      pooling:    true
  OTHER_ORM:
    class:        sfOtherOrmDatabase
=====

now, the "class" variable is important, because in your plugin directory you need something like the following structure:

=====
sfOtherOrmPlugin/
  config/
    sfOtherOrmPluginConfiguration.class.php
  lib/
    database/
      sfOtherOrmDatabase.class.php
    ...
=====

Notice that sfOtherOrmDatabase.class.php maps to "class: sfOtherOrmDatabase" in the .yml file.

the sfOtherOrmDatabase class needs to extend the sfDatabase class and implement connect() and shutdown() methods.

The sfOtherOrmPluginConfiguration class needs to extend the sfPluginConfiguration class and implement initialize().

Now, where I got hung up is actually connecting, I thought by implementing connect(), Symfony would call connect() automatically, but it doesn't. And, since I was using Propel code as my template, I was confused because Propel never actually calls sfPropelDatabase::connect(), it uses its own Propel::getConnection() instead.

However, initialize is always called, so I decided my custom class would connect on initialization, so let's go ahead and extend sfDatabase::initialize to call connect():

===== sfOtherOrmDatabase::initialize() =====
public function initialize($parameters = array())
{
  parent::initialize($parameters);
  $this->connect();
  return true;
    
}//method
=====

Now my custom db orm automatically connects and is ready for use when I get into the controller. And I am free from Propel and Doctrine so I can use databases like MongoDb.

Idealog: Check if a Javascript Function Exists or Is Defined

if(typeof yourFunctionName == 'function') {
  yourFunctionName();
} 

http://www.idealog.us/2007/02/check_if_a_java.html

Mysql changing a column type

ALTER TABLE tbl_name CHANGE field_name field_name field_type;

so, to change the username field on the table user to TEXT: ALTER TABLE user CHANGE username username TEXT;

http://www.roseindia.net/sql/mysql-alter/mysql-alter-column-datatype.shtml

Multiple databases support in Symfony - Stack Overflow

the queries you need to run to update your mysql db and tables to utf-8

you need to run this query for the db:

ALTER DATABASE db_name
	CHARACTER SET utf8
	DEFAULT CHARACTER SET utf8
	COLLATE utf8_general_ci
	DEFAULT COLLATE utf8_general_ci
	;

and then these 2 queries for each table in that db:

ALTER TABLE table_name DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

ALTER TABLE table_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;

via: http://web.archive.org/web/20070605215105/http://www.nicknettleton.com/zine/php/php-utf-8-cheatsheet

some other links that were helpful
http://www.joelonsoftware.com/articles/Unicode.html
http://stackoverflow.com/questions/140728/best-practices-in-php-and-mysql-with-international-strings

more stuff:
http://marcyes.com/2009/12/21/php_utf8_cheatsheet/

of common misconceptions - Wikipedia, the free encyclopedia