2013/09/24

Reminder: Check out Liu's photos on Facebook

facebook
Liu is sharing photos, updates and more on Facebook. Sign up to stay in touch with Liu and all the people you care about.
Liu Lantao
View Liu's Timeline
Go to Facebook
This message was sent to laxbilley.lltaichi@blogger.com. If you don't want to receive these emails from Facebook in the future or have your email address used for friend suggestions, please unsubscribe.
Facebook, Inc., Attention: Department 415, PO Box 10005, Palo Alto, CA 94303

2013/09/09

Reminder: Check out Liu's photos on Facebook

facebook
Liu is sharing photos, updates and more on Facebook. Sign up to stay in touch with Liu and all the people you care about.
Liu Lantao
View Liu's Timeline
Go to Facebook
This message was sent to laxbilley.lltaichi@blogger.com. If you don't want to receive these emails from Facebook in the future or have your email address used for friend suggestions, please unsubscribe.
Facebook, Inc., Attention: Department 415, PO Box 10005, Palo Alto, CA 94303

2013/08/23

Check out Liu's photos on Facebook.

facebook
Check out Liu's photos on Facebook.
If you sign up for Facebook, you'll be able to stay connected with friends by seeing their photos and videos, staying up to date with their latest status updates, exchanging messages and more.
Join Liu on Facebook
This message was sent to laxbilley.lltaichi@blogger.com. If you don't want to receive these emails from Facebook in the future or have your email address used for friend suggestions, please unsubscribe.
Facebook, Inc., Attention: Department 415, PO Box 10005, Palo Alto, CA 94303

2010/09/30

Taobao FileSystem(TFS)开源发布了

TFS新近发布出来了,代码量不小,抽个时间研究下。
taobao定制了不少功能,也有很多通用功能不能支持(比如自定义文件名),做迁移前需要考察它是否支持某些常用的特性。

http://code.taobao.org/svn/tfs/

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

2010/07/17

路由器MTU与ISP不匹配导致无法上传文件

路由器MTU与ISP不匹配导致无法上传文件

(1) 症状/问题表现
网站不能正常连接,或者连接上非常慢,或者无法上传或无法发送大文件。

(2) 关于MTU
MTU(Maximum Transmission Unit)是网络上传送的最大数据包,MTU的单位是字节。
MTU设置的标准是1500,大部分网络设备的MTU也都设置为1500,这样可以使的数据包在网络传输上获得最佳效率。
如果网络上某一个节点的MTU设置被人为调小(比如1460),导致标准大小的数据包(1500)在这一节点被拆开来传送,这样会产生很多数据包碎片,增 加丢包率,降低网络速度。而天朝的实际情况是,某些网络服务提供商会修改某些节点的MTU,以达到限制用户通过路由器共享带宽的目的。

把电脑或路由器的MTU调整为与网络服务提供商设备的MTU相同或稍小,就可以减少这种拆分,提供网络访问质量。一般情况下我们只需要设置路由器的 MTU值即可。

(3) 检查网络服务提供商设备的MTU值
开始菜单–程序–附件–命令提示符,输入以下命令:
 ping -f – l 1500 www.renren.com
其中:
-l 1500 发送一个定长数据包,1500是测试数据包的大小;
–f 通知路由器不能私自更改该数据包大小。

在1500以下调整测试数据包的大小,观察反馈结果的变化并判断电信服务商设备的MTU值。
如果出现"Packet needs to be fragmented but DF set",表示数据包需要被拆开来发送。
减少测试数据包长度,再执行上面的ping命令。重复几次,直到前面的提示消失,记下当时测试数据包的长度。
把测试数据包长度加上数据包头28字节,就得到MTU的值。

(4) 修改路由器MTU
在路由器的管理界面(怎么进入管理界面?看一下说明书吧),一般在"WAN设置"/"广域网设置"及其"高级设置"中,可以看到MTU设置。修改MTU为 合适的数值(等于或稍小于网络服务提供商的MTU)后,保存设置重启路由器。

重启后,进入图片上传的网页(http://upload.renren.com/addphoto.do),传一张图片试试能不能成功。



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

2010/06/08

Varnish Setup in Steps

配置与编译
./autogen.sh
./configure
make

测试
cd bin/varnishtest && ./varnishtest tests/*.vtc

安装
make install

启动
/data/varnish/sbin/varnishd -a 0.0.0.0:80 -s file,/data/vcache/varnish_cache.data,20g -f /data/varnish/etc/vcl.conf -p thread_pool_max=1500 -p thread_pools=8 -p listen_depth=512 -P /data/varnish/sbin/varnish.pid
重新载入
kill -HUP `cat /data/varnish/sbin/varnish.pid`

关闭
killall varnishd

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

2010/06/02

Flex Hello-world example.

Flex开发与普通的页面开发之间,道理基本相通:
网页有html,Flex有mxml,并且都有相应的可视化设计工具(Dreamweaver和Flash Builder,有趣的是这两个工具现在都归Adobe公司);
网页开发有<script>标签,Flex开发有<mx:Script>标签;
网页开发的产物通过浏览器进行工作,Flex开发的产物通过flash插件工作;
网页开发中有ajax的模式,Flex开发使用了RPC调用。

reference: http://learn.adobe.com/wiki/display/Flex/2d.+Tutorial

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

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