星期二, 五月 11, 2010

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/ .

星期三, 四月 21, 2010

补充:使用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/ .

星期二, 二月 23, 2010

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/ .

星期四, 二月 11, 2010

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

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

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

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

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

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

星期日, 一月 24, 2010

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/ .

标签:

星期四, 十二月 10, 2009

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/ .

标签:

星期五, 九月 25, 2009

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/ .
------

星期四, 九月 24, 2009

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/ .
------