Effective Linux - Euler's Blog (http://www.effectivelinux.com)

Utilize shell scripts,linux commands, open source tools,java, to Maximize the Power of Linux.
Focused on working with linux and shell, search engine technology including Chinese segmenter
Any questions please contact me at gmail: david.ullua

12/06/2008

Using VirtualBox From Linux to virtualize windows and from windows to virtualize linux

1. How to Adjust resolution of guest OS:
启动guest操作系统,安装virtualbox的增强功能,先选择“设备”->“安装增强功能”。
(booted guest OS, Devices -> Install Guest Additions)

若是在linux的Virtual Box上虚拟windows, guest os为windows (主操作系统为linux)。
安装增强功能后,在windows的我的电脑中会看到光驱变成了“VirtualBox Guest Additions", 点击光驱直接安装 Guest Addtions, 安装完重启windows即可。 (Windows would load VirtualBox Guest Additions CD automatically, all you need to do is to run the CD and install Guest Additions , then reboot Windows)

若是在Windows的Virtual Box上虚拟linux,guest os 为linux(主操作系统为windows)。
安装增强功能后,Ubuntu会自动挂载VBoxGuestAdditions.ISO,并显示在桌面上。 (All you need to do is run BoxLinuxAdditions.run ) :
打开终端,利用su或者sudo指令进入root模式,然后依次输入:
#cd /cdrom 注意:cd命令后面有一个空格)
#sh VBoxLinuxAdditions.run

2.若使用NAT方式, guest os可以通过原操作系统的路由功能直接访问网络。

3.允许guest OS访问原操作系统中的目录。 (How to allow folder share between guest OS and the primal OS)
启动guest os后, 点"设备" -> "分配数据空间" ("devices" -> "share folders" )
增加共享目录,选择目录, 给共享目录取一个名字即可。 比如取名为share。
那么当guest os为windows时,可以运行:
net use x: \\vboxsvr\share 来使用共享的目录。(映射到x:盘)

当guest os为linux时,可以运行:
mount -t vboxsf share /mnt/mount_point 来通过linux上的mount_point目录来访问共享的share。

4.如果遇到声音出不来的情况, 那么关闭guest os后,选择虚拟机,设置一下声音(Audio),确保Enable Audio有被勾选上,并选择了合适的驱动,如果一个驱动不行,就换其他的,然后重启guest os,多试几次就好了。
(If no sound in the guest OS, you can shutdown the guest os, and enable Audio in the Settings for the virtual machine.)

5.安装增强功能以后,主系统和虚拟的操作系统之间不在需要来回切换,可以很方便地当作一个操作系统使用。
特别是全屏(Full Screen Mode)和无缝显示(Seamless Mode)感觉用户体验相当棒!

9/19/2008

PHP, MySQL中使用UTF-8编码,以及中文乱码的解决

若在linux/unix服务器上使用
注意如下事项:
1、设置mysql服务使用的编码:
#vi /etc/
在 [mysqld]以及[mysqld_safe]后面都加上以下两行:
default-character-set=utf8
default-collation=utf8_general_ci

然后重启mysqld服务: /etc/init.d/mysqld restart (fedora 9) 为例。
2.php的页面代码,执行sql语句前(或者在数据库连接建立后)设置本次连接的字符集,示例如下:
mysql_query("SET NAMES 'utf8'");
$result=mysql_query("select * from t_userlog");

3.Terminal登录mysql时指定字符集:
mysql --default-character utf8 -u root -pmypass
这样也可以:
mysql --default-character-set utf8 -u root -pmypass

4.apache的配置文件httpd.conf中,找到 AddDefaultCharset一行,注释掉,或者改成如下:
AddDefaultCharset off

(这一步是为了让不同字符集,比如utf-8,gbk的网页放到服务器上都可以正常在客户端显示)

5.每一个php页面中,都在head部分设定meta头的charset:
< meta equiv="Content-Type" content="text/html; charset=UTF-8" >

6. 以终端登录mysql中可以用如下sql语句来显示以character开头的变量:
SHOW VARIABLES LIKE 'character_set_database';

SHOW VARIABLES LIKE 'character_set_client';
show variables like 'character%';

可以通过 show character set; 语句来显示有哪些可用的字符集。

5/31/2007

Utilize hudson and ant to set up a daily build system step by step

Hudson is popular daily build system and a continuous integration engine. It is easy to setup and maintenance. Here's the brief introduction of the deploy process:

0). download hudson from https://hudson.dev.java.net/servlets/ProjectDocumentList.
You can download jnlp release jar or old release war package.

1).Hudson needs a web container such as glassfish, tomcat or winstone.
But Hudson ships with Winstone, so you can run it standalone by run : java -jar hudson.war, or java -jar hudson.jar if you downloaded the jnlp release.

Use the -D option to specify HUDSON_HOME in the invocation:
$ java -DHUDSON_HOME=/path/to/home -jar hudson.war

Alse you can use the environment variable:
$ export HUDSON_HOME=/path/to/hudson_home
$ java -jar hudson.war

HUDSON_HOME: Hudon needs some diskspace to perform builds and keep archives.
(By default, this is set to ~/.hudson , but you can change it: https://hudson.dev.java.net/admin.html)

2).If you don't have container yet, you can run hudson standalone (with shipped container Winstone), then you can access the portal of hudson by http://hostname:8080/ (default port is 8080), and create a new job, set some basic configurations. it will run by the schedule you configured.

3).If you have a container already (like tomcat), just deploy hudson.war to the webapps directory of tomcat, restart tomcat. then you can access the portal from http://hostname:8081/hudson, assume 8081 is the port for tomcat. for glassfish please take a reference at https://hudson.dev.java.net/containers/glassfish.html.

4). you can configure automatic build (like crontab), or periodical build or build by email, ref: https://hudson.dev.java.net/build.html

5). if you met problem when run ant task (), make sure your ant target is correct. My ant target is "-f CustomBuild.xml makepackage", it runs makepackage in ant build file CustomBuild.xml. If still fails, you can just checkout your project from repository to a clean directory, and run ant command to check whether it runs through, if fails check ant build file.

6).if can't send email successfully, just click "Manage Hudson" in the index page of the hudson portal, click "System Configuration" to configure smtp related info. If your SMTP need authentication, click "Advanced" in the "E-mail Notification" section, and enter the username plus password.

It should works, else email me your problem.

5/28/2007

gains of subversion (SVN带来的收益)

Author: David Lv Euler
Date: 05/28/2007, Suzhou

When I working on .Net and VSS. Our team was often troubled by the crippled VSS. In many cases, someone modified a common file like DbHelper.cs, or a business logic class Order.cs, and we need to modify the file too. Then we need to wait for him/her to checkin/commit the file, even worse, he/she is taking a vacation in another city, then we have to modify the file's read-only attribute on local disk, however could not checkin/commit the changes. It wasted us lots of time in waiting and in checkin/checkout.

If you are suffering from "lock, checkout and modify" model of VSS (Visual Source Safe) in team cooperation, or you are searching for a version control system, I suggest you to try subversion (SVN) as source management system. Subversion has a model of "checkout, modify, update and commit". After checkout a file/folder, anyone can modify a file in the same time, then when execute updating(if no concurrent modification you don't need to update, just commit directly), svn will merge other's modification to your working copy automatically, then you can commit your copy safely. If it can't merge these modifications, it would tell you where are conflicts, and you can resolve them manually and then commit safely. you can reference the manual in http://subversion.tigris.org .

Even if you are using dotnet, there is subversion plugins for VS.net. Now my team are using java, SVN has helped us in source code management and team cooperation greatly. I believe that it is one of the most successful open source project.

当我使用.net和VSS的时候,我们的团队经常被憋足的VSS所绊倒。很多情况下,有人修改了一个公用文件DbHelper.cs 或者一个业务逻辑文件Order.cs, 这时我们也需要修改这个文件。然后我们不得不等他/她签入/提交文件。更糟糕的是,此时他/她可能正在另一个城市旅行,这时我们只好修改本地文件的只读属性,但依然无法签入。大量的时间在等待和签入签出中被浪费了。

如果您正在被VSS的“锁定,签出,修改”模型所困扰,或者您正在寻找一个版本管理系统,那么我向您推荐subversion (SVN). Subversion使用"签出,修改,更新和提交"的模型,当签出一个文件或目录后,每一个人都可以同时修改同样的文件,然后执行更新(如果没有并发修改就不需要更新,可以直接提交), svn会自动合并其他人的修改到您的工作文件中.然后您可以安全地提交您的机器上的拷贝. 如果svn无法合并更改,那么她会告诉您哪些地方有冲突,您可以手工解决这些冲突,然后安全地提交. 您可以参考http://subversion.tigris.org 上面的手册.

即时您在使用dotnet, 仍然有VS.net的subversion插件可以使用。现在我的Team使用java, SVN在代码管理和团队协作上给了我们很大的帮助。我相信她是最优秀的开源项目之一。

5/09/2007

"You can't load TkCximage", could not run amsn as normal user

gaim or Kopete would miss lots of messages. what's the most worse is file transfer often fails. so i tried amsn under linux as MSN messenger.

I download amsn 0.96 from linuxpackages for the slack package.
First time when i run ./amsn, it said "exec wish" failed, then I googled and installed TCL/tk in the slackware 11 second ISO file.

Then run ./amsn, it said could not find ComboBox, oh, then googled and find that the package is installed by root, and normal users does not have the rights of /usr/share/amsn/utils/combobox. So I chown the rights to a normal user. Still, it said "You can't load TkCximage, this is now needed to run aMSN. please compile amsn first..." , oh, God, the cause is /usr/share/amsn/ and all it's sub-directories doesn't have the execute permission, so can't load TkCximage.

Then I logged in xfce as root , run amsn, it works. So I tried to give all subdirectories under /usr/share/amsn/ with execute permission, ( add execute permission for all subdirectories under folder ):
#cd /usr/share/amsn/
#find ./ -type d -exec chown david.users {} \;
#find ./ -type d -exec chmod +x {} \;

then logged as normal user david, run ./amsn, it works now.

4/09/2007

mysql error -- /etc/rc.d/rc.mysqld restart

in Slackware 11, when i connect mysql (5.0.24a) by ip/remotely:

$mysql -u roboo -h 172.16.100.30 -p

error showed as following:
Enter password:
ERROR 2003 (HY000): Can't connect to MySQL server on '172.16.100.30' (111)

i googled around, someone said can edit the my.cnf , comment this line:
skip-networking
but there isn't any my.cnf on the file system. even type locate my.cnf,nothing
happened, i got stuck on the problem. then tried to find which configuration
file (my-huge.cnf, my-large.cnf, my-medium.cnf, my-small.cnf ?) mysql is
using, and didn't find anything in /usr/bin/mysqld-safe. however, find
something useful by ps command:

$ps aux|grep mysql
root 3896 0.0 0.0 2328 432 ? S 08:56
0:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/run/mysql/mysql.pid --skip-networking
mysql 3921 0.0 0.5 52840 5416 ? S 08:56
0:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysql/mysql.pid --skip-locking --skip-networking
mysql 3922 0.0 0.5 52840 5416 ? S 08:56
0:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysql/mysql.pid --skip-locking --skip-networking
mysql 3923 0.0 0.5 52840 5416 ? S 08:56
0:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysql/mysql.pid --skip-locking --skip-networking
.....

yes,--skip-networking is the key.it means when mysqld is started,
a "--skip-networking" parameter is passed. I opened /etc/rc.d/rc.mysqld ,
and see this line:
SKIP="--skip-networking"

and in the later lines SKIP is taken as a parameter of mysqld. so comment the
SKIP line, restart mysqld.
#/etc/rc.d/rc.mysqld restart

it works!

3/31/2007

how to package jar easily with find command

Eclipse jar packing function isn't very easy and comfort to use. Sometimes the packaged jar does not include some classes.

we can use find and jar command to make a jar package easily:
assume $project is where your project located, and bin is the output directory.
com.xxx.yyy is the parent package of the project.

cd $project/bin
find ./com  > classlist  (or find ./com -name *.class if you have .cass files only)
jar -cvf project.jar @classlist

About Me

I am a senior developer and a team leader with 3 years development experience in Suzhou, China, focus on mobile web search, linux, Java and machine learning in NLP (natural language processing). My goal is to improve people's life with computer technology.