Friday, December 11, 2009

Crob Job Example

1. crobtab -e
2. Add following line
* * * * * you command | logger "wget ran"
3. Save and exit. (You should see a message say "crontab: installing new crontab")

What does this command do?
It will run your command every min, and write a message to the system log. The system log usually locate at /var/log/messsages

More reference:

Thursday, December 10, 2009

Wordpress: Query Analysis

Wednesday, November 25, 2009

ORDER by title in mysql, ignoring the word “The”

Often time when you want to sort your sql return record by title, but the title starts with the word "The", for example "The Mummy" and we wants to sort by "Mummy" instead.
There are 2 solutions I have found:
1. Create a new field on the fly and sort by using the new field.
Select *, str_replace(title, 'The ', '') as sort_title ORDER BY sort_title

2. For better query performance, create a new column in the table ('sort_title') that is same as the title column but without a prefix of "The " or "A".

Some more info can be found here:

Monday, November 23, 2009

SSH tunneling

ssh -NL
now access via localhost:1090

Friday, November 20, 2009

Simple json object decoding

var newdata = eval('(' + jsonData + ')');

Thursday, November 19, 2009

PHP Date format in other language

To make php change data format dynamically base on the current language, use strftime() in combine with setlocale().
If local has not been installed, install it and restart Apache.
More info on

Wednesday, October 14, 2009

Prevent Iphoto From Start Up In Iphone

1. Open the App called Image Capture (it should be in your applications folder)
2. Once open go to the Pref. (apple , ) and click the general tab
3. You will see an option to open an application when camera is connected
4. Adjust what you need to, or just select No Application.

Tuesday, October 06, 2009

PHP: Interceptor method

Tuesday, September 29, 2009

htaccess: directory browsing

To enable directory browsing, add a .htaccess file under that directory and add this line to the file: "Options +Indexes"
To prevent directory browsing, add this to the file: "IndexIgnore */*"

Friday, September 25, 2009

Progressive JPEG

Reference From: Progressive JPEG
A simple or "baseline" JPEG file is stored as one top-to-bottom scan of the
image. Progressive JPEG divides the file into a series of scans. The first
scan shows the image at the equivalent of a very low quality setting, and
therefore it takes very little space. Following scans gradually improve the
quality. Each scan adds to the data already provided, so that the total
storage requirement is roughly the same as for a baseline JPEG image of the
same quality as the final scan. (Basically, progressive JPEG is just a
rearrangement of the same data into a more complicated order.)

The advantage of progressive JPEG is that if an image is being viewed
on-the-fly as it is transmitted, one can see an approximation to the whole
image very quickly, with gradual improvement of quality as one waits longer;
this is much nicer than a slow top-to-bottom display of the image. The
disadvantage is that each scan takes about the same amount of computation to
display as a whole baseline JPEG file would. So progressive JPEG only makes
sense if one has a decoder that's fast compared to the communication link.
(If the data arrives quickly, a progressive-JPEG decoder can adapt by
skipping some display passes. Hence, those of you fortunate enough to have
T1 or faster net links may not see any difference between progressive and
regular JPEG; but on a modem-speed link, progressive JPEG is great.)

Up until recently, there weren't many applications in which progressive JPEG
looked attractive, so it hasn't been widely implemented. But with the
popularity of World Wide Web browsers running over slow modem links, and
with the ever-increasing horsepower of personal computers, progressive JPEG
has become a win for WWW use. IJG's free JPEG software (see part 2, item
15) now supports progressive JPEG, and the capability is spreading fast in
WWW browsers and other programs.

Except for the ability to provide progressive display, progressive JPEG and
baseline JPEG are basically identical, and they work well on the same kinds
of images. It is possible to convert between baseline and progressive
representations of an image without any quality loss. (But specialized
software is needed to do this; conversion by decompressing and recompressing
is *not* lossless, due to roundoff errors.)

A progressive JPEG file is not readable at all by a baseline-only JPEG
decoder, so existing software will have to be upgraded before progressive
JPEG can be used widely. See item 16 in part 2 for the latest news about
which programs support it.

Tuesday, September 01, 2009

Debugging in PHP

Fast noodle debug in php:


Tuesday, August 04, 2009

Tuesday, July 28, 2009

1 pixel heigh div in IE 6

If you want to create a 1px horizontal line, some people may use a 1px height div with a color background to accomplish it instead of using
tag. For example,

div.details-sep-hr {
border:0 solid black;

This works perfect with all modern browsers but not in IE6. IE may generate a line more than 1px height. To fix this, add overflow hidden to the class.

div.details-sep-hr {
border:0 solid black;
overflow: hidden;

Thursday, July 09, 2009

Negotiation in Apache

In Apache HTTP web server (v2.2), If the browser requesting an image ( for example without extension, such that, the server can resolve the issue automatically by search all files under "images" directory that match example.*. The reason behind this is the feature of "Content Negotiation" in Apache Web Server, it seems like this is only the feature for v2.2 or above.

The effect of MultiViews is as follows: if the server receives a request for /some/dir/foo, if /some/dir has MultiViews enabled, and /some/dir/foo does not exist, then the server reads the directory looking for files named foo.*, and effectively fakes up a type map which names all those files, assigning them the same media types and content-encodings it would have if the client had asked for one of them by name. It then chooses the best match to the client's requirements.

For more information, go to:

Tuesday, June 30, 2009

New way to style for IE 6

Just discover that we can specify style for ie 6 using: _myclass syntax.
For all modern browsers, it will think that this is incorrect syntax and will ignore it entirly; However, for old browser, such as IE 6, it intelligently think this is a typo, and assume it to be myclass.
More Info in: Underscore hack for CSS and IE

Other way to style IE 6 is through conditional commenting or using syntax like myclass[class] which only regonize by modern browser.

Thursday, June 25, 2009

Extjs: Using stripCharsRe

Ext js comes with a config option for textarea (maybe also for another form field) that to strip off any unwant character from a value, here is an example of stripping leading white space for the textara field in my form:
stripCharsRe: /^\s+/g, //strip off leading white space
grow: true

Tuesday, June 16, 2009

SVN COPY files from respository

svn copy svn:// -r 277 .

Syntax: svn copy [fullpath] -r [revision #] [distination]

Friday, June 05, 2009

Running PHP from Command Line (CLI) directly

First, finding the php location, usually in /usr/bin for mac;
Then use execute: /usr/bin/php -r 'echo phpinfo();'

DONT forget put quote surround your script.
For more info, type 'man php'


Wednesday, June 03, 2009

Extjs AUTO complete of combo box

Here is and example to make a auto complement combo box in Ext JS. 3 important factors keep in mind here:
1. I am using jsonstore and set mode to local
2. jsonstore should set autoload to "true"
3. Set triggerAction to "all" in the combo box config

{ xtype:'combo', id: 'shoutoutsTags',
fieldLabel: 'Tag',
value: '',
mode: 'local',
width: 200,
store: new{
url: 'get_data.php',
fields: ['id', 'name'],
root: 'tags',
autoLoad: true
displayField: 'name',
valueField: 'id',
forceSelection: true,
triggerAction: 'all',

hiddenName: 'mytag' //dont put it the same name as name filed value

Thursday, May 28, 2009

Friday, May 15, 2009

Prototype error: Value undefined (result of expression this.fireEvent) is not object.

If you got a js error saying "Value undefined (result of expression this.fireEvent) is not object." when using prototype, make sure you only include prototype.js ONCE in your document.

Thursday, May 07, 2009

Alternate table row color using javascript

This version on javascript has been tested on Firefox, Safari, IE 6, and IE7

$('chart_table').select("tbody tr").each( function(e) {
Event.observe(e, 'mouseover', function() {
Element.addClassName(e, 'hover');
Event.observe(e, 'mouseout', function() {
Element.removeClassName(e, 'hover');

========css =====
.hover{ background-color:#CECECE; color: #fff;}

More detail:

Tuesday, May 05, 2009

Regular expression

For Anchor tag:
preg_match_all('/]*>(.*?)<\/a>/Ui', $post, $matches);

For Image:
preg_match_all('/]*>/Ui', $post, $matches);

Tuesday, April 28, 2009

IE 6 weir duplicate character

If you ever seem IE 6 generate duplicate characters, you should double check if you have comment inside another comment tag.
More detail:

Thursday, April 09, 2009

Install SVN server

cd ~
mkdir src
cd ~/src

tar -xzf apr-util-1.3.4.tar.gz
tar -xzf apr-1.3.3.tar.gz
tar -xzf subversion-1.6.0.tar.gz
tar -xzf neon-0.28.4.tar.gz
tar -xzf sqlite-amalgamation-3.6.11.tar.gz

cd ~/src/apr-1.3.3
./configure --prefix=$HOME LDFLAGS="-L/lib64"
make install
cd ~/src/apr-util-1.3.4
./configure --prefix=$HOME --with-apr=$HOME LDFLAGS="-L/lib64"
make install
cd ~/src/neon-0.28.4
./configure --enable-shared --prefix=$HOME LDFLAGS="-L/lib64"
make install

cd ~/src/sqlite-amalgamation-3.6.11
make install

cd ~/src/subversion-1.6.0
cp ../sqlite-3.6.11/sqlite3.c sqlite-amalgamation/sqlite3.c
./configure --prefix=$HOME --without-berkeley-db --with-zlib --with-ssl LDFLAGS="-L/lib64"
make install

(You may get some warming message, but it is ok)

More info:
Follow instruction on: (more detail on the 2nd page to make svn checkable to local)

Tuesday, April 07, 2009

Mysql reset indexes

Use this sql can reset the index of an auto increment column.

Find more info on: Reset auto incrementation

Thursday, April 02, 2009

IE debugging tools

Most of web developers know debugging in IE is a painful job especially IE6. Unlike, firefox that has an add-on "Firebug" makes all of us happy in the debugging and inspection. How I wish IE has the same kind of tool~~. But today, after spending sometime on forum, it seems like ppl are already taking some action on IE. Here's a list of tool that may make developers' life easier on IE:

X-RAY: A free cross browser tool that lets you see the box model in action for any element, letting you see beneath the skin of any web page.

DebugBar: An Internet Explorer plug-in, feature in: DOM inspector, HTTP inspector, Javascript inspector, js console, HTML validator etc.

CompanionJS: Detailled javascript error reporting (call stack and real file name where the error occured).

These tool may requires to install IE script editor, which can be download from microsoft official site at: Microsoft Script Debugger

Wednesday, April 01, 2009


If you use UNIX_TIMESTAMP() and FROM_UNIXTIME() to convert
between TIMESTAMP values and Unix timestamp values, the conversion
is lossy because the mapping is not one-to-one in both directions.
Because of daylight saving time, it is possible for two UNIX_TIMESTAMP()
to map two TIMESTAMP values to the same Unix timestamp value.
FROM_UNIXTIME() will map that value back to only one of the original
TIMESTAMP values. Here is an example, using TIMESTAMP values in
the CET time zone:

mysql> SELECT UNIX_TIMESTAMP('2005-03-27 03:00:00');
| UNIX_TIMESTAMP('2005-03-27 03:00:00') |
| 1111885200 |

mysql> SELECT UNIX_TIMESTAMP('2005-03-27 02:00:00');
| UNIX_TIMESTAMP('2005-03-27 02:00:00') |
| 1111885200 |

mysql> SELECT FROM_UNIXTIME(1111885200);
| FROM_UNIXTIME(1111885200) |
| 2005-03-27 03:00:00 |

Thursday, March 26, 2009

Install Ruby on Leopard

Wanna to try out Ruby On Rail long time ago but just dont have time the get it install on my Mac, so tonight is the time. Although Leropard ship with Ruby package, it is not up to dated, and beside it does not has MYSQL C Binding, there are more extra steps need to be perform to get ruby fully function on Leopard. There are already many posts out there show how to configure it. I will summary the main steps here and provides a list of links that i use as a references.
1. Log in as a root
2. Update gem (The one ship in leopard is out of date)
gem update --system
3. Install the latest rails (current 2.2)
gem install rails -v=2.2.2
4. Install MYSQL C binding to improve mysql performance (the tricky one)
=> Use the leopard dvd install xcode tool
=> Run: sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-
=>Choose option 3: mysql 2.7 (ruby)

To test Rails,
$ rails demo
$ cd demo
$ ruby script/server
veiw page at: http://localhost:3000


Ruby Installation

C Binding issue on Leopard

Detail on how to fix the problem

More detail on C Binding

My new web development coding suit

These days I am trying out to use another powerful text editing tool, and just find that Textmate is right to the spot. So far i like it very much. Not only because of it simplicities while powerful but also an eye candy tool for coding.
With combine of Expand Drive, i can mount a remote drive to my local machine and editing remote file right from textmate. To enhance performance due to slight delay by remote access, and nature of textmate of auto refreshing when it refocus, install Remate is the right assist for textmate that would solve the problem.

If interested, try it yourself:


Remate 2

Tuesday, February 24, 2009

Convert mysql output to another data type

Sometimes there's a need to convert a datatype from one to another in the database, for example, if the data is store in utf8 format in the database and you want it output to latin1 datatype, one way to do this is using the convert function that mysql provide. Here a snippy code for that:

"SELECT CONVERT(fieldname USING latin1) as newfield FROM dbtable"

More detail can be found on: MYSQL CONVERT FUNCTION

Tuesday, February 17, 2009

Migrate column from one table to another table

Here is an example on how to migrate column between table:

update fo_tags en, fo_tags_cn cn, fo_tags_cs cs
en.name_cn =, en.name_cs =,
en.kind_cn = cn.kind, en.kind_cs = cs.kind
where = and =

Friday, February 06, 2009

Make png file works with ie 6

To make IE 6 works with PNG transparency, one easy way is using a htc script, for example, attached

img.ispng {
behavior: url("/");

to the css file, then for each png image, add a "ispng" class to it.

The can be download at

Monday, February 02, 2009

Fixing IE 6 transparent issue

Here a small utility to help fix IE 6 transparency issue on PNG graphic.