Saturday, 5 December 2009

HOWTO: backup / resotre mysql database for drupal

To Backup:

  1. select the database need backup in phpMyAdmin
  2. select the tab of Export, and save as file in a sql format.
To resotre:
  1. upload the drupal installation files into the proper directory.
  2. copy the old director of /site/all, in which are the modules and themes to the new site directory. Otherwise some functionalities will miss.
  3. create the database you want in phpMyAdmin with proper database name.
  4. select the new database and Import.
  5. Install the new drupal site.

Wednesday, 14 October 2009

HOWTO install egg file for python

Using easy_install, which is installed by setuptools (

~$ easy_install XXXXX.egg
This is for binary egg file. While script egg file should be treated as normal shell script. To install:
~$ sh XXXXXX.egg

Another popular way to install python 'modules', is:
~$ python install
This is from python source. Normally third parties will provide such kind of source.

Thursday, 10 September 2009

HOWTO: screencast in Ubuntu

With recordmydesktop, ffmpeg, mencoder, libavcodec-unstripped-52 ( for aac audio encoder), ubuntu-restricted-extras installed. Run the following command to record and convert it to mp4 format, in order to upload to youtube.

mencoder out.ogv -oac pcm -ovc lavc -lavcopts vcodec=mpeg4 -o out.mp4

Thursday, 20 August 2009

Matlab: Mex example in C way

There is a yprime.c for mex in Matlab. Here I translate to C, in order to understand mex better.

#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
static void yprime(
double* yp,
double* y
double r1,r2;

double mu = 1/82.45;
double mus = 1 - 1/82.45;

r1 = sqrt((y[0]+mu)*(y[0]+mu) + y[2]*y[2]);
r2 = sqrt((y[0]-mus)*(y[0]-mus) + y[2]*y[2]);

yp[0] = y[1];
yp[1] = 2*y[3]+y[0]-mus*(y[0]+mu)/(r1*r1*r1)-mu*(y[0]-mus)/(r2*r2*r2);
yp[2] = y[3];
yp[3] = -2*y[1] + y[2] - mus*y[2]/(r1*r1*r1) - mu*y[2]/(r2*r2*r2);

int main(){
double yo[4];
double yi[4] = {100, 2, 3, 4};

yprime(yo, yi);
printf("print out %f",yo[0]);

// some conversion practice
double a = yi[0];
char t1[7],t2[8],t3[8];

*t1= (char) a;

printf(strcat(t1, t2));


// i = sprintf(str, "%d", 15); //for interger to string

return 0;

Sunday, 16 August 2009

HOWTO: compile objective-c using gcc in Linux

to compile these examples of objective-c (install libobjc first) from objective-c on

1) traditional:
gcc -c XX.m XXX.m -Wno-import
gcc -o prog XX.o XXX.o -lobjc -Wno-import

2) gcc *.m -lojbc -Wno-import

-Wno-import is because the maintainer of gcc doesn't like 'import';

-lobjc: -l(library) -L(libaray directory) -lobjc(for GNU objective-c libraray)

For those examples using GNUstep, most of the header files need to be changed from ' #import ' to '#import ' to suit the GNU objective-c library.

More details:

Monday, 3 August 2009

HOWTO: Version control using BZR vs RCS

No matter programming or documents editing, BZR will work for you to provide easier and better version control.

Here are some simple steps for docs processing:

  1. bzr init
    create a folder, 'text', then create a file, 'test1.txt', in which we type in a paragraph. Then 'bzr init' to let bzr know this is the folder where bzr should monitor.
  2. bzr add
    'bzr add test1.txt'. Now bzr knows where and what to monitor.
  3. bzr diff
    add more text into the test1.txt, then run 'bzr diff' to test whether there is any changes.
  4. bzr commit -m 'description'
    if there are some changes, and you want to create another version for that for the current version backup. run 'bzr commint -m "some description"'.
  5. bzr log
    to check verisons.
    more changes and more commits here.
  6. bzr branch -r
    For example we just want to retrive the first version, run 'bzr branch `pwd` -r 1'. A new folder with the name of current folder 'text' will be created, in which our text1.txt 1st version is there.
RCS: (same procedure)
  1. create folder RCS
    this step can be ignored, the rcs information will be saved in the same folder with the file you are editing. Otherwise, the file info file will be saved in the RCS folder.
  2. ci -u test1.txt
    ver 1.1 is created. RCS uses the concept of 'lock'. -l -r -u are similar, to keep the text file locked when new version is registered.
  3. co -l test1.txt
    (if without this step, new version can not be registered. because 'no lock', prompted by 'ci', is this for synchronization?) So to lock the text file to make it writable (very weird concept, locked == writable???). Then add more text in it.
  4. rcsdiff test1.txt
    To check what's different from the registered version.
  5. ci -u test1.txt (same with step2)
    The version number increment with 0.1.'ci -r2 -u test1.txt' to make the version increment by 1.0.
    more changes and more commits here.
  6. co -l1.1 test1.txt
    Retrive version 1.1 to replace the current editing file. -l -r -u are similar, just -u makes the file non-writeable, while -l make the file writeable. Good practice is 'ci -u' and 'co -l', so that when the new version is registered by ci, the file will become 'non-writable'='can not modify'='No lock'. (weired)
Note: no space between '-r2' and '-u1.1'.

BZR is more user friendly, and Ubuntu uses it on
RCS is quite mature (old), LYX uses it as version control. So even I don't like it, but I have to still use it, because I love Lyx.

Sunday, 2 August 2009

HOWTO: autoconf & automake HELLO WORLD

1) Create sources, “”
2) `autoscan`:create configure.scan
3) Rename “configure.scan” to “”
4) `autoheader`:create for automake
5) Add AM_INIT_AUTOMAKE to “”, just after AC_INIT()
6) `aclocal`:create necessary macros in aclocal.m4 for automake.
7) `automake ­­--add-­missing --­­copy`: create from
8) `autoconf`:create configure
9) `./configure`:check and create Makefile
10) `make`
11) `make install`

if you modify your source...
1) Run `autoscan` again
2) Compare configure.scan with
* Update
3) Run `autoreconf`

# for hello.c

To simplify it:
1) c/cc files,
2) autoscan => mv configure.scan => add Add AM_INIT_AUTOMAKE after AC_INIT

3) autoheader
4) aclocal
5) automake

6) autoconf <=> autoscan,(compare,autoreconf

7) ./configure && make && make install

Simplest 'make'

int main(int argc, char* argv[])
printf("Hello, world!\n");
return 0;

# Makefile: A standard Makefile for hello.c
all: hello
clean: rm -f hello
Run: make, to create executable bin file.

HOWTO: autoconf & automake

  1. Write templates.
  2. Write
    2.1 Use autoscan to generate a template.
    2.2 Specialize the generated configure.scan to suit your project.
    2.3 Rename configure.scan to
  3. Run automake to generate from (automake scans to find out more about the project).
  4. Run aclocal to make local copies of all autoconf macros. These macros are then included in the project.
  5. Run autoconf to generate configure.


automake, when used in conjunction with autoconf, makes creating Makefiles easy. automake operates on a to generate . is then processed by the configure script to generate Makefile. has macros that are processed by automake. A sample is shown below. Variables surrounded by @'s are automatically propagated without change to The configure script, when parsing into Makefile, makes the necessary substitutions (for example, @LDFLAGS@ may get expanded to "-lm -lthread).
        bin_PROGRAMS = gpstat
        gpstat_SOURCES = about.c interface.c multi-plot.c attach_process.c
        gpstat_LDFLAGS = @LDFLAGS@ @GTK_LIBS@ -lgthread

automake knows the rules to create object files and executables for the platform it is running on. The above sets of macros tell automake that:
1. The final executable is to be named gpstat. 
2. The sources for gpstat are the value of gpstat_SOURCES. 
3. Add @LDFLAGS@, @GTK_LIBS@, and -lgthread to the link line. (The configure script will replace LD_FLAGS and GTK_LIBS with their proper values.) 
4. Include the variable $INCLUDES in the compilation line.



The configure script is generated from using autoconf. is a normal text file that contains several autoconf macros. These macros specify what tests to carry out. General uses of the configure script include:
1. Find machine information (Hostname, version...). 
2. Find the path to a particular program (bison, lex, ...). 
3. Find out if a tool supports a feature (for example, if the compiler supports bool). 
4. Check if the required libraries are available on your system. 
5. Process to generate Makefile.


automake also provides autoscan, a utility script that will help you create a template autoscan scans the program sources and adds suitable macros to It creates configure.scan, which then should be renamed, after making suitable modifications.
automake also provides a program called aclocal. aclocal makes local copies of all autoconf macros, so that other developers can modify the file.

You can combine the invocation of automake, aclocal, and autoconf as follows:
foo@pastwatch$ aclocal&& automake && autoconf

Comments can either begin with dnl or a #. The following is a small, well-documented, self-explanatory file.
dnl Process this file with autoconf to produce a configure script.
dnl notice how comments are preceded by "dnl"
# comments can also begin with a #
dnl This macro is a must, and this tests if the configure
dnl script is running in the correct directory
dnl This macro tells the configure script to put
dnl "defines" in a file rather than the command line.
dnl get the flags
dnl this macro is used to get the arguments supplied
dnl to the configure script (./configure --enable-debug)
dnl Check if we have enable debug support.
AC_MSG_CHECKING(whether to enable debugging)
AC_ARG_ENABLE(debug, [ --enable-debug=[no/yes] turn on debugging
[default=$debug_default]],, enable_debug=$debug_default)
dnl Yes, shell scripts can be used
if test "x$enable_debug" = "xyes"; then
CFLAGS="$CFLAGS -O3 -ffast-math -mcpu=v8 -mtune=ultrasparc"
dnl tells us that we require autoconf with version greater than
dnl 2.12 to generate configure
dnl get system information
dnl Since foo is currently untested on any os other
dnl than solaris, so check the os and quit if not solaris.
UNSUPPORTED_OS="FOO is currently unsupported on your platform.
If you are interested in making it work on your platform, you are
more than *welcome*. Contact for details."
case "${target_os}" in
echo ===========================================================
echo Setting up build environment for ${target_cpu}${target_os}
echo ===========================================================

# Build time sanity check...
dnl get path to install program
dnl initialize automake
dnl Checks for c compiler.
dnl check for standard c headers
dnl export these variable (so Makefile substitutions
dnl can be made.
dnl Checks for libraries.
dnl AC_CHECK_LIB(gthread, g_thread_init)
dnl AC_CHECK_LIB(pthread, pthread_create)
dnl Check for /proc
find /proc. See the file 'README' for help.))
dnl check for procfs.h
find procfs.h. See the file 'README' for help.))
dnl Checks for header files.
dnl Checks for typedefs, structures, and compiler characteristics.
dnl Create these files, making substitutions if necessary

Tuesday, 28 July 2009

HOWTO: get stdin from shell in Gedit External Tool

The following code can get the input from Gedit External Tool as you assigned for 'input'.

echo $search
The trick is the command of xargs.

Also available Environment Variables in Gedit External Tool are:

An example: compile java file and run it
javac $GEDIT_CURRENT_DOCUMENT_NAME && java -cp . `echo $GEDIT_CURRENT_DOCUMENT_NAME | sed s/.java//`

Wednesday, 22 July 2009

16-bit binary data interpreting difference between Java and Matlab

The 16-bit data will be interpreted as different values in Java and Matlab. WHY??

Here are some experiments: save number 15 to 8-bit and 16-bit binary files, and another 259 in 16-bit binary files (refer to : this post).

In Matlab (fread(fid1, 'uint8');): 15

16 bit bin file containing 15:
In WinHex: 0F 00
In java (DataInputStream.readShort();): [3840, 0]
=> 3840/256=15;
=> so, it's a kind of [15 00]
In Matlab (fread(fid1, 'uint16');): 15

16 bit bin file containing 259:
In WinHex: 03 01
In java (DataInputStream.readShort();): [769, 0] //Note, for every byte, java can

contain a value larger than 256, while other programming language will increment.
=> 769%256 = 1; 769/256=3.0039;
=> so, it's a kind of [03 01]
In Matlab (fread(fid1, 'uint16');): 259

Therefore, a integer value in the range of 16-bit, for example 41837. In Matlab,

it will be intepreted as 41837, mod(41837,256)=109, 41837/256=163.4. So 41837 can

be displayed as [163 109] = 163*256+109; while java intepret [163 109] as

163+109*256 = 28067;

This seems wrong inside Java, but Java know how to process such value and export

it correctly to another bin file, which one can be understood by Matlab, WinHex or

other programming languages or editor.

Tuesday, 21 July 2009

Simplest procedure to TRIPLE BOOT on Macbook

The must:

  • Only ONE partition for Linux; Only ONE partition for Windows. (to satisfy Windows)
  • Windows must locates at the last partition. (to satisfy Macbook)
  • Before installing, ensure the partitions are ready and good! (Disk Utility normally can not do this, or do half of this task. Because it will create several 'spare spaces' between each partitions made by it, these partitions always make the Windows installation fail due to more than 4 primary partitions existing. But Disk Utility can create one more partition from the original one whole partition, then split it using other ways, which includes 'diskutil' in Mac, 'gparted' from Linux Livecd or even the Windows installer during Windows setup). Any partitions modification will make Windows can not boot up even synced by rEfit.

  • - If Windows has been installed by Boot Camp. Try to change boot.ini in my windows partition (disk util create a new partition between mac and windows and messed up my boot.ini, the partition it tried to boot (third) is now linux Hd instead of windows (become 4th. This might be your problem. It gave me BSoD right after splash screen)

So the procedure:

  2. sync mbr/gpt using rEfit. (maybe can be ignored)
  3. Install Winxp on the 4th (last) partition.
  4. sync mbr/gpt using rEfit.(maybe can be ignored)
  5. Install Linux.

Java/Matlab read and write 16-bit data file

  • Read 16 bit binary file:
    File file = new File("FILENAME.bin");
    FileInputStream fis = new FileInputStream(file);
    BufferedInputStream bis = new BufferedInputStream(fis);
    DataInputStream dis = new DataInputStream( bis );

    short[] myarray = new short[256000];
    int cnt;
    for (cnt = 0; cnt < 256000; cnt++) {

    myarray[cnt] = dis.readShort();


    RandomAccessFile dis = new RandomAccessFile(new File("FILENAME.bin"), "r");

    1) bufferedInputStream can be ignored, but it will improve the performance 90% for large file operation.
    2) RandomAccessFile works like a 'pointer', similar to fread in Matlab, offset or skip can be assign when data retrieving while not really load all the file. This class has both read and write methods, it is a convenience class, like filereader and filewriter, while the former method is kinda low level methods.

  • Write 16 bit binary file:
    FileOutputStream fos = new FileOutputStream(new File("OUTPUT.bin"));
    BufferedOutputStream bos = new BufferedOutputStream(fos);
    DataOutputStream dos = new DataOutputStream(bos);

    for (cnt = 0; cnt < 256000; cnt++) {

    myarray[cnt] = dis.readShort();




    RandomAccessFile dos = new RandomAccessFile(new File("OUTPUT.bin"), "rw");
    Note: The following step is essential!!!! Otherwise, there will be some data lost.
  • Matlab:

    fid1 = fopen('filename.bin', 'r');
    A = fread(fid1, 100, 'uint16=>float32');

    fid2 = fopen('output.bin', 'w');
    fwrite(fid2, A, 'uint16');

Sunday, 19 July 2009

BUG, HOWTO: how java read 8-bit and 16-bit

you have to use twice as much memory, but there really is no other solution:

use a short to hold an unsigned byte, use a long to hold an unsigned int. (And use a char to hold an unsigned short.)

This example create a 16-bit file, which only contain a value, 15 in 16-bit (000f), This file can be viewed by Gedit. From Matlab, it can retrieve and display correctly as 15, but in Java, using DataInputStream.readShort(), it's 3840, which equals to 15*256.

Example 1: Using Matlab to generate a 16-bit data file.
clear;clc;%% create binA=15;fid = fopen('output.bin', 'w'); fwrite(fid, A, 'uint16');fclose(fid);%% read binfid1 = fopen('output.bin', 'r'); B = fread(fid1, 1, 'uint16')fclose(fid1);

Example 2: Using Java to retrive the 16-bit data from the bin file.
import*;public class convbin { public static void main(String args[]) throws IOException { File file = new File("onev.bin"); FileInputStream fis = new FileInputStream(file); BufferedInputStream bis = new BufferedInputStream(fis); DataInputStream dis = new DataInputStream( bis );// RandomAccessFile dis = new RandomAccessFile(new File("fotech1.bin"), "r"); short[] myarray = new short[256000]; int cnt; for (cnt = 0; cnt < 1; cnt++) { myarray[cnt] = dis.readShort(); } fis.close(); System.out.println("Done."); FileOutputStream fos = new FileOutputStream(new File("o22.bin")); BufferedOutputStream bos = new BufferedOutputStream(fos); DataOutputStream dos = new DataOutputStream(bos);// RandomAccessFile dos = new RandomAccessFile(new File("o22.bin"), "rw"); for (cnt = 0; cnt < 1; cnt++) { dos.writeShort(myarray[cnt]); } System.out.println("Finish."); bos.flush(); fos.close(); }}

More details, except the example:

Friday, 17 July 2009

HOWTO: run remote X11 applications

The server is running on Linux. To run the remote server applications on my own machine:

  • On Windows:
    1. Install Xming as the X11 server.
    2. Run Putty, as ssh client, with the X11 forwarding arguments: 'localhost:0' or ':0', or even with blank only enable forwarding.
  • On Mac OSX
    1. run: ssh -X -l username 192.168.1.XXX
    * using Putty: with the X11 forwarding arguments: ':0'!!!!!!!!
  • On Linux
    1. run: ssh -X -l username 192.168.1.XXX
    * using Putty: with the X11 forwarding arguments: ':0' or blank.

Sunday, 12 July 2009

HOWTO: install Adobe Air on Feodra 11

Just guest Redhat developers want to improve the boot speed, they make the fedora 11 without some 'useful' packages by default. This makes some program can not installed properly, such as Adobe Air.

The fix:

yum -y install xterm gtk2-devel gnome-keyring libxml2-devel libxslt rpm-devel nss
From: yum -y install xterm gtk2-devel gnome-keyring libxml2-devel libxslt rpm-devel nss

放弃在Mac 10.5.7 上安装GNUstep 0.23

经过大半个星期的下班时间调试,尝试在Mac osx 10.5.7 (darwin 9.7)上安装GNUstep 0.23,最终没有成功,还把Mac弄残一次,我猜可能是由于compiling的时候出现的segmentation fault致使Kernel Panic。

  1. make的时候,常常是需要 $LDFLAG 比用到 $DYLD_LIBRARY_PATH 的时候多。后者貌似更像是运行程序的时候使用,而不是configure和make时候用。
  2. Mac作为操作系统,其界面无可争议,但是底层系统方面,我个人觉得还不如Linux。在最近的console下编译程序的时候,出现两次致使Mac不断重启的情况,而解决方法都是不得不重装系统后,第二次更离谱,连cmd+s的single user mode都无法进入。Mac啊,现在给我的感觉是典型的外强中干。
  3. GNUstep需要有gnu的objc runtime,如果用默认的设置,必然使得其调用mac自带的gcc和objc的库,这样肯定会带来些兼容性的问题。 我猜我弄出的两次mac无法开机不断重启,与此两种不兼容并冲突的objc有关系。因为GNUstep在ubuntu 9.04和fedora 11下编译运行的很好。如果想在Mac上安装,我觉得还得是要等macports提供,macports跟进的还算不错,对gnustep,和官方新版本放出的时间也就差2个星期左右。可是,macports下的objc目前还不能安装,等到这个出现后,可以再试编译gnustep源文件。

#export LDFLAGS='-L/usr/local/lib -L/usr/lib -L/opt/local/lib -L/sw/lib'
export LDFLAGS='-L/opt/local/lib -L/sw/lib -L/usr/GNUstep/Local/Library/Libraries'
#export DYLD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/opt/local/lib:/sw/lib

export CPPFLAGS='-I/opt/local/include -I/sw/include'
#export CFLAGS='-I/usr/local/include -I/usr/include -I/opt/local/include -I/sw/include'

export PATH=/opt/local/bin:/opt/local/sbin:/sw/bin:/sw/sb:/usr/bin:/bin:/usr/sbin:/sbin

#. /usr/GNUstep/System/Library/Makefiles/

注:个人认为,在编译gnu的程序时,最好避免用到mac自带的一些命令。而且,最好在编译之前,把/usr/bin/gcc改成是 /opt/local/bin/gcc-mp-4.2这样的,以防止避免gnu和mac的程序冲突。

Thursday, 9 July 2009

HOWTO: remove files older than N days

Command Syntax

find /path/to/files* -mtime +5 -exec rm {} \;

Note that there are spaces between rm, {}, and \;

Extremely useful for Miro, because it doesn't delete files unwatched. So with this command added in /usr/bin/miro, the Miro library will keep only latest videos no matter you watch it or not.

The first argument is the path to the files. This can be a path, a directory, or a wildcard as in the example above. I would recommend using the full path, and make sure that you run the command without the exec rm to make sure you are getting the right results.
The second argument, -mtime, is used to specify the number of days old that the file is. If you enter +5, it will find files older than 5 days.

The third argument, -exec, allows you to pass in a command such as rm. The {} \; at the end is required to end the command.

Command from:

Tuesday, 7 July 2009

HOWTO: compile source code on MAC OS X


Macport (recommended, can be found on, updated and organized well) and Fink are installed in default locations, /opt/local and /sw.

Note: Fink is buggy, normally reinstallation on the previous version will not work, issues like path setup maybe occur, either bin files or libraries are not accessible.

To compile:
  1. For library invoking:
    export LDFLAGS='-L/usr/local/lib -L/usr/lib -L/opt/local/lib -L/sw/lib'
    - '-L/dir' is the convention to setup gcc switch, while -L for make is --check-symlink-times, useless for me :)
    - Official way for invoking library is to setup $DYLD_LIBRARY_PATH (export DYLD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/opt/local/lib:/sw/lib), which in Linux is $LD_LIBRARY_PATH by default.
    - Normally lib path don't need specified, because the bin files (in /usr/bin or /opt/local/bin' will know where to get appropriate libraries, no matter bin files from Macports or Fink.

  2. For header files invoking:
    export CPPFLAGS='-I/usr/local/include -I/usr/include -I/opt/local/include -I/sw/include'
    - This is the way to setup both 'make' and 'gcc' switch, which is 'make -I/usr/local/include'.

The following are what I typed in terminal with user root to compile GNUstep-0.22.

export CPPFLAGS='-I/usr/local/include -I/opt/local/include'
export LDFLAGS='-L/usr/local/lib -L/usr/lib -L/opt/local/lib -L/sw/lib'
export DYLD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/opt/local/lib:/sw/lib:/usr/GNUstep/Local/Library/Libraries
. /usr/GNUstep/System/Library/Makefiles/

Sunday, 5 July 2009

MAC OS X: change the environment PATH

To add a new directory to the path, simply add it to the existing PATH line in .profile being careful to separate it from other directories there with colons and careful not to introduce unwanted spaces (everything after the space will be ignored). For example, to add the directory /mightyq/bin to the PATH shown above, the line could become any of the following examples:

export PATH=/mightyq/bin:/opt/local/bin:/opt/local/sbin:$PATH
export PATH=/opt/local/bin:/mightyq/bin:/opt/local/sbin:$PATH
export PATH=/opt/local/bin:/opt/local/sbin:$PATH:/mightyq/bin

Note that in the third example the new directory is added to the end of the PATH. You have the ability to optimize the searches your shell will do on your behalf each time you run a command by organizing your PATH logically. Putting less frequently used or really massive directories later in the path may give you a little performance boost (although these days things are pretty fast, so you have to be a little anal to really enjoy this).

If you don’t need a directory in your path, you can reverse the process by deleting the unwanted directory still taking care to preserve the no spaces, colon separation rules.

One last note, to test the change you made, you can use the echo command, but you need to make the shell reload the .profile first. Assuming you are in your home directory (if not, running ‘cd’ without any options will take you there), run these commands:

. ./.profile
echo $PATH

The first . is a shortcut to cause the shell to ’source’ or load the contents of the subsequent file as itself, in the manner that the shell uses when you login to a system or start a Terminal window. If you simply executed these commands like a shell script (bash .profile, for example) you would start a new shell, that shell would get the variable set, and at the end of running the .profile script, that new shell would cease to exist and the newly defined variables would be relegated to the missing sock universe.While . makes the variables generated from new shell ( child shell ) return to the current shell (parent shell).

Saturday, 4 July 2009

BUG: GNUstep Project Center can not generate the conf for 'MAIN_MODEL_FILE'

GNUstep Project Center (0.5.0) can not generate the conf for 'MAIN_MODEL_FILE', therefore, to make the GUI (gorm style) work, put corresponding configuration in the 'GNUmakefile'. Like the following:

# Main application



The missing part in Gorm Manual on GNUstep, about 'NewClass' controller

8 Creating an Application
If you have ProjectCenter, you need to open it and create an “Application” project.
Create it with the name “FirstApp”. From there you can open the MainMenu.gorm by
clicking on interfaces and selecting MainMenu.gorm. If is properly installed, you
Gorm should start up.
If you don’t have ProjectCenter, you can create the Gorm file by hand. First you need
to start Gorm. You can either do this by doing ‘gopen’ from a command line
prompt, or you can invoke it from the Dock or from the workspace’s file viewer.
You then need to select the ‘Document’ menu, and then ‘New Application’. This should
produce a new document window, with a menu and an empty window. This should be
the same as with the ProjectCenter gorm file since this is the basic starting point for an
For the sections below... only do one or the other, not both.
8.1 Creating A Class In Gorm
There are two ways to do this next operation. I will take you through each step by step.
First click on the classes icon in the toolbar on the top of the Gorm document window.
You should see the view below change to an outline view containing a list of class names.
Once this happens we’re ready to create a class. Select the class you wish to subclass in
the outline view. For our example we will use the simplest: NSObject. Select it by clicking
on the class name once. Then go to the Classes menu in the main menu and select Create
Subclass (you can also type Alt-Shift-c, which will do this as well. The new class will be
created in the list with the name “NewClass”.
8.2 Using The Outline View
From here double click on the subclass name to make it editable. Type the name of the
class and hit enter. For our example, please use the class name MyController. When you
hit enter an alert panel will appear and warn you about breaking connections, simply select
OK and continue.
This method of inputting the classes was inspired by IB in OPENSTEP 4.2/Mach which
had functionality very similar to this. For users of that the transition to Gorm will be
8.2.1 Adding Outlets In The Outline View
Too add an outlet, select the round icon with the two horizontal lines in it (it sort of looks
like a wall outlet. This should become depressed. Here you need to go to the Gorm Menu,
under Classes select “Add Outlet/Action”. Each time you press this menu item another
outlet will be added with a name similar to newOutlet, as you add more the number at the
end will increase. For now add only one outlet.
To rename the outlet simply double click it and change it’s name like you did the class
above to “value” for the sake of our example.
Chapter 8: Creating an Application 20
8.2.2 Adding Actions In the Outline View
The procedure to add on action is precisely the same as adding an outlet, except you
must click on the button which looks like a target (a circle with a + inside). Add an action
and name it “buttonPressed:” for the sake of our example.
8.3 Using The Class Edit Inspector
This way is much more inline with the “OPENSTEP/GNUstep” philosophy. For each
object there is an inspector, even for Class objects.
Once you have created the class as described in the previous section “Creating a Class
In Gorm”, you must skip to this section to use the inspector. In the Gorm main menu
select Tools and then select “Inspectors”. This will make certain that the inspectors win-
dow is being displayed. Once the inspectors window is up move the pulldown on the top
to “Attributes” and select the class you created which should, at this point, have the name
“NewClass”. You’ll notice that the “Class” field at the top which shows the name’s back-
ground color has turned white, instead of grey. This indicates that this class name is
editable. Erase “NewClass” from the text field and type “MyController”.
8.3.1 Adding Outlets In The Inspector
Adding outlets is very intuitive in the inspector. Simply select the “Outlets” tab in the
tab view and click “Add” to add more outlets, and “Remove” to remove them. For the sake
of our example, add one outlet and name it “value”.
8.3.2 Adding Actions In the Inspector
Very much like above only with the “Actions” tab, add an action called button pressed.
8.4 Instantiating The Class
In the Classes outline view select the new class you’ve created, now called MyController
and then go to the Gorm menu and select Classes, and then Instantiate. The document
window should shift from the classes view to the objects view. Amoung the set of objects
should be a new object called MyController.
8.5 Adding Controls from the Palette
Go to the Gorm menu and select Tools, then Palettes. This will bring the palette window
to the front. The second palette from the left is the “ControlsPalette”. Select that one and
find the button object (it should have the word “Button” in it). Drag that to the window
and drop it anywhere you like.
Repeat this operation with the text field. It’s the control with “Text” in it. We are now
ready to start making connections between different objects in the document.
Chapter 8: Creating an Application 21
8.5.1 Making Connections
The type of application we are creating is known as a “NSApplication delegate” this
means that the MyController object will be set as the delegate of NSApplication.
To make this connection click on NSOwner and hold down the Control button, keep it
pressed as you drag from the NSOwner object to the MyController object. The inspectors
window should change to the Connections inspector and should show two outlets “delegate”
and “menu”. Select the “delegate”, at this point you should see a green S and a purple T
on the NSOwner and MyController objects respectively, and press the “Connect” button
in the inspector. In the “Connections” section of the inspector you should see an entry
which looks similar to “delegate (MyController)” this indicates that the connection has
been made.
Now we need to make connections from the controller to the textfield and from the
controller to the button. Select the MyController object and Control-Drag (as before)
from the object to the text field, this will make an outlet connection. You should see the
connections inspector again, this time select the “value” outlet and hit Connect.
Next, control-drag from the button to the controller, this will make an action connec-
tion. The connections inspector should again appear. This time you need to select the
“target” outlet, to get the list of actions. The list should have only one entry, which is
“buttonPressed:” since this is the one we added earlier. Press Connect. You should see an
entry like “buttonPressed: (MyController” in the Connections section of the inspector.
It is also possible to make this connection to NSFirst, but to keep things simple, make
it directly to the object. If you make the connection to buttonPressed: on NSFirst the
functionality of the application will be unchanged, but the invocation will take the path
described above in the section which describes “The Responder Chain”.
8.6 Saving the gorm file
At this point you must save the .gorm file. Go to the Gorm menu and click Documents
and then select “Save”. If the document was opened from a pre-existing .gorm, it will save
to that same file name. If it is an UNTITLED .gorm file a file dialog will appear and you
will need to select the directory where you want to store the .gorm file and type the name
of the .gorm file.
8.7 Generating .h and .m files from the class.
This is different than saving, some people have gotten this confused with the idea of
Gorm generating the code for the gui. Gorm does nothing of the sort (grin).
Go to the Classes section in the Document window and select the MyController class yet
again. Now go to the Gorm menu and select Classes and the select “Create Class Files”.
This will bring up a file panel and it allow you to select the directory in which to put the
files. It will first create the MyController.m file and then the MyController.h file. Simply
select the directory in which your app will reside and hit okay for both. You can change
the names, but the default ones, which are based on the class name, should be sufficient.

When you look at the .m for this class, you should see the ‘buttonPressed:’ method with
the commecnt ‘/* insert your code here */’ in it. Delete this comment and add ‘[value
setStringValue: @‘‘Hello’’];’. The class should look like this after you’re done:
/* All Rights reserved */
#include "MyController.h"
@implementation MyController
- (void) buttonPressed: (id)sender
[value setStringValue: @”Hello”];
You recall, we connected the textfield to the “value” variable. The call above causes the
method setStringValue to be invoked on the textfield you added to the window.
Also, note that the name of the method is “buttonPressed:”. This is the action which is
bound to the button. When it is pressed the text in the textfield should change to “Hello”.
You now need to build the application either by copying in a GNUmakefile and making
the appropriate changes or by using ProjectCenter’s build capability, depending on if you
use it or not.
This app is available as “SimpleApp” in the Examples directory under the Documen-
tation directory distributed with Gorm. Hopefully this has helped to demonstrate, albeit
on a small scale, the capabilities of Gorm. In later chapters we will cover more advanced
application architectures and topics.

Friday, 3 July 2009

HOWTO: add shared libraries to lib path in Linux

Permanent way:
  • Create a new file in /etc/ called .conf
  • Edit the file and add a line per directory of shared libraries (*.so files), it will look something like:
Reload the list of system-wide library paths:
  • sudo ldconfig
Temporary way:
  • export LD_LIBRARY_PATH=/your/lib/path
On Mac, the dynamic library path is $DYLD_LIBRARY_PATH

Saturday, 13 June 2009

BUG: eclipse starts with empty dialog


sudo apt-get install xulrunner
( sudo yum reinstall xulrunner on fedora)

append to eclipse.ini


Thursday, 11 June 2009

BUG: Videos are twisted in Feodar 11 first week

Many users are already aware from coverage in the press that significant changes have recently been made to the driver for Intel graphics adapters (and the supporting code in Mesa/DRI and the kernel), and that these have caused some functionality regressions. If you are suffering from problems with an Intel graphics adapter such as failure of X to start at all, hangs or freezes or crashes in the graphical environment, display corruption, failure of 3D accelerated applications to work properly or similar problems, and your issue is not specifically covered elsewhere on this page, the following general advice may be of use.

1) Several such issues may be worked around by disabling kernel mode setting. To do this, add

as a kernel parameter. If this solves your problem, please check whether a bug has already been reported for it, and if not, file a new bug report on the xorg-x11-drv-intel component, explaining your symptoms, and providing all the usual information required for bug reports. In future kernel mode setting will be the only available method, and so we wish to ensure all problems caused by kernel mode setting are fixed.


2) when 'nomodeset' was appened in the kernel line, it seems some visualization functions were affected, such as mp4 files can not played and mp3 files can not played with MOVIE PLAYER, which use some visualization graphic when music is playing. The symptoms are same, the video/audio will be closed or you will be logged out directly.

To fix this, the video driver of VESA should replace the default INTEL driver in system-config-display.

Friday, 29 May 2009

HOWTO[zen-cart]: disable random on homepage

At beginning.
Copy featured_products.php / new_products.php from /includes/modules/ to /includes/modules/YOURTEMPLATE, then start to edit it.

1. append "order by featured_sort_id DESC" to the two select statements

2. change ExecuteRandomMulti() to Execute()

3. change MoveNextRandom() to MoveNext()

Tuesday, 26 May 2009

The procedure of Zen-cart display home page

1) tpl_main_page.php

2) $body_code is defined in /includes/templates/template_default/common/main_template_vars.php
Here, firstly check whether it's overridden or not by the current template. If not (/not exist overridden main_template_vars.php, then load the default tpl_SOME_PAGE_default.php)
3) If overridden, in the zen-cart pages system, /includes/modules/pages/index/main_template_vars.php defines which tpl file should be loaded to display the home page.
  • tpl_index_categories.php // $category_depth=='nested' 有子分类
  • tpl_index_product_list.php // $category_depth=='products' || zen_check_url_get_terms() 列出所有
  • tpl_index_default.php // the default tpl_SOME_PAGE_default.php 主页默认内容

HOWTO: Add css for IE within zen-cart

1) Prepare a css file for IE, called ie7.css, located in /includes/templates/template_default/my

2) Add the following codes:
echo '<!--[if lte IE 7]><link rel="stylesheet" href="' . $template->get_template_dir('.css',DIR_WS_TEMPLATE, $current_page_base,'my') . '/ie7.css" />'."\n".'<![endif]-->';

around the following codes in /includes/templates/template_default/common/html_header.php

 * load all template-specific stylesheets, named like "style*.css", alphabetically


  $directory_array = $template->get_template_part($template->get_template_dir('.css',DIR_WS_TEMPLATE, $current_page_base,'css'), '/^style/', '.css');

  while(list ($key, $value) = each($directory_array)) {

    echo '<link rel="stylesheet" type="text/css" href="' . $template->get_template_dir('.css',DIR_WS_TEMPLATE, $current_page_base,'css') . '/' . $value . '" />'."\n";


HOWTO: The Zen Cart Execution Process

Zen Cart, like most open-source code, is a largly undocumented.
Luckily for us, it also has a habit of mixing in much of it's
program/application logic with it's actual HTML design, so it's not
only undocumented, it's also hard to browse the HTML code. To top it
off, it also has a dynamic template loader, which means that the
program logic and HTML templates could be in any one of four different
directories. Also undocumented, and of dubious usefullness.

The result is that it's not only difficult to browse through the
program logic and HTML code, but you often don't even know which files
are going to get loaded.

This document is an attempt to sort through the overarching structure of how Zen Cart tends to work.

index.php steps:

Here's where all of action begins.
  1. it loads 'includes/application_top.php'
  2. if $main_page isn't set, it gets set to 'index'
  3. if the directory 'includes/modules/pages/$main_page' doesn't exist, $main_page gets set to 'index'
  4. it loads all of the files starting with 'header_php' in 'includes/modules/pages/$main_page'
  5. now it loads 'html_header.php' from the first first place it finds it from the following directories
    1. includes/templates/mytemplate/$main_page/
    2. includes/templates/template_default/$main_page/
    3. includes/templates/mytemplate/common/
    4. includes/templates/template_default/common/

  6. now it does the same thing for finding and loading 'main_template_vars.php'
  7. now it does the same thing for finding and loading 'tpl_main_page.php'
  8. Finally it displays the '</html>' tag. Why display it here when the '<html>' tag is displayed somewhere else? Who knows.

application_top.php steps:

This file will load in all of general definitions used site-wide,
initialize some site-wide classes ($template, $db) and do other general

html_header.php steps:

The default html_header.php file will simply create all of the HTML up to the </head> tag
It loads 'includes/modules/meta_tags.php', which uses a bloated switch statement to figure out what the site's title, meta-keywords, and meta-description should be.
It tries to find the css directory, and loads in it all stylesheets that begin with 'style' and end with '.css'
It does the same thing for the jscript directory, and tries to load all files that begin with 'jscript_' and end with '.js'

main_template_vars.php steps:

it simply sets $body_code to the first of:
  1. includes/modules/pages/$main_page/main_template_vars.php
  2. includes/templates/mytemplate/$main_page/tpl_{$main_page}_default.php
  3. includes/templates/template_default/$main_page/tpl_{$main_page}_default.php
  4. includes/templates/mytemplate/templates/tpl_{$main_page}_default.php
  5. includes/templates/template_default/templates/tpl_{$main_page}_default.php

that's it.

tpl_main_page.php steps:

this file lays out the basic page.
  1. <body>
  2. loads the 'includes/modules/header.php' file
  3. if the left column is enabled, it loads 'includes/modules/column_left.php'
  4. it loads the file set in $body_code
  5. if the right column is enabled, it loads 'includes/modules/column_right.php'
  6. loads 'includes/modules/footer.php'
  7. </body>

includes/modules/pages/$main_page/main_template_vars.php steps:

is where the meat of the actual content if loaded and displayed.
it typically does all of the program logic first, sets all of the
necessary variables, and then loads the template file. As usual, the
template file is loaded from the first of the following:
  1. includes/templates/mytemplate/$main_page/
  2. includes/templates/template_default/$main_page/
  3. includes/templates/mytemplate/templates/
  4. includes/templates/template_default/templates/

The standard is that the template file will be named 'tpl_SOMENAME.php'. Note that it doesn't end with '_default.php'. The undocumented naming convention is that files that end with '_default.php' are files that get loaded with it can't find the 'includes/modules/pages/$main_page/main_template_vars.php' file.

tpl_{$main_page}_default.php steps:

If it doesn't find the
above file and it instead finds a tpl_*_default.php file, then it means
that all of the program logic and variables will be mixed up with the
actual displayed HTML code. In Zen-Cart's defense, this generally means
that there's not a lot of program logic to be had here, hardly any
really, but it's still damn annoying to be mixing the program logic
with design. No sir, I don't like it one bit.

Future Updates

Eventually this document will also cover the process by which the program loads in the language files, such as "english.php" and the content files like "privacy.php" and "conditions.php."
The Zen Cart creators actually created these files with the idea that
they would be a part of your custom template, which is a clear
violation of the content/design seperation.

This document will also cover sideboxes (which requires a whole
nother custom template directory). As an interesting sidenote, when you
switch to a new template, all of the sideboxes get turned off. The
level of user-unfriendliness of Zen Cart is amazing to me sometimes.

This article is from:

Saturday, 16 May 2009

HOWTO: [MAC] Move User to a different partition

Move User to a different partition

As we have hopefully set up a separate partition for our private data, here’s the bash-way of moving a home. (based on this article)

  1. in 'Disk Utility' to setup a new partition with 'Mac OS Extended (Journaled)' format, I call it 'home'.
  2. copy the whole home to your new partition:

    # sudo su -
    # cp -Rp /Users/username /Volumes/username
  3. Now we use Directory Services which can be accessed by dscl (Directory Services Command Line):

    # sudo su -
    # dscl localhost
    > cd /Local/Default/Users
    > change username dsAttrTypeNative:home /Users/username /Volumes/home/username> exit

Reboot, verify if your user data is at the new spot and then delete it from the old spot (/Users/username).

Wednesday, 13 May 2009

HOWTO: hide 隐藏 SHOPEX footer 'powered by shopex'

Shopex use zend encoder to protect their commercial product. To run it, the 'zend-optimiser' is needed for decoding. Some web servers do not provide this module, such as ONE.COM. Therefore, to remove this 'footer' slogan, you must have their license the override the encoded php file.

Here is a hack to remove this 'powered by shopex' from footer, using 'mootools', which is coming with shopex installation automatically.

  1. go to /themes/THEME NAME/block/footer.html.
    Use '<div id="footer_remove">' and '</div>' to surround the '<{foot}>'
  2. go to /themes/THEME NAME/block/header.html.
    Add the following javascript after '<{head}>'

    <script type="text/javascript">

    window.addEvent('domready', function() {

    var fa=$('footer_remove').getElements('a[href^=]');

    fa.setStyle('display', 'none');

    var fb=fa.getNext('span');

    fb.setStyle('display', 'none');});




Tuesday, 12 May 2009

HOWTO[mac]: php.ini for both xdebug and zenddebugger in both Eclipse and M(L)AMP

Note: Either zenddebugger or xdebug is not included by default, (all-in-one PDT saying zenddebugger is included), You'd better check and install from software update in Eclipse. can be extract from the dmg file of Komodo .
zenddebugger: from zend or pdt (issued from zend), or

Note: Sometime, when the debugger is changed, the xdebug will not work any more on that project. Copy all the files into a new php project, it will work fine. This seems that the some of the project properties are changed during debuger is changed. (so far, don't know which modified property cause this issue). Refactor, such as rename, the project name will fix it.

The content in the end of php.ini


;----------------------- to be removed; it never runs well with this line


; Sometime, to enable Zend Debugger, Xdebug need to be disabled in php.ini; vice versa.


Monday, 4 May 2009






男儿自立 必须有倔强之气



  • 男儿自立,必须有倔强之气。

曾 国藩的倔强性格,在他最初出来带兵的时候表现得最为突出。他是以在籍侍郎的身份出来带兵的,没有地盘,无粮饷,事事仰给于人。偏偏曾国藩又是勇于任事之 人,因而与地方官员势同水火,屡屡发生冲突。加上初期与太平军作战屡战屡败,更是使他的处境雪上加霜。然而在与官场政敌和与太平天国的双重博斗中,他却养 成了一种咬牙立志、不肯认输的脾气。他自己将之称之为“打脱牙,和血吞”的“挺”字功夫。他曾经夫子自道说:





  • 倔强并不是刚愎自用



担 当大事,全在于明、强这两个字。所有的事,没有志气和刚强都是无法成功的。即使是修身齐家,也必须以明强为根本。“难禁风浪”这四个字说得很好,我把它再 送给你。自古以来,豪杰之士都以这四个字为大忌。我家祖父教人,也以“懦弱无刚”四个字为大耻。所以男儿自立于世,一定要有倔强之气。

  • “强”字须从“明”字做出




  • 看清问题之后要坚持到底



  • 天地之道,刚柔互用,不可偏废




曾国藩的为官之道,说白了,就是一种智慧。而这种智慧,主要是来自于中国传 统文化。曾国藩确实是一个悟透了中国文化的人,他的为人行事,也无不体现出中国文化的影响。他的以天下为己任,明显体现出儒生的进取精神;他的“花未全开 月未圆”、“晚场善退”,明显体现出道家的影响;他的治乱世用重典,学的是所谓的“申商之术”,他的俭以奉身、勤以治事,则明显体现出的是墨家的影响。 儒、道、法、墨四家的思想,在曾国藩身上都得到了充分的体现。

从文化的角度来说,曾国藩就是传统文化的化身。他非常善于将性理之学与经世致用结合贯通,他讲究人生理想, 讲求精神境界,讲求道德修养与自我完善,他的反省内求,日新又新,磨砺意志,勤俭刻苦,力戒虚骄,以恒为本等修身原则,在很大程度上体现了中华民族的优秀 美德。他以一介儒生,居然将燃烧了大半个中国的太平天国革命的烈火给扑灭了下去,这其中自然也有他成功的经验。曾国藩是一个理学家,他有深厚的传统文化底 蕴,但又绝对不是一个书呆子。毛泽东曾经说:“吾于近人,独服曾国藩。观其收拾洪杨一役,完美无缺,设使易以他人,岂能若是?”陈毅元帅也说过:“曾国藩 用兵很有一套,在军事上很值得研究。”其实何止是军事,曾国藩为官一生,他的“以天下为己任”的追求(当然他的“天下”毕竟是清王朝的“天下”),他的忧 患意识,他的打脱牙和血吞的刚毅精神,他对子弟、子女的教育方法,他在逆境之中所表现出来的政治智慧,都是很值得研究的。尤其是曾国藩是一个很善于概括的 人,他在不经意中留下的许多话,充满了哲理性,可以说既是他为官一生的经验总结,也体现了传统文化的深厚之所在。这些话,完全是可以当作格言来读的。毛泽 东在论述如何继承传统时提出了一条基本的原则,就是“取其精华,弃其糟粕”。对于曾国藩,我们同样可以采取这样的方法。

曾国藩是一个活生 生的人,他有他的局限,他有他的缺点。他的彷徨,他的郁闷,他的内心矛盾,他的焦虑紧张,都与普通人没有什么区别。他三次自杀,他屡战屡败,他是在不他断 地与自我作战的历程中一步步地完成他的“功业”的。他的成功,从根本上来说,还是出于那坚韧不拔的精神。梁启超在评价曾国藩时曾有过一段非常精譬的话。我 们就以这段话,来为我们的这个专题打一个结。梁启超说:

曾国藩并没有超群绝伦的才华。在当时的著名人物中,他可以说是最不聪明的一个。他 的一生,也一直在逆境之中,然而他立德、立功、立言,达到了古人所说的三不朽的境界,他的成就震古烁今,没有一个人能跟他,这是什么原因呢?他一生得力的 地方,在于立志自拔于流俗,而困而知,而勉而行,历尽百千险阻而不屈服;他不求近效,铢积寸累,受之以虚,将之以勤,植之以刚,贞之以恒,帅之以诚,勇猛 精进,坚苦卓绝,如此而已!如此而已!

Thursday, 30 April 2009

@, in PHP

To supresses error reporting.

Sometmes functions are called with "@' in front of them -
E.g. $somevar = @mail($to,$subject,$msg);

Friday, 24 April 2009

HOWTO: firefox cannot save username & password on

If it just happens on that site try clearing the hotmail cookies. Select Tools > Options > Privacy - In the Cookies section click "Show Cookies..." to access the option for removing cookies.

If you can not use the "remember me" option on other sites as well, a likely cause is the file that stores cookies is corrupt. To test this close Firefox, go to your profile folder and rename cookies.sqlite to cookies.tmp
Restart Firefox, log into those sites and then see if it remembers the logins.

Also make sure that cookies are being accepted and not being deleted when Firefox closes. Go to Tools > Options > Privacy, on that dialog you can make sure that cookies are being accepted, then in the private data section make sure that Firefox is not set to delete cookies when Firefox closes. Also click on the Exceptions button in the cookies section to make sure cookies from those sites are not being blocked.

Next check any internet security software to make sure it is not blocking or deleting cookies. Some internet security software has privacy options that can block or delete cookies.

Monday, 20 April 2009

My MAC applications

Large files:
xcode developer
Photoshop cs4 trial
Dreamweaver cs4 trial

NTFS-3g (


Adobe reader
Adobe flash player
Calaboration_1.0.2 (iCal sync with Google Calendar)
ffmpegX (video converter, 3gp to mp4/avi etc.)
Messenger (Microsoft)
Speed download (buy)
Textmate (buy)

Sunday, 19 April 2009

MAC: X11 on Mac 10.5.6

The X11 download on is for Panther 'only'. So it will never be installed successfully. You will get the error prompt like "You cannot install X11 on this volume. A newer version of this software already exists on this volume."

Your best bet for staying current with bugfixes is to install the latest X11 package (at the moment X11 2.3.0) released by the Xquartz project, which contains Xquartz-1.4.2-apple5, and includes many fixes outside of Xquartz. Afterwards, just install the latest binary versions of Xquartz released periodically as fixes are being made. To see the complete list of changes in release X11-2.3.0, please go here.

After this installation, run the from /Application/Utilities/, then run terminal from the X11 Application menu. In this xterm based terminal you can run those x11 applications installed by macports or fink, also run those like gimp which need x11 environment.

For example:
1) run gedit
2) run gimp
open -a gimp or open /Applications/

Saturday, 18 April 2009

MAC: startup item

1. Accounts settings in System Preferences. There is a tab called "Login Items".

2. All the system's start up items (as opposed to login items) should be located in a folder named StartupItems in your hard drive's /Library.

Friday, 17 April 2009

Mac 10.5.6 on PC (ipc osx86 10.5.6 on Dell dimension 5150)

Dell Dimension 5150:

Burn it using the lowest speed is important.
The supported hardware list:

Intallation options:
try not to select extra driver and patches, which can be installed easily after successful installation.

To remove kext cache in 10.5.6 or later just run:
sudo rm -rf /System/Library/Extensions.mkext

Kernel: 9.5 voodoo (the default kernel 9.6 will bring black screen; After upgrade to 10.5.7, the voodoo kernel need to be reinstalled)
ethernet driver: intel pro/100 ve (tips for your particular device: modifying Info.plist)
audio: the patch or driver coming with this iso doesn't work for my Dell Dimension 5150, the available driver is here.
video: typing '-x "Graphics Mode"="1280x1024x32@85" as boot flag to change the screen resolution. More details are here.
Alternatively, using ATI 9700 driver as the driver for x300, this will remove small square around mouse, but still no QE support in Leopard. + ATI Radeon x300 PCI-Ex Callisto v.008 to change the screen resolution.

seatbelt (to solve mounting dmg file kernel panic issue)
shutdown (seems not work properly)
"NTFS-3g (" can be installed later as a software

Sleep problem: (I did both together, so far don't know which fixed this problem. This happened when I upgrade to 10.5.7)
1) try to remove useless ATI and Gefore kext from /System/Library/Extensions.
2) GMA driver ( I removed the ATI VGA card, because it doesn't support Quartz Extreme. )


Monday, 13 April 2009

BUG: f-spot uploading photos to flickr

F-spot will suspend when uploading photos to flickr.

sudo ifconfig wlan0 mtu 1450
then try to upload again.
Where MTU = Maximum transmission unit


As you become more experienced with Linux you maybe want to fine tune your internet connection settings . . . . .

The default of 1460 bytes per packet can vary with the connection, distro or hardware you have.
On some systems you can have better results with low MTU settings and some with high MTU settings, you will just have to see and try what works best for you.

Here is how you can change the MTU settings for your network interface:

First have a look on how the settings are now:

# ifconfig eth0

And you will get something similar to this:

QUOTE = ifconfig
eth0 Link encap:Ethernet HWaddr 00:07:95:XX:XX:59
inet addr: Bcast: Mask:
RX packets:29861 errors:0 dropped:0 overruns:0 frame:0
TX packets:26784 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:6378900 (6.0 Mb) TX bytes:2889677 (2.7 Mb)
Interrupt:11 Base address:0xd400

Now we will test another setting ( MTU 1460 ):
# ifconfig eth0 mtu 1460

And see if you get better results . . . No ? Well, try again
# ifconfig eth0 mtu 1300


# ifconfig eth0 mtu 1200

Now imagine you found the value you want to make permanent: MTU 1250 , pull up the file "/etc/sysconfig/network-scripts/ifcfg-eth0" and make it read:

QUOTE = /etc/sysconfig/network-scripts/ifcfg-eth0

After the next boot the MTU settings will be on 1250

dual boot configuration within XP

When Linux or Mac os86 installed on the disk, where Windows has been installed before, some time it's not set dual boot by defalt. This is the fix, only using the funtion coming along with xp.

in Dos, type:
list disk
select disk 0
list part
select part 3 // could be different depending on your partitions

Saturday, 4 April 2009

HOWTO: gtalk in pidgin

Force old (port 5223) SSL: Checked
Allow plaintext auth over unencrypted streams: Un-Checked
Connect Port: 443
Connect Server:
Proxy type: Use Global Proxy Settings

Tuesday, 31 March 2009

HOWTO: outer DIV can not cover element with FLOAT style

Normally, all the content in the outer DIV will inherit the css styles from it, such as background.
But when the float style is used for inner tag, this part of content may come out of the outer DIV. Also, if you are using Firebug in Firefox, when your mouse is hovering on the outer DIV, the browser then will not cover all the parts inside the DIV.

All are because the FLOAT style.

In this article, Simple Clearing of Floats, 4 methods are intorduced to fix this 'bug', which appears in Firefox, Chrome, while not in IE, this did supprise me. Normally IE is more buggy in my opinion.

My favorite method is to append the outer style with 'overflow:auto'. Then, the floated part will be covered by the outer DIV, no matter the background issue or the selection problem in Firebug.

See also: (other conflicts with some attributes)
text-align for normal div tag ( this will not work 100% in table with align attribute, this will be ignored) and align attribute for table: here

style of marquee in div ( style of div will not work 100%)

Sunday, 29 March 2009

40 Beautiful PSD Slicing Websites


March 27, 2009

Correctly slicing a PSD into XHTML & CSS is an art that takes time to master. If development and coding is not your thing, there are companies that will take your web design file and bring it to life. There are several factors to consider when choosing a PSD slicing company, and one of them is the design of their own site. If their design appears to be low quality, what is their code going to be like? In this article, I’ve listed 40 PSD slicing companies with beautifully designed sites.

40 Beautiful PSD Slicing Websites






HTML Burger

Feather Code

The Designer’s Chop Shop

CSS Rockstars

CSS Ninjas


The Choppr





XHTML Slicer


xHTML Master





We Do Markup

W3 Markup







PSD to WordPress


PSD to Any






Outline to Design

Tuesday, 24 March 2009

Javascipt onload confclits

Normally there are two ways to run javascipt when html page is loaded:

  1. window.onload=INLINE_FUNCTION_NAME, is normally used to make specific javascript runnable when the html document is loaded.
  2. general javascript function, like "function FUNCTION_NAME() {... }; FUNCTION_NAME();"
The problem of method 1) is that one page only can have one onload function. there are always conflicts in Joomla or drupal which use a lot of javascript for functions.

The problem of method 2) is that when the function started, maybe the html document is not fully loaded.

To solve this, 'domready' from mootools helps a lot and improves the loading speed very much. See domready vs load.
Insert mootool.js (optional for Joomla, But required for local html test)
<script type="text/javascript" src="mootools.js">

You should go to to download the latest mootools.js.

Monday, 23 March 2009

HOWTO: Joomla CSS drop-down menu (javascript for IE6)


At beginning, I compared the two drop-down menu raw methods:

Both of them are using suckerfish CSS methods to diminish javascript usage from DHTML.
Because IE doesn't support 'hover' status on 'li', only on 'a'. to solve this problem, there is some javascript for IE, using 'onmouseover'.

The difference between the above two javascript methods, one uses 1)'document.THECLASSOFTAG.getElementsByTagName("LI")' to retrieve <li>, while 2) the other uses 'navRoot.childNodes......' with loop to find out all <li> within the range, which defined by 'document.getElementById("THEIDOFTAG")'.

Javascript in method 1) is NOT supported by IE 6 and 7, even Firefox. This only affect IE 6, others don't need javascript to achieve this drop-down menu.

But, the 'hiding method', which uses 'left:-98%' to hide the submenu from screen is very good and secure, compared with the method using 'display: none', which used in method 2).

Method 2) is just traditional way to parse the html document. But it's for pure HTML practice, not exactly for Joomla.

Therefore, I modified above 2 methods, to make it easily setup on Joomla 1.5.

Make Joomla Drop-Down Menu without install anything

1. Create your Menu with the following Hierarchy:

Menu 1( globalnews ).

– Menu 1 Sub Menu 1 (test).

– Menu 1 Sub Menu 2 (test).

Menu 2( uknews ). // this menu have no submenu

2. Make sure the parameters are set to.

• Menu Style is set to List.

• Always show sub-menu Items is set to Yes.

• Menu Class Suffix is set to -nav - you can pick you own, but then make sure you change it in CSS & JS files. So you will get your menu within

All the menu strcture will be like this ( this can be found from your scource from IE or Firefox:

<div class="pill_m">
<div id="pillmenu">
<ul class="menu-nav">
<li class="parent item63"><a href="/globalnews"><span>Globalnews</span></a>
<li class="item75"><a href="/uknews"><span>test</span></a></li>
<li class="item76"><a href="/uknews"><span>testtest</span></a></li>

<li class="item61"><a href="/uknews"><span>uknews</span></a></li>


here, the 'div class="pill_m"' and 'div id="pillmenu"' is what I put in the templates/MYTEMPLATE/index.php to help me setup the css style.

3. Insert this piece of JS in your template index.php 'head' tag, or in java script file that’s called from index.php.
<!--[if IE]>
<script type="text/javascript">
window.addEvent('domready', function()
if (document.getElementById) {
//navRoot = document.getElementById("pillmenu");
ulTag = pillmenu.childNodes(0);//navRoot==pillmenu, which is a 'id'.
for (i=0; i<ulTag.childNodes.length; i++) {
node = ulTag.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className=temp_cn.replace(temp_cn, "sfhover")
node.onmouseout=function() {
this.className=this.className.replace("sfhover", temp_cn);
  • Here <!--[if IE]> make this script just work for IE, to improve the performance of Fifrefox,safari, they do need such javascript to make the dorp-down menu.
  • window.onload=INLINE_FUNCTION_NAME, is normally used to make specific javascript runnable when the html document is loaded, BUT, in joomla, there always a lot of javascript block in the pages, and one page only can have one onload function. To solve this, 'domready' from mootools helps a lot and improves the loading speed very much. See domready vs load.
  • Even using general javascript function, like "function FUNCTION_NAME() {... }; FUNCTION_NAME();", will not work properly, because when the function started, maybe the html document is not fully loaded. Still, mootools domready event helps.
4. Insert mootool.js (optional for Joomla, But required for local html test)

<script type="text/javascript" src="mootools.js">


You should go to to download the latest mootools.js.

5. Here the corresponding CSS
<style type="text/css">
/*** Copied menu ***/
.pill_m {
text-align: center;
margin: 0 auto;
padding: 0;
background: url(../images/menu.jpg) top center repeat-x;
width: 100%;
height: 41px;
#pillmenu {
margin:0 auto;
#pillmenu ul {
margin: 0;
padding: 0 22px;
list-style: none;
#pillmenu li {
float: left;
margin: 0;
padding: 0;
height: 49px;
background: url(../images/menu_li.jpg) top right no-repeat;
#pillmenu li:hover {
#pillmenu li a#active_menu-nav {
#pillmenu li a {
font-family: Verdana,Helvetica,Arial,sans-serif;
font-size: 13px;
/* float: left;*/
display: block;
line-height: 39px;
padding: 0 24px 0 16px;
color: #111111;/*color: #FFFFFF;*/
text-decoration: none;
font-weight: bold;
#pillmenu li a:hover {
color: #CCCCCC;
.pill_m li ul { /* second-level lists */
position: absolute;
left: -98%; /* using left instead of display to hide menus because display: none isn’t read by screen readers */
.pill_m li:hover ul, .pill_m li.sfhover ul { /* lists nested under hovered list items */
left: auto; /* change is to 10px, 20px, etc for indenting the sub menue */
z-index: 100;
#pillmenu li.parent ul li, #pillmenu li.sfhover ul li{
background: url(../images/menu.jpg) top center repeat-x;
#pillmenu li.parent ul li a, #pillmenu li.sfhover ul li a{
font-size: 10px;
line-height: 20px;
Here the background can be changed as you want, or set it 'none' or other colors.
Have a try, If you got any problems, comment here to let me know.

Wednesday, 18 March 2009

CSS Differences in Internet Explorer and FireFox

1) parentElement

innerText VS elem.firstChild.nodeValue;
This uses W3C DOM compliant properties to retrieve the text value of the first TextNode of the cell. This makes it more likely to work across browsers.

2) Width in IE and Firefox

According to standard (that FireFox follows), content width is set excluding paddings and border(see figure there).
"The size of the box is the sum of the element width (i.e. formatted text or image) and the padding, the border and the margin areas".

But in IE the width of the box is the width of the content plus any border or padding.
In other words:
width(IE)="padding-left"+"border-left"+ width(FF) + "padding-right"+"border--right".


More tips can be found in Adrian Anttila's post JavaScript differences in Firefox and Internet Explorer

Tuesday, 17 March 2009

Which CMS? Drupal vs. Joomla vs. Wordpress

Here is a video from 5th Ultra Light Startups. There are 3 people from Drupal, Joomla and Wordpress, who are introducing these 3 CMSes.

A basic idea can be got when you see this video, more details can be found on

Monday, 16 March 2009

IE CSS: texts display incompletely

Some texts, huge ones, bigger than 20px, especially link (<a>), will not display completely in IE. Always missing the top part of the characters.

1) This just happens when the texts are embedded in 'table', while no problem with 'div'.

2) Not the problem of the height of 'tr'. No matter how you change it, it will not fix it.

3) The real reason is the 'line-height', which normally declared in 'body' part.

in the specific table, to use class or ID to select the table you want to modify, add 'line-height', make it 10%-15% bigger than that declared in body part.

This variable is just like the line space we always use in OFFICE WORD, normally I set it to 1.5, to make it look comfortable.

Friday, 13 March 2009

Php, Joomla: alphacontent(joomla component) show youtube thumbnail

A very good frontpage component for joomla, AlphaContent, can pick up photos from article as thumbnail on the article list. However, it just pick up thumbnail for articles, which have photos inside, not for those only embed video object.

Modify the 'function findIMG( $contenttext, $showfirstimg)', in /components/com_alphacontent/assets/includes/alphacontent.functions.php, will solve this problem.



$contenttext = <<<youtube
<div><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase=",0,40,0" width="425" height="350"><param name="width" value="425" /><param name="height" value="350" /><param name="src" value="" /><embed type="application/x-shockwave-flash" width="425" height="350"

$showfirstimg = '1';

//<img width="20" src=""></img>

function findIMG( $contenttext, $showfirstimg ) {
$image = "";

// check is there any img tag/images
if (preg_match_all('#<img(.*)>#', $contenttext, $match0) ) {
if ( count($match0) ) {
$n = sizeof($match0[1]);
if ( $showfirstimg=='2' ) {
$contenttext = $match0[1][$n-1];
} else $contenttext = $match0[1][0];
// else $contenttext may just host video 'src'

// for image search
if ( preg_match_all('#src="(.*)"#Uis', $contenttext, $match ) ) {
if ( count($match) ) {
$n = sizeof($match[1]);
if ( $showfirstimg=='2' ) {
$image = $match[1][$n-1];
} else $image = $match[1][0];
return $image;

// for youtube video search, just the first video thumbnail
if ( preg_match('#src="(.*)"#Uis', $contenttext, $match_video ) ) {
if ( count($match_video) ) {
if (preg_match('#youtube#i', $match_video[0], $match_temp) ) {
$youtube_src = $match_video[1];
if (preg_match('/v[\=\/][a-zA-Z0-9_]{1,}&/',$youtube_src, $image_0)) {
preg_match('/v[\=\/](.*)&/',$image_0[0], $image_1);
} else {
preg_match('/v[\=\/](.*)/',$youtube_src, $image_1);

$vid = ( $image_0 === null ) ? Vj9ChXA9y8I : $image_1[1];
$image = "".$vid."/0.jpg";

// for other video search, static image to inform others: othervideo.png
else {
$image = "";

if ($image == ''){
$image = "";

return $image;

echo findIMG( $contenttext, $showfirstimg );

Thursday, 12 March 2009

Regular expression and Possible modifiers in regex patterns in Php

Regular expression tool - "Help PHP PCRE

Any character
Start of subject (or line in multiline mode)
End of subject (or line in multiline mode)
Start character class definition
End character class definition
Alternates (OR)
Start subpattern
End subpattern
Escape character
Newline (hex 0A)
Carriage return (hex 0D)
Tab (hex 09)
Decimal digit
Charchater that is not a decimal digit
Horizontal whitespace character
Character that is not a horizontal whitespace character
Whitespace character
Character that is not a whitespace character
Vertical whitespace character
Character that is not a vertical whitespace character
'Word' character
'Non-word' character
Word boundary
Not a word boundary
Start of subject (independent of multiline mode)
End of subject or newline at end (independent of multiline mode)
End of subject (independent of multiline mode)
First matching position in subject
Zero or more of n
One or more of n
Zero or one occurrences of n
n occurrences
At least n occurrences
At the most m occurrences
Between n and m occurrences"

Possible modifiers in regex patterns
If this modifier is set, letters in the pattern match both upper and lower case letters.

If this modifier is set, a dot metacharacter in the pattern matches all characters, including newlines. Without it, newlines are excluded. This modifier is equivalent to Perl's /s modifier. A negative class such as [^a] always matches a newline character, independent of the setting of this modifier.

This modifier inverts the "greediness" of the quantifiers so that they are not greedy by default, but become greedy if followed by "?". It is not compatible with Perl. It can also be set by a (?U) modifier setting within the pattern or by a question mark behind a quantifier (e.g. .*?).

My photo
London, United Kingdom

Facebook & Twitter