2010/05/11

Emerge抱怨gcc不能工作啦!

Emerge抱怨gcc不能工作啦!

平时gentoo自动更新,省心也省力。结果聪明反被聪明误,遇到了搞不清道不明的依赖关系,有个东西是装也装不上,卸也卸不下,只好动手挨着理出来。
一次舒爽的emerge --depclean之后,系统里多余的小家伙挨个儿离开了。
重启,再来试试revdep-rebuild(系统推荐的步骤是emerge --update --deep --newuse world, emerge --depclean, then revdep-rebuild)。
不好,突然停住了,看看输出的提示,找到红绿交界的地方,看到如下文字:

-------code-------
checking whether the C compiler (gcc  ) works... no
configure: error: installation or configuration problem: C compiler
cannot create executables.
--------end-------

糟糕,我的GCC挂了?貌似刚才的操作没有惹到它老人家吧!

没办法,找找吧。

$ which gcc
发现它好端端的躺在/usr/bin/gcc,乖乖不得了。

看看配置吧,gcc-config -l一下,貌似这唯一的一条不是默认的选择。
------------------
lax@mib ~/empty/gentoo $ gcc-config -l
 [1] i686-pc-linux-gnu-4.4.3
------------------

试试修改一下:
$ sudo gcc-config 1
 * Switching native-compiler to i686-pc-linux-gnu-4.4.3 ...                   [ ok ]

它OK,我也OK,再来Emerge一下,终于走下去啦。

--
Liu Lantao
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .

2010/04/21

补充:使用Ruby进行Log分析


补充:
使用str.split方法,分析同一个文件需要的时间:
lax@mib ~ $ time ruby accounting_total_reqs.rb
4820147812

real    0m8.272s
user    0m8.105s
sys    0m0.148s


--
Liu Lantao
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .

使用Ruby进行Log分析:放弃String.split,使用Regexp.match

使用Ruby进行log分析,它的性能成为一个瓶颈。
传统在perl中通过split的方式进行字段抽取的工作,在ruby中性能变的极差。
对一个32万行的log文件进行统计,抽取其中一个字段进行累加。
原有采用split方式,脚本运行时间在12~13s,且CPU占用较高。这种情况下,进行实施数据分析的消耗巨大,无法大范围部署。
而让这一状况得以改观的是,采用Regexp.match(str)进行抽取,计算速度有了非常大的改善,在2s内完成了计划的任务。

---------------
lax@mib ~ $ cat accounting_total_reqs.rb
#!/usr/bin/env ruby

f = File.open("NginxAccounting.log")
regex = Regexp.new(/req_total:(\d+)/)

tp = 0
while(f.gets)
    $_.scan(regex)
    tp += $1.to_i if $1
end
puts tp
---------------

采用str.scan(regex),速度比较满意:
lax@mib ~ $ time ruby accounting_total_reqs.rb
12437322629

real    0m1.786s
user    0m1.753s
sys    0m0.031s

调整为regex.match(str)方法后,速度又有少量提升:

lax@mib ~ $ time ruby 5.rb
12437322629

real    0m1.603s
user    0m1.570s
sys    0m0.031s


--
Liu Lantao
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .

2010/02/23

Gentoo: setup scim in GNOME

1 add USE flags:
 USE="${USE} scim unicode nls"

2
emerge -avuDN world

3  #  vim /etc/locale.gen;
    #  locale-gen
    #  env-update ; source  /etc/profile

4  add LANG="en_US.UTF-8" to /etc/env.d/02locale

5  set environment inf /etc/source of ~/.xinitrc
 export XMODIFIERS=@im=SCIM export GTK_IM_MODULE=scim export QT_IM_MODULE=scim
6  Sometimes: add line "scim -d &" to ~/.xinitrc


--
Liu Lantao
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .

2010/02/11

C++构造函数私有的有趣问题

C++构造函数私有的有趣问题

很多情况下,一个类的构造函数是按照public权限作为接口,当构造对象时默认来执行一些初始化功能。但是当构造函数出现在private中时,对类进行实例化时,会无法取得构造函数的权限,于是不能通过这种方式构造对象实例。疑问出现了:如果不能通过构造函数对类进行实例化,那么这个类还有用处吗?

其实,构造函数私有并不违背C++的语法规则,我们也大可不必为这个问题担心。解决之道呢,一般来说有两种方法。
第一种方法,使用class的static成员来进行实例化工作。因为他们独立于class的对象,所以不必实例化也能够使用它来进行一些private操作,当然就可以调用那个害羞的构造函数。
第二种方法,当然可以通过一些朋友们来绕过这个权限控制,也就是我们都很熟悉的友元函数/友元类。

追究原因,因为这类class不能被任意调用创建实例,于是适合构造一些需要进行对象控制的类。

--
Liu Lantao
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .

2010/01/24

Compiz-fusion on Thinkpad SL400, NVIDIA Card.


1 - Set USE flags

x11-libs/libX11 and media-libs/mesa with xcb enabled.
x11-libs/cairo with glitz, xcb and svg enabled.
x11-wm/compiz-fusion with emerald enabled.

2 - Keywords

dev-python/compizconfig-python 
x11-wm/compiz 
x11-wm/compiz-fusion 
x11-plugins/compiz-plugins-main 
x11-plugins/compiz-plugins-extra 
x11-plugins/compiz-plugins-unsupported 
x11-wm/emerald 
x11-themes/emerald-themes 
x11-apps/ccsm 
x11-libs/libcompizconfig 
x11-libs/compizconfig-backend-gconf 
x11-libs/compizconfig-backend-kconfig 
x11-libs/compiz-bcop


3 - Emerge

emerge compiz-fusion

4 - Usage for nvidia card

LIBGL_ALWAYS_INDIRECT=1 INTEL_BATCH=1 compiz --replace --indirect-rendering --sm-disable ccp

5 - GNOME setting

Navigate to System > Preferences > Startup Applications
Add a new Program to the session list named Compiz-Fusion and path /usr/bin/compiz-manager
Add a new Program to the session list named Emerald and in command "emerald --replace"
Save the settings and relog to test.


reference: http://en.gentoo-wiki.com/wiki/Compiz-Fusion


--
Liu Lantao
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .

2010/01/18

..--

日子滴滴嗒嗒,缓缓急急,入盛夏过深秋到寒冬。

半年的新生活,渐渐地,习惯了朝九晚九的新节奏,在一个狭小的区域里,每天摆来又摆去,重复着不变的节奏。 却疏远了深夜的麻辣烫,黄昏乌鸦鸣叫的校园,还有近郊香山高处的风与景。在这里,生活繁琐而艰难,每天面对各种诱惑,然后以各种路过的姿态,回归自己正常 的方向

一个烦躁不安的日子,翻阅着半年来几个月里朋友们的文字,那些远走他处享受生活的,那些
仍 在这个水泥都市里奋斗的,那些消失许久后又现身的,都在各自的经历之后,发出了大大小小的满意的声音。印象里的一个个充满精力彻夜狂欢着的形象,顿显 成熟的影子。年轻人们的话题,那些飞扬的梦想,大概都伴随那时的日记本放进了尘封的储物箱中了。

在熙熙攘攘的人群中穿梭,在齐整划一的办公间拼搏,在深夜的孤 灯熄灭处栖身,每天又每天之后,终于,我们对周围的一切心满意足。


--
Liu Lantao
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .

2009/12/10

Ruby让你成为一个愉悦的开发者


在最近工作的几个项目中,我有意无意的采用了Ruby语言。作为一种介于主流与非主流之间的动态语言(TIOBE排名10左右),采用ruby的开发者群体在一度暴涨之后,一直处于一个相当稳定的水平。

从效率来看,ruby确实不是一个让人完全满意的选择。在我以前一个项目中实现的一个搜索项目,最先采用了一个PHP的版本,运行起来显示了php一贯的高效和稳定特性。后来采用了ruby进行功能扩展,开发的过程让人愉悦,少量的代码实现了全部功能,并且增加了灵活性,但是在数据量急遽增加的时候,ruby的表现并不如php那样轻松自在。jruby等正在尝试通过新的手段来对这个方面进行改进,前面的路还有很长,值得期待。

而抛开这个瑕疵,Ruby语言本身的优雅简洁,却能将开发者吸引到它的圈子。

ruby强调代码的质量,在ruby的世界里,到处看到的是短小精悍的代码,寥寥几行,可以清晰看到进程的脉络。那比较负责的任务怎么实现呢?Ruby的解决方案是将问题分解,在单独的块里实现复杂的功能。其实这个单独的块也是一个清晰的框架,复杂的功能还会继续分块下去,直到所有的功能的实现都在一个简洁的块中实现。不用卖弄任何技巧,问题在逐步自然而优雅的分解过程中,已经有了一个完美的解决。
大多数语言支持完善的函数,大都有代码重用的机制。而Ruby所特有的灵活高效的block机制,让它出类拔萃。在你需要的时候,方便地def你的方法;采用block/closure,对进程进行有效的控制。通过引入这种灵活性,使Ruby的代码更加简洁。开发者会发现这种语言不会因为严格的语法规则来限制他/她的思维,怎么能不爱它呢?

Ruby的社区也比其它的社区更为友善一些,很少能看到其它社区常见的那句RTFM。这一方面可以归因于ruby是个后起之秀,很多问题都在解决之中,文档中并没有成熟的解决方案。而另一方面,ruby开发者一直处于一种愉悦的开发心情中,大都应该不会以那种暴躁的方式来对待有相同兴趣的吧。


--
Liu Lantao
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .

2009/09/25

curl -4 --head -H "Host 203.166.178.9" http://www.liulantao.com/images/lax_shetou.gif


lax@homex ~ $ host www.liulantao.com
www.liulantao.com has address 203.166.178.9
lax@homex ~ $ curl -4 --head -H "Host 203.166.178.9" http://www.liulantao.com/images/lax_shetou.gif
HTTP/1.1 200 OK
Date: Fri, 25 Sep 2009 13:19:45 GMT
Server: Apache/2.0.52 (Red Hat)
Last-Modified: Sat, 07 Feb 2009 07:30:15 GMT
ETag: "1208ae-16be-1bc9efc0"
Accept-Ranges: bytes
Content-Length: 5822
Connection: close
Content-Type: image/gif

--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

What is Test-Driven Development in Ruby?

TDD steps:

1, Write a test that describes some shortcoming or missing feature in the code.

2, Run the tests.

3, Write just enough code to make this test pass.

4, Run the tests again.

5, Refactor.

6, Write a test to define a new feature and start the process all over again.


Always remember:

1, Code doesn't exist yet until it's tested.

2, Run tests religiously.


see more:
1, http://ruby.about.com/od/advancedruby/a/tdd.htm

--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

2009/09/24

rake db:drop with permission denied error.

>rake db:drop
Couldn't drop db/development.sqlite3 : #<Errno::EACCES: Permission denied - db/development.sqlite3>

maybe you run script/console and didn't exit.

--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

2009/09/16

A journey to Gentoo: Intel video card and xorg installed.

config intel video card on Gentoo Linux.

first, make sure the kernel module option, "Device Drivers --> Graphics support --> Direct Rendering Manager --> Intel 810" should be checked for my i810 card.

then set  VIDEO_CARDS="intel"  in /etc/make.conf.

now, reinstall xorg-x11:  # sudo emerge -uDNva xorg-x11.

when all above steps were finished, remove /etc/X11/xorg.conf, run $ startx, and everything is fine.

Though, there is neither any input method nor web browser installed, a easy journey to go.

--
Liu Lantao, Oaks Pacific Corp.
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

2009/09/07

Installing Chromium Web Browser on Fedora 11.

[lax@homex ~]$ sudo vim /etc/yum.repos.d/chromium.repo
[chromium]
name=Chromium Test Packages
baseurl=http://spot.fedorapeople.org/chromium/F$releasever/
enabled=0
gpgcheck=0

[lax@homex ~]$ sudo yum install *chromium* --enablerepo=chromium
Loaded plugins: aliases, fastestmirror, refresh-packagekit
Loading mirror speeds from cached hostfile
 * fedora: ftp.cuhk.edu.hk
 * rpmfusion-free: mirrors.cat.pdx.edu
 * rpmfusion-free-updates: mirrors.cat.pdx.edu
 * rpmfusion-nonfree: mirrors.cat.pdx.edu
 * rpmfusion-nonfree-updates: mirrors.cat.pdx.edu
 * updates: ftp.cuhk.edu.hk
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package chromium.i586 0:4.0.204.0-0.1.20090827svn24640.fc11 set to be updated
--> Processing Dependency: libv8.so.1 for package: chromium-4.0.204.0-0.1.20090827svn24640.fc11.i586
--> Processing Dependency: libminizip.so.1 for package: chromium-4.0.204.0-0.1.20090827svn24640.fc11.i586
--> Processing Dependency: nss-mdns(x86-32) for package: chromium-4.0.204.0-0.1.20090827svn24640.fc11.i586
--> Running transaction check
---> Package minizip.i586 0:1.2.3-22.fc11 set to be updated
---> Package nss-mdns.i586 0:0.10-7.fc11 set to be updated
---> Package v8.i586 0:1.3.8-1.20090827svn2777.fc11 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package     Arch    Version                                  Repository   Size
================================================================================
Installing:
 chromium    i586    4.0.204.0-0.1.20090827svn24640.fc11      chromium     15 M
Installing for dependencies:
 minizip     i586    1.2.3-22.fc11                            fedora       25 k
 nss-mdns    i586    0.10-7.fc11                              fedora       25 k
 v8          i586    1.3.8-1.20090827svn2777.fc11             chromium    914 k

Transaction Summary
================================================================================
Install      4 Package(s)        
Update       0 Package(s)        
Remove       0 Package(s)        

Total download size: 16 M
Is this ok [y/N]: y
Downloading Packages:
(1/4): chromium-4.0.204.0-0.1.20090827svn24640.fc11.i586 |  15 MB     02:15    
(2/4): minizip-1.2.3-22.fc11.i586.rpm                    |  25 kB     00:01    
(3/4): nss-mdns-0.10-7.fc11.i586.rpm                     |  25 kB     00:00    
(4/4): v8-1.3.8-1.20090827svn2777.fc11.i586.rpm          | 914 kB     00:09    
--------------------------------------------------------------------------------
Total                                           100 kB/s |  16 MB     02:43    
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : v8-1.3.8-1.20090827svn2777.fc11.i586                     1/4
  Installing     : minizip-1.2.3-22.fc11.i586                               2/4
  Installing     : nss-mdns-0.10-7.fc11.i586                                3/4
  Installing     : chromium-4.0.204.0-0.1.20090827svn24640.fc11.i586        4/4

Installed:
  chromium.i586 0:4.0.204.0-0.1.20090827svn24640.fc11                          

Dependency Installed:
  minizip.i586 0:1.2.3-22.fc11                 nss-mdns.i586 0:0.10-7.fc11     
  v8.i586 0:1.3.8-1.20090827svn2777.fc11     

Complete!


--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

Output of an Array to sentence, the ruby way

@contacts.collect{|s| s.name}.to_sentence.concat(".")


--
Liu Lantao
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

2009/09/06

西四新开的一家奶酪魏


奶酪魏,西四店,今年入夏新开的店。老字号的牌子,进去店面不大,装修得简单,但是也干净整洁。奶酪白色小瓷碗,一般是7元。此外还有奶酪卷、奶酪干等品种。

我要了一碗原味的,很好吃,入口滑而不腻,奶的香醇之气全在其中,回味很久。平时吃的现酿酸奶与它相比,瞬间就没有了一点儿吸引力。

地点嘛,22路、826路等公交车在平安里路口南,路东。过段时间西四的地铁开通,应该更方便了。

奶酪魏第一家店位于前门门框胡同15号,名字为麟记酪铺,在经常是极为有名的了,梁实秋的文章中曾有描述。

--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

2009/09/02

Config rubygems and rails in ubuntu.

 sudo apt-get install rubygems
 sudo gem install rubygems-update
 sudo update_rubygems
 sudo apt-get install libsqlite3-dev
 sudo gem install sqlite3-ruby rails

--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

2009/08/29

Unix-like系统用户交流信息的几个小命令



向系统所有在线用户发送消息:
$ wall [message]
如果想设定是否接收这个消息:
$ mesg [y|n]

向特定用户发送小心:
$ write user [ttyname]

$ talk person [ttyname] 
也可以通过mesg来设定。

当然还有选项更丰富的mail命令:
$ mail [-iInv ] [-s subject ] [-c cc-addr ] [-b bcc-addr ] to-addr... 
$ mail [-iInNv -f ] [name ] 
$ mail [-iInNv [-u user ] ]

--
Liu Lantao
Oak Pacific Interactive Corp. Ltd.
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------