Note about s2mem and s2disk under Linux

October 5th, 2008 firenet Posted in linux | No Comments »

With the help of thinkwiki, s2mem cost a little time to work fine. If your computer resume immediately after s2mem, you should try:

modprobe -r uhci_hcd
 
modprobe -r ehci_hcd

This remove the modules which would awake the computer aumatically. Surely, after your computer resume, you must load these modules for your USB devices.

S2mem is easy and S2disk is not.

First, I got a error “write error: no such device” and i didn’t understand it . Which device is needed? Once I reboot the computer and found a message “Unable find swap signature”. Oh , I havn’t allocate swap space.

Such a stupid error. So

mkswap /dev/sda7
 
swapon -v /dev/sda7

OK, let me try

echo disk > /sys/power/state

Now, my computer can suspend. But when I press the power button to resume, it boot as like it never suspend. Why?”Unable find swap signature” reminds me. I should modify /etc/initramfs-tools/conf.d/resume. It should be like this: RESUME=/dev/sda7. Then

update-initramfs -u

OK, after these, my computer suspend and resume fine.^_^


Got my first notebook thinkpad x61!

September 27th, 2008 firenet Posted in linux | No Comments »

Yestaday,  I got my first notebook thinkpad x61. It has a T8100 CPU, 2GB memory and 250GB HD. (You can find more detail at here. The first one is my type.) 9:25a.m, I got to the Harbin’ Branch of Digital China. There are two nice boys and they help me finish the process for getting the computer. Nearly one hour later, I got back to my school with the thinkpad.

After lunch, I started to deal with the system: Windows Vista is there but I don’t like it. I prefer to linux, whick i am more familiar with. I use Debian lenny at usual time and you know I spend much time to configure it as I wish. So I want to move the whole system on my PC to the thinkpad. For that, I follow these steps:

  1. First of all, I pack the system as a file, a big file. Use this command: tar cvpzf backup.tgz –exclude=’/proc/*’ –exclude=/lost+found –exclude=/ba
    ckup.tgz –exclude=’/mnt/*’ –exclude=’/sys/*’ / . It would create a file named backup.tgz at the root directory.  Wait a while^_^.
  2. Then copy the file to the partition which I got ready for linux root directory at the X61. I used Acronis software to split the partition and size it 50GB and format it to ext3 fs. After the preparation, I copy the file to the partition. How to copy? you have many choices. i.e. , under Windows Vista you can use usb device or LAN to copy the file to NTFS fs partition(fat32 is not supposed because 4G filesize limit is end~), then use ext2ifs or other software to move the file to the ext3 partition. But I didn’t do it like that. I use a use disk whick is bootable. I installed slax over the usb disk. After booting from the usb disk, mount the ext3 fs, copy the file to it. Very easy.
  3. The last step, even easier! Pack the big file, and you can guess it will cost some time. Use the command: tar xvpfz backup.tgz -C /. After that you should fix the grub. Everyone can do it!. Get to the directories which you packed and find the command–grub. Run it and get into the grub command interface. Then “root (hd0, 5)” and “setup (hd0)”, at last “reboot”.Notice : here I supposed the ext3 fs locate on /dev/*da6.

Finish the three steps and you can boot linux at your X61~Even better, the system is configured as you wish!Of cource, some drivers are different between your X61 and PC.That’s next……


ntfs-3g的效率如何?

September 16th, 2008 firenet Posted in linux | No Comments »

还是virtualbox崩溃引来的破事儿,重新安装了virtualbox 2.0非OSE版,接着就是安装windows 2003。随手抓了一张03的安装光盘,安装成功后再安装Office 2k3,令人郁闷的事情发生了:virtualbox提示文件大小超出限制~刚开始还没有反应过来,以前都是这么安装的呀?后来突然想到,我把虚拟机文件放到了fat 32分区,查看文件大小,确实4G了。以前安装成功,估计是那个版本的windows 2003精简过~无奈,格式化为ntfs,考虑到还需要在windows下访问这个分区。用ntfs-3g挂载分区后,开始安装。不知道是不是ntfs-3g的效率问题,CPU占用很高,速度还很慢,copy文件后的配置,平时20分钟就能完成,这次40分钟也搞不定。尝试了好几次,没办法,绕过这个问题吧,搞成ext3。如此这般,5次安装2003后,终于成功了。


Search for proxies via python 续

September 16th, 2008 firenet Posted in python | No Comments »

前几天virtualbox崩溃了,一直使用的花刺代理自然也不能使用了。教育网没有代理可怎么活?没办法,只好自己搞定了。上网搜索了一下,找到一个网友的代码,拿过来,稍微修改了一下,给经常使用的代理更高的优先级,添加保存所有的下载代理功能(原来的脚步只会下载验证成功的代理)。放在46上,好像还能用~


Search for proxies via python~

September 16th, 2008 firenet Posted in python | No Comments »

#!/usr/bin/env python
"""Get proxies from urls, and test their speed"""
import urllib, re, time, threading
urls = ["http://www.hitchina.net/taxonomy/term/14",
"http://www.hitchina.net/taxonomy/term/15",
"http://www.ipbbs.com/",
"http://www.pass-e.com/proxy/",
"http://www.haozs.net/ip.htm"
]		#where to get proxies
urls_proxy = {}		#proxy used to connect urls
proxy_pattern = re.compile(r"""\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{1,}""")
test_url = "http://setiathome.berkeley.edu/"
test_pattern = re.compile(r"""SETI@home""")
time_out = 30.0		#max waiting time to test proxies
output_file = "Proxies.txt"
template = "UserdefinedTemplate.pac"
pac_pattern = re.compile(r"""MyProxy""")
pac_file = "proxy.pac"
advProxy = ["http://219.217.250.3:3128"]
 
class TestTime(threading.Thread):
"""test a proxy's speed in new thread by recording its connect time"""
def __init__(self, proxy):
threading.Thread.__init__(self)
self.proxy = proxy
self.time = None
self.stat = proxy + " time out!"
def run(self):
start = time.time()
try:
f = urllib.urlopen(test_url, proxies = {"http":"http://"+self.proxy})
except:
self.stat = self.proxy+" fails!"
else:
data = f.read()
f.close()
end = time.time()
if test_pattern.search(data): #if data is matched
self.time = end-start
self.stat = self.proxy+" time: "+str(self.time)
else:
self.stat = self.proxy+" not matched!"
 
def totest(proxy, result):
"""test a proxy's speed in time_out seconds"""
test = TestTime(proxy)
test.setDaemon(True)
#print "testing "+proxy
test.start()
test.join(time_out) 	#wait time_out seconds for testing
#print test.stat
if test.time:
result.append((test.time, proxy))
 
if __name__ == "__main__":
#get old proxies in output_file
try:
f = open(output_file)
except:
allproxies = set()
else:
allproxies = set([x[:-1] for x in f.readlines()])
f.close()
 
#get else proxies from urls
for url in urls:
print "getting proxy from "+url
try:
f = urllib.urlopen(url, proxies=urls_proxy)
except:
pass
#print url+" can not open!\n"
else:
data = f.read()
f.close()
allproxies.update(proxy_pattern.findall(data))
print url+" finished!"
 
#test all proxies' speed
result = []
for proxy in allproxies:
#new thread to test every proxy
t = threading.Thread(target=totest, args=(proxy, result))
t.setDaemon(True)
t.start()
 
#show all proxies' speed
time.sleep(time_out+5.0)
result.sort()
#bestProxy = result[0]
#print bestProxy
bestProxy = ""
candProxy = [result[i][1] for i in xrange(len(result))]
for adv in advProxy:
if adv in candProxy:
bestProxy = adv
if not bestProxy:
for i in xrange(len(result)):
bestProxy = result[i][1]
break
#print bestProxy
#print str(i+1)+"\t"+result[i][1]+"   \t:\t"+str(result[i][0])
#output needed proxies
#num = min(abs(int(raw_input("\nHow many proxies to output: "))), len(result))
try:
f = open(output_file, "w")
except:
print "Can not open output file!"
else:
f.writelines(proxy + "\n" for proxy in allproxies)
#f.writelines([x[1]+"\n" for x in result[:num]])
f.close()
#print str(num)+" proxies are output."
try:
f = open(template, "r")
except:
print "Can not open template file!"
else:
data = f.read()
f.close()
#data = re.sub(r"MyProxy", bestProxy, data)
data = pac_pattern.sub(bestProxy, data)
try:
f = open(pac_file, "w")
except:
print"Can not open pac file!"
else:
f.write(data)
f.close()

正式上课第一天~

September 1st, 2008 firenet Posted in 小记 | 6 Comments »

2008年9月1日,我的硕士研究生生活开始了。

今天课不多,一门英语一门计算机网络与通讯,英语没去,计算机网络与通讯去了,听得挺认真,居然没有睡觉。

2008年9月1日,我的导师确定了,是姜守旭老师。熟悉姜老师的同学告诉我,说姜老师挺好的,要求很严,对学生很好。感谢遇到了一个好老师!

今天算是我们数据库中心的迎新会议,李建中老师也给大家谈了很多,给予大家很大的希望。今天我才知道,两年时间确实太短暂了,而需要我做的东西又那么多……没办法,加油吧,好好地学,明年,找个perfect work吧~

God bless me !


四年毕业,各奔东西

July 10th, 2008 firenet Posted in 小记 | No Comments »

四年时间转瞬即逝,眨眼之间我们毕业了。相对于以前的初高中毕业,大学毕业才是真正的毕业。四年时光,我们在这儿搭建一个自己的家;四年时光,我们在这儿找到新的亲人;四年时光,我们脱离父母,寻找自己的人生之路。毫不夸张地说,大学的四年,是我们真正开始融入到社会中去,我们真正长大成人的四年时光。我想,这四年是我一生永难忘记的回忆。

四年时光给我们留下了很多,有快乐,有痛苦,有无形的知识,有有形的行李。最后的短暂时光总是相似的,收拾行李打包,吃饭喝酒,送别某人,回来继续下一个循环。不得不承认,最触动人心的是送别,有人嚎啕大哭,有人有说有笑,有人用力握手,有人紧紧相拥。祝福总是真诚的,心情总是沉重的,而我,几乎总是沉默的。不想多说。

我总觉得那个时候特别不自在,因而今早特地走得早一些,没有和一些兄弟告别,哎~


致全体十四班同学的一封信zz

May 20th, 2008 firenet Posted in important | 4 Comments »

有一个想法,就是在这次地震过后,失去双亲,或者是家庭深受地震灾害而经济困难的孩子,我们十四班,能够出一些人力和财力,对他们进行捐助。
我的想法是,在川外的朋友,如果资金允许,每年能出100元钱(更多当然更好),让我们在成都的十四班的同学和朋友管理;而在成都的朋友、同学,在周六日 或节假日抽出一点时间和精力,轮流把这些钱或者物资,负责送到扶助的她(他)手里。而且最好能抽出时间和精力去与被扶助对象沟通、交流。
这只是我的初步想法,有很多细节上的问题,等看看大家的反应再讨论和解决了。如果大家支持或者有别的想法或意见,都可以提出来,发在班级邮箱里,并请注意在班级邮箱里注明自己的姓名。谢谢大家!

邓富耀,唐光明
——–***分割线***——–
谈一下我自己的看法。我觉得这个想法很好,当然问题也很显然,很多细节都还没有想法或者实施的步骤,所以我建议大家把这个看作一个意向性的公告,我想,如果决定实施的话,那个时候还是应该有一个包含更多细节,令人觉得可行的报告。
PS:大家可以发意见到邮箱,也可以在这儿直接评论。Any question is welcome~
PS2:公共邮箱ybsyz0414@163.com 密码见群公告~

小记续

May 1st, 2008 firenet Posted in 小记 | No Comments »

早晨看了切尔西和利物浦的比赛才睡觉,一觉直接到11点。起来洗漱,吃饭,中午12点,3天后,我又回到了实验室……
昨天提到了球赛比分短信提醒,花了一下午的时间才搞定,真汗~代码如下(commented here):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/perl -w
use Encode;
use HTML::TreeBuilder;
use Data::Dumper qw(Dumper);
$Data::Dumper::Indent = 1;
undef $/;
$oldscore=$score=0;
$times = 0;
for ( $times=0;$times <= 50; $times++){
system("wget","http://score.espnstar.com.cn/","-Oindex.html");
open($fd,"
$string = <$fd>;
$string = decode("gb2312", $string);
$string = encode("utf8", $string);
$tree = HTML::TreeBuilder->new_from_content($string);
foreach $row ( $tree->find_by_tag_name("tr") ) {
$line = "";
foreach $cell ( $row->content_list ) {
$line = $line.$cell->as_text." ";
}
if ($line =~ /拜仁慕尼黑/gs) {
if ( $line =~ /(\d*) - (\d*)/gs) {
$score= $1.$2;
}
if($score ne $oldscore){
$cmd='curl -x 222.171.7.131:7628 -u user@163.com:passwd -d status="'.$line.'"'." " .'http://twitter.com/statuses/update.xml';
system($cmd);
$oldscore=$score;
}
}
}
$tree->delete();
close($fd);
system("rm","index.html");
sleep 300;
}

为什么花了那么长时间,主要原因是PERL的熟悉程度太差了,经常需要上网查资料,PERL也看了好久了,不过用得太少了,真郁闷,看着这么像C的代码……还有就是正则表达式,本来想自己构造正则表达式来提取信息的,但是玩着玩着才发现,实在太难了,恰巧前几天看了一段话:“一些人,遇到一个问题时就想:“我知道,我将使用正则表达式。”现在他有两个问题了。 –Jamie Zawinski, in comp.emacs.xemacs ”说的很好~


小记

May 1st, 2008 firenet Posted in 小记 | No Comments »

      四年了,我错过了很多经典之战,学校固执的作息制度使得我无比郁闷。前几天突然有一个想法,无法看到比赛直播,做一个球赛比分短信提醒,算是一点补偿吧。大概的思路是这样,从网络上提取有用的比分信息,处理后利用twitter等类似网站的OpenAPI,发送短信到自己的手机上。信息倒是很好找,随便找了个HTML页面,直接就能提取相关信息。问题的关键是,使用哪个网站的API?原来有个叽歪的账号,而且叽歪的文档也很齐全,首先开始尝试,按照说明文档,更新,OK,没有问题,网页上正确地显示了更新,但是手机上怎么没有呢?还以为是移动的网络延迟,反复地尝试,三天也没有收到。。。期间也尝试了饭否的服务,just the same!Why?上网搜索,终于在一篇文章中提到,叽歪的短信下行服务只是在测试期间开放,现在已经关闭了;而饭否根本没有开通此项业务~我无从证实这一点,不过我确实收不到短信。没办法,还是去twitter吧,虽然一块钱一条的短信认证很贵,不过好在好使,瞬间就收到了更新。OK,这样整个流程就通了,稍微整理就可以使用了,代码随后送上……

      这几天都没有去实验室,忘记给姐姐投票了,不过前边的人刷得也太狠了@_@

PS:我的twitter账号是kevinmiter[AT]gmail.com,大家可以加我啊,follow me ~