Thursday, March 30, 2006

bashrc : aliases I use.

Heres the file I always put in the
/etc/profile.d/ directory on systems I use.

===== yky.sh
# aliases i like to use
# 031110 yky Created from bashrc

alias h='history'
alias j='jobs -l'
alias l='ls -Fax'
alias ll='ls -laF'
alias d='ll'
alias c='cd ..'
alias md='mkdir'
alias rd='rmdir'
alias mr='more'
alias f='finger'


====

dont forget to chmod 755 it.

yk.

Wednesday, March 29, 2006

MySQL: CHARSET from latin1 to utf8

A website im supporting needs to have multilingual characters. The default character set for MySQL is latin1. This unfortunately will not support Chinese nor other wierd multibyte characters.

It will quietly support them, but returns gibberish and will cause frustration all round.

After digging around, the best character set to use is UTF8.
To set the default charset for the server, the my.cfg/my.ini file has to be modified:

default-character-set=utf8


Unfortunately, once a database and their tables have been defined as latin1, they remain as latin1 unless you run this for each database:

alter database mydatabase charset=utf8;


and for each table:
alter table mytable charset=utf8;


and for each varchar/char type column:
alter table mytable alter column mycol charset=utf8;


and repeat ad infinitum....

This is rather tedious and boring, so there should be a better way. And that is to dump out the sql, change the charset and dump it back in. Here is the script.


===== latin1ToUTF8.sh

echo Script to convert MySQL latin1 charsets to utf8.
echo Usage: $0 dbname
echo 060329 yky Created.

echo Dumping out $1 database
mysqldump --add-drop-table $1 > db.sql

mydate=`date +%y%m%d`
echo Making a backup
mkdir bak &> /dev/null
cp db.sql bak/$1.$mydate.sql

echo String replacing latin1 with utf8
cat db.sql | replace CHARSET=latin1 CHARSET=utf8 > db2.sql

echo Pumping back $1 into database
mysql $1 < db2.sql

echo Changing db charset to utf8
mysql $1 -e "alter database $1 charset=utf8;"

echo $1 Done!


======

There must be a better way ?!

yk.

Thursday, March 23, 2006

Timestamp your Photos - Filename Dater

Ive been printing digital pictures for quite a while now, and have always wondered why they never made use of the important information available in the EXIF sections of the pictures.

Wouldnt it be great if they printed that information at the back of your photo, so that you know the date and time and all the intricate details of how that picture was taken?

Currently now, they just print the first 8-12 characters of the filename, plus a whole load of unreadable junk at the back. Since I dont like printing the date on the picture itself, I have always renamed my images with the first 6 characters as the date, so there is a means of finding out the dates taken.

e.g. 060101_NewYearParty1.jpg, etc...

Now this is tedious, especially when doing over 300 pictures to process (I usually wait 6 months before processing images, as I do alot of retouching and some fancy stuff)

So I wrote a little delphi program to do this for me.
It will scan through the files in a directory, and if applicable, prepend the date information on the filename. The Date is either extracted from the EXIF data, or if not available from the modified date. If there is a date already tagged to the image, it will skip yet another prepend.

The original files:


After processing:


Note that the digicam pic uses the 'Date Picture Taken' and the movie uses the Modified date.

The very simple UI:


And its rudimentary output:


It was written in Delphi, and Im in the process of getting the permission of the dEXIF author, Gerry McGuire (believe it or not), to release this as GPL if possible. (The website says its 'opensource', but Im not sure which license...)

In the meantime, here is the executable:

FilenameDater.exe : 570KB v1.0

Have fun.

yk.

Wednesday, March 22, 2006

dspam: Sendmail + Quaranteen

I had this nagging problem with dspam + Web UI where I couldnt send the quaranteened emails to the recipient if dspam caught as a False Positive email.

maillog gives this error: ======

Feb 13 16:55:04 rslinux27 postfix/sendmail[14503]: fatal: usage:
sendmail [options]
Feb 13 16:55:05 rslinux27 dspam[14495]: Delivery agent returned exit
code 64: /usr/sbin/sendmail -d lo@user.com.my

The Web UI gives this error: =====

An Error Has Occured
The following error occured while trying to process your request:

sendmail: invalid option -- d
sendmail: fatal: usage: sendmail [options]
14269: [02/13/2006 16:46:08] Delivery agent returned exit code 64:
/usr/sbin/sendmail -d lo@user.com.my

This was described in my post to the newsgroup. Unfortunately for me no one answered this cry for help, until another user found the same problem. I emailed him, and he found a solution:

postfix sendmail implementation doesnt know the "-d" parameter. It is
defined in the configure.pl script of the cgi.

replace the -d with a -- and it should work :)


In detail:

In the directory where the cgi scripts for the WebUI for dspam are held:
e.g. /var/www/html/dspam/configure.pl

edit the line which has
$CONFIG{'DSPAM_ARGS'} = "--deliver=innocent --class=innocent " .
"--source=error --user %CURRENT_USER% -d %u";

to:

"--source=error --user %CURRENT_USER% -- %u";

The reason why its obscure is because there is no mention of 'sendmail' nor any indication that these params will flow to sendmail.

Anyway, now it works, so False Positive emails in Quaranteen can be released
and forwarded to individual users as per advertised.

yk.