Cufon font replacement

Cufon is pretty good. Much easier to work with than sIFR. The embedding part rocks as you can do it all online. For my own site I use it for headlines. Since the cookbook section contains recipes from around the world I limit and extend the characters to:
– uppercase
– lowercase
– numerals
– punctuation
– basic latin
– and extras including Serbian Cyrillic aphabet: čćšđžČĆŠĐŽабвгдђежзијклљмнњопрстћуфхцчџшАБВГДЂЕЖЗИЈКЛЉМНЊОПРСТЋУФХЦЧЏШ„”‘’–—«»°ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿŔŕ

Adding

<script type="text/javascript"> Cufon.now(); </script>

to the buttom of the page, but before other JS scripts, like Google Analytics, really makes the difference. There is no flicker in replacing the default font and Cufon font. Apparently it helps with IE quirks as well.

CodeIgniter 1.7.2 and SQLite 3

Nice little trick to get CI and sqlite3 to work together. Specify the database file location but prefix it with ‘sqlite:’.

$db['default']['database'] = 'sqlite:'.APPPATH.'data/dictionary.sqlite3';

Tip taken from:
http://blog.trevorbramble.com/past/2009/9/20/codeigniter_sqlite3/

Make MAMP PRO not ask about passwords on service restart

Change your default MAMP password from ‘root’ to something more useful:
/Applications/MAMP/bin/mysql4/bin/mysqladmin -u root -p password newpassword

Edit the following files:

  • /Applications/MAMP/bin/phpMyAdmin-X.X.X/config.inc.php

    $cfg['Servers'][$i]['password'] = 'newpassword'; // change root to your new password

  • /Applications/MAMP/bin/mamp/index.php

    $link = @mysql_connect(’:/Applications/MAMP/tmp/mysql/mysql.sock’, ‘root’, ‘newpassword‘);

  • /Applications/MAMP/bin/stopMysql.sh

    # /bin/sh
    /Applications/MAMP/bin/mysql4/bin/mysqladmin -u root -pnewpassword –socket=/Applications/MAMP/tmp/mysql/mysql.sock shutdown

Tip taken from this site.

Rotating Apache logs with logrotate

It’s pretty easy to set this up on Linux as most distros come with rotatelog functionality.

All I had to do was to create a file /etc/logrotate.d/apache2 with this content:

/usr/local/apache/domlogs/www3.serbiancafe.com.short {
daily
missingok
rotate 5
ifempty
copytruncate
olddir /usr/local/apache/domlogs/oldlogs
}

/usr/local/apache/logs/*_log {
rotate 3
size 100M
copytruncate
}

If plain English:
First log is rotated on a daily basis regardless if the log is there or empty. Last 5 logs are kept in “olddir” directory. And, you don’t have to restart Apache when you use copytruncate directive.

Second group defines a rotation for all files ending with “_log”. They rotate three files when their size is over 100M.

More options can be found in logrotate man page

Coda books with custom images for Code Igniter, MySQL, PHP…

http://blog.drastudio.com/past/2008/11/29/adding_more_coda_books/

Common Linux server commands on a new box

Changing a time zone

Log in as root and type these commands:
mv /etc/localtime /etc/localtime-old
ln -sf /usr/share/zoneinfo/America/Toronto /etc/localtime

To be continued

Deleting too many files

When you try to delete a big number of files in a directory of thousands using:

rm *

You’ll get an error. Linux complains about “Argument list too long”. Issue this command from a directory where files are located to get rid of them:

find . -exec rm {} \;

If you want to delete a large number of cache files, without deleting them all, the best way is to delete the files that were not recently accessed. Say you want to keep the popular cache hits which were accessed in the last 5 days and remove older files, your command would be:

find . -atime +5 -exec rm {} \;

If you try to use a wildcard when using find, you’ll be limited to the maximum number of pages your argument list can accept, which is a kernel limit. So, to work around this, I created a subdirectory for each cache group so I can use a directory name as the first parameter of find. The following example deletes items from cache which were not accessed in more than 4 days. This Something like this:

find /www/site/ci/system/cache/khcache/ -atime +4 -exec rm {} \;

Previously, I was using a wildcarded ‘find’ which was failing:

find /www/site/ci/system/cache/khcache_* -atime +4 -exec rm {} \;

Don’t forget to fix your cache directory setting in your configuration files.