Twitter Updates

follow me on Twitter


Skip to content

图文教程:在 KVM 上安装 Fedora 12

17-Nov-09

基于内核的虚拟机 KVM 应该是很好玩的一个东东,速度很快,今天 Fedora 12 刚刚出来,经过几个小时的艰苦的下载过程,终于在 KVM 安装上了,安装过程非常顺利,一点障碍都没有,我很少写这样图文的教程文章,中文的就更少了,不过今天就尝试一下吧,呵呵

首先当然是先安装 KVM 了,如果你用的是 gentoo ,可以参考 Gentoo Linux Wiki ,如果是其他的发行版,你可以参考官方一些资料,在不就 google 一下,这里就不详细说它的详细安装过程了。

安装好 KVM 之后,第一件事当然是建立一个虚拟硬盘,不管是任何 guest 系统,以下命令都使用:

1
kvm-img create -f qcow2 fedora-12-i686.img 20G

然后就可以开始启动虚拟机了,第一次用以下的命令让虚拟机从 cdrom 启动

1
2
3
4
5
6
7
# -hda 参数指定虚拟硬盘
# -m 参数指定内存,这里是 1G,默认是128MB
# -cdrom 参数指定 ISO 镜像文件
# -localtime 这个参数在我这里是蛮重要的,让 guest 显示正确的时间,默认是 UTC 
# 关于 kvm 命令的更多的参数,请 man
 
kvm -hda fedora-12-i686.img -cdrom Fedora-12-i686-Live.iso -m 1024 -localtime

More…

小谈墨西哥华为

09-Nov-09

快要毕业了,5年的大学生涯还有一个月就要结束了,跟着的就是找工作的事情。在墨西哥,信息技术这一行并不是那么发达,但是因为学习计算机工程的本来就是少数,工作机会还是比较多的,竞争也不大,像我们学校,每一届大概就是20来号人。就像世界各地一样,一份好的工作还是比较难找的。

因为认识在华为工作的一位朋友,所以没有通过当地华为公司的人事部就直接去了技术部门面试和谈待遇,自认自己的能力不算低,就不跟国内的高人对比了,但以在墨西哥的平均技术水平来说,自己的水平还是过得去的。但是结果就是感觉这里的华为并不是那么需要和重视会中英西和技术的人才,待遇跟墨西哥人公司没什么两样,只能说,不比这里的很多公司差,但是也不比很多公司好,最后结论就是,可能呆在墨西哥人公司或者其他外企公司更好,起码有人看得起我。

首要的应该是吃和住的问题,我是孤身寡人在墨西哥城,家人都在墨西哥的北部的一个小城市,如果华为能在这方面安排一下,那可是帮了不少忙,但是那天谈到的是,如果我想跟大伙一起去吃饭,自己要掏7美刀,比自己到外面吃墨西哥餐还要贵;我想去华为,除了是因为有更多的发挥机会之外,另外就是因为我也是中国人,可以跟中国人一起共事应该是很有意思的事情;但是在待遇方面,我却一点都感觉不到自己是一个中国人,感觉完全被当成一个能说中文的墨西哥人看待了;想想如果在华为工作,每天大伙们都一起去食堂吃饭,空荡荡的留下我自己一个人在那,我估计我会感觉不好受;(想想如果有墨西哥人问我为什么不跟其他人去吃饭,我都不知道怎么回答呢)

不知道在中国公司被当成墨西哥人和在外国公司做中国人这两个概念究竟是有什么样的区别,那天去华为的时候,旁边的墨西哥产品经理就问我到华为工作会不会找到家的感觉,我当时就说了:”应该会。” 但是现在细想一下,我要融入公司里面还有一定的难度,因为我变成两不像了,在中方方面,被当成墨西哥人对待,但是在墨方方面,我是一个中国人,因为我长的就是中国人的样子。

去华为转了一圈后,感觉这里的华为的问题还是挺多的,最严重的应该是本地化问题,公司里面70%以上的都是中国人,我不知道真正的比例,但是在办公室里看到的中国人的比例绝对墨西哥人多,这就意味着是中国人在做主导的,这有可能是当地人没有接受到适当的培训,本地人得不到信任或者其他原因,但这不利于本地公司的发展,最终这是在墨西哥的一个分公司,负责的是墨西哥的市场,由于文化和语言上的差异,理应是墨西哥人作为主力才对的。估计会有很多华为内部员工的人说那是因为当地人不怎么样,但是个人觉得这应该是招募和管理的问题,虽然墨西哥的人才流失问题很严重,但是不代表墨西哥就没有人才。

由于本地化做的不好,自然而然就有很多后续的问题,和本地员工之间的沟通问题,和墨西哥本地客户沟通的问题,中国的好习惯和坏习惯都带过来了,中国的那边的好的和坏的思考和管理方式也带过来了,等等。

不知道在世界各地的华为是不是也是这样的状况,我只看到了表面的一些问题,但是如果你要问有什么解决方法的话,我还真不知道,我并没有真正了解华为,我在这就发发牢骚而已。

Comet in Tomcat

09-Nov-09

NIO or ARP Protocol is needed to use comet in tomcat, so you should have something like following:

1
2
<!-- server.xml in tomcat -->
<Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol" connectionTimeout="20000" redirectPort="8443" />

Here is a test servlet:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import java.io.*;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import org.apache.catalina.CometEvent;
import org.apache.catalina.CometProcessor;
import org.apache.catalina.CometEvent.EventType;
 
public class CometServlet extends HttpServlet implements CometProcessor {
    public void event(CometEvent e) throws IOException, ServletException {
        if (e.getEventType() == EventType.BEGIN) {
            // ...
            HttpServletResponse response = e.getHttpServletResponse();
            PrintWriter out = response.getWriter();
            out.write("Hello world");
            out.flush();
            System.out.println("message is sent out");
        }
        if (e.getEventType() == EventType.READ) {
            // ...
        }
        // more codes
    }
}

Number Of 1’s In A Binary Number

04-Nov-09

This problem is quite simple, the obvious way always first comes to mind is that the given number N divide by 2, and test the remainder:

1
2
3
4
5
6
7
8
9
10
public int countOnes(int n){
	int num = 0;
	while(n > 0){
		if(n % 2 == 1){
			num++; 
		}
		n /= 2;
	}
	return num;
}

The same manner operating on binary level:

1
2
3
4
5
6
7
8
public int countOnes(int n){
	int num = 0;
	while(n > 0){
		num += n & 1;
		n >>= 1;
	}
	return num;
}

Beside of this good algorithm with complexity O(log n), yet we can have a better algorithm:

1
2
3
4
5
6
7
8
public int countOnes(int n){
	int num = 0;
	while(n > 0){
		n &= (n - 1);
		num++;
	}
	return num;
}

PostgreSQL Note

30-Oct-09

Login as postgres user

1
$ su postgres

The postgres command shell is

1
$ psql

Being inside of psql, you can drop and create database:

1
2
3
4
5
6
7
8
# get help
postgresql=# \h
 
# create database
postgresql=# CREATE DATABASE dbname;
 
# delete database
postgresql=# DROP DATABASE dbname;

To import .sql file into a database:

1
$ psql -U postgres -d dbname -f sqlfilepath

Extracting Audio From Video Files

26-Sep-09
1
2
3
for file in `ls *.avi`; do 
      mplayer -dumpaudio $file -dumpfile `basename $file .avi`.mp3
done

BB 8830 + Iusacell + Voice + EVDO

16-Jun-09

Recently i bought a Blackberry 8830 from ebay.com which is great, it just costed me a little but really a pretty phone, the only defect is that there is no camera, haviing one is ideal, anyway i dont use camera so much. it’s ok then.

Cause it’s from Verizon USA, for carriers in Mexico, they call it “extranjero”, which means you cannot get support from local carrier, in this case, it’s Iusacell. after quite a lot of effort, now 8830 has been adapted to iusacell, that is voice + sms + evdo. wow, viva EVDO, the connection is great, tried to download a 5mb file and the speed maintened in about 80kB/s. oh, have to comment that, i have a great data plan, i am paying about 170 pesos for unlimited evdo connection! it’s about 12 dollars. whatever, this plan is not offering to any new customers any more.

so here i would write down the steps to get it work for others who might need.

1. first of all, you would take your phone to iusacell so they can assign the line for you. it’s free. that means, the activation of phone line.(probably you could configure it by yourself)

2. at this point, you would have the voice and sms service already. then you would follow this post to configure the data service. After the firsts three steps, you probably get data service configured, any way, it could be not EVDO, you woudl see ‘1x’, ‘1X’ beside of the signal in the screen, but not ‘1XEV’ or ‘1xev’.

Now what you have to is update the prl file. you would call *228 to get a new update from iusacell(option 1 then 0). Reset the mobile network connection, it says EVDO? if yes, then congratulations, you got it. if no, dont worry, iusacell is just playing with us, i think iusacell just dont want us to use evdo because we have one cellphone “extranjero”. hehe. now you would want to download a new prl from here and load it into your phone using QPST. here i use the prl 232, maybe you want to use prl 252, your choice.

tips: download MML(MFI Multiloader), QPST from shopcel.com. there all tools you need. for unlocking GSM and GPS, you need MML too.

Using phpMyAdmin

22-May-09

phpMyAdmin is really good. comparing with mysql-gui-tools, i prefer phpMyadmin cause mysql-gui-tools requires so many dependencies!! phpMyAdmin can do whatever can do the mysql-gui-tools does.

Cause i use it to connect arbitray mysql server in development process, what i have to to do is to enable the $cfg['AllowArbitraryServer'] option in config.inc.php:

1
$cfg['AllowArbitraryServer'] = '1'

New Theme

22-May-09

OpenBox + tint2(panel) + xcompmgr + Airborne(theme)

RSS tools

12-May-09

tools chain: Firefox + Google Reader + Google Goodies(next button) + Firefox plugin: Google Reader Watcher

Firefox
The most popular browser in the linux world.

Google Reader
Google powered online RSS reader. you have to put your faviortes feeds here.

Google Goodies (next … next …)
A shortcut button located in firefox’s bookmarks bar which opens your unread article for you.

Firefox Plugin: Google Reader Watcher
a plugin which gives you a notification wheneven you get a new unread article from google reader.

So, what i do, just click on the NEXT button wheneven watcher notifies me about new articles. i dont even need sign in or open google reader anymore!!!