人生的梦境

好几年没有更新博客了,这期间也没有认认真真地写过什么文字,习惯了微博和朋友圈的只言片语,时光也随之变成了无法拼接的碎片,看不出它原本该有的模样。

花了很多时间恢复了这个博客,数据迁移过程因为MySql的版本问题,进行得很不顺利。好在最后都圆满解决了,以前的文章和评论大部分也都还在,那个曾在电脑后探索这个浩瀚世界的小小的我还在。可惜不少图片都找不到了,文章的时序也不太正常,以后再慢慢修复这些问题。

本来想试着在这篇回归的文章里,给这几年并不顺利的人生做个总结,最后还是放弃了:我写不出生命中那些无法言喻的痛苦和快乐,也描述不了那些心花怒放和痛彻心扉的时刻。就借用苏拭的一句”人生如梦“来总结吧,短短四字,已是淋漓尽致。

即便如此,我还是相信,在某个地方有我的诗和远方。就像动画片里的托马斯小火车,每一次的出发,都相信自己要去的是一个伟大的目的地,永不妥协.

MongoDB: Optimize index to avoid the scanAndOrder operation

Recently,I’ve got a performance issue with MongoDB index,it confused me and took me awhile to figure it out.let me try to get this issue straight:I have a compound index on multiple fields,but always result in a slow scan and order operation when performing a range query ,which means that the index is not being used for sorting.

For example,if I have an index “{a:1, b:1, c:-1}”,it works well for find({a:1,b:2}).sort({c:-1}), but  very slowly for find( {a:{$in:[1,2,3]}, b:4}).sort({c:-1}),here’s the output of the explain plan:

Continue reading “MongoDB: Optimize index to avoid the scanAndOrder operation”

OpenSSL for windows

openssl-for-windows,host on google code,is an clean and lightweight OpenSSL library for windows(both 32bit and x64 version).

all versions are compiled in the assembly language routines with Microsoft Visual Studio 2005 and Microsoft MASM as “Multithreaded(/MT)”,you can using it with any version of MSVC.

Download openssl for windows

files included in this library are listed below:

|bin (libeay32.dll, ssleay32.dll,openssl.exe)
|include
|– — openssl  (openssl head files)
|lib (
libeay32.lib,ssleay32.lib)

if you find it useful, a time saver,or even just mildly interesting,then my effort was worth it.
if you have any suggestions on how to improve it, I’d love to hear it.

link to this page: http://www.deanlee.cn/programming/openssl-for-windows/

Enjoy:)

Shrek Forever After

shrek8

在广州休息的时候看了Shrek Forever After,当我以为Shrek和Fiona会延续上一集的美满,像所有童话故事的结局那样,“从此过着幸福的生活”的时候,Shrek的烦恼来了。

生活并不总是童话,在日复一日的扮演一个好爸爸,好丈夫和好朋友之后,平淡规律的生活变成了一种无法忍受的折磨:Shrek突然厌倦了这一切,他只想痛快的做回自己,做回那个无拘无束的怪物,哪怕只有一天。

可是这个看似并不过分的要求,却让他几乎失去了生命中最宝贵的一切:爱情、亲情和友情。他只有一天时间,来完成救渎,找回失去的幸福。

当时间的沙漏走到最后一刻,当Shrek渐渐融化,当Fiona的真爱之吻,让Shrek从噩梦回到童话的那一刻,我真想握着她的手,一起感受那一刻的幸福。那一瞬间给我的感动,就像是看到nemo最终找到了爸爸,就像是看到Isabelle走进了Wallace的帐篷,就像是看到Jane在历经了尘世的浮华之后,最终回到了傻小子阿甘的身边:这个世上还有什么比爱更美妙的事情?

噩梦醒来,童话仍然在继续,时间的沙漏还在不停的滴答,Shrek获得了重生,而我们,有多少人还在原地等待救赎?

Sorry for the late thanks

很惭愧得获得了十佳火炬青年的称号,本来以为不会是我,因为我实在是没什么事迹好写的,那些对我而言都是日常工作,是生活的一部分,尤其是在看了本市其他候选人的资料介绍以后,更让我觉得我只是一个站在沙滩上,仰望着巨人们的孩子,能够站在一起已是荣幸。

Anyway,火炬还是来了,感谢我所在的团队,没有你们,我只是青年,不是火炬青年;没有你们,我只有可爱多,不会有火炬。

有不少同学想看看火炬是长什么样子的,其实火炬的实物是没有的,那只是个概念,我只有用可爱多冒充火炬来补偿下同学们的念头了。

Dean’s FCKEditor for WordPress plugin(V3.3)

This plugin Replaces the default WordPress editor with CKeditor 3.0.1.

CKeditor is an open source WYSIWYG text editor ,brings to the web much of the power of desktop editors like MS Word.it’s lightweight and is compatible with most internet browsers which include: IE 5.5+ (Windows), Firefox 1.0+, Mozilla 1.3+ and Netscape 7+.

Features

  • Replace the default wordpress editor with CKEditor
  • Post comment with CKEditor to provide styled and colorful comments(Optional).
  • Build-in File manager and upload manager.
  • Build-in WordPress "read more" Button.
  • Control output format.
  • Customizable toolbar buttons
  • Integrated with WordPress media buttons:

    image

  • Manage and insert Smileys into your post.
  • Customize editor’s skin.
  • …and more.

Download FCKEditor for wordpress

Installation

This plugin requires WordPress v.2.0 or later ( Tested on  2.8.4 too).

  1. unzip and upload the files into your wp-content/plugins/ directory.
  2. Activate the plugin on your Admin Panel->Plugin Management page.
  3. Done,enjoy it.

Acknowledgements

Many thanks to all of you, who have encouraged me to update my articles  and code, and who sent in bug reports and fixes.

Continue reading “Dean’s FCKEditor for WordPress plugin(V3.3)”

MANIFOLD DESTINY – 谁证明了庞加莱猜想?

这几天看到了俄罗斯数学天才佩雷尔曼破解庞加莱猜想,拒领百万奖金的新闻。对比2006年中国数学界大张旗鼓的宣称是中国人彻底破解了庞加莱猜想的闹剧,两者形成了鲜明的对比。纽约客上发表的这篇文章MANIFOLD DESTINY(流形多舛的命运——一个传奇难题与解决者之争),讲述了这场闹剧背后的故事。

这件事情让这位俄罗斯的数学天才如此的失望,以至于他最终选择了退出数学界,用他自己的话来说就是“我不能说我被伤害了。有其他人做得更糟糕。当然,有很多或多或少还算诚实的数学家。但他们几乎所有人都墨守陈规。他们差不多还算诚实,但他们容忍那些不诚实的人。”

中国缺的不是天才,而是信仰;不是智慧,而是道德。

wp-comments-notifier:a wordpress comments notifier

wp-comments-notifier is an open source application written in QT/C++ that alerts you when new comments are posted on your WordPress blog (works well with WordPress MU too), It displays an icon in your system tray to let you know if you have new comments,It also includes features that allow you to manage/reply/edit your comments directly from your desktop.
Continue reading “wp-comments-notifier:a wordpress comments notifier”

Permalinks Migration Plugin for wordpress

With this plugin, you can safely change your permalink structure without breaking the old links to your website,and even doesn’t affect your search engine rankings.

introduction

Many people want to change their permalink structure,for example, from /%year%/%monthnum%/%day%/%postname%/ to /%category%/%postname%/

But doing so will make all pages indexed by search engines become invalid,moreover, losing visitors from other sites or bookmarks that links to you.

There is a way to tell the search engines (and browsers) that the page has permenantly moved, and that the old address should be replaced by the new one . It’s called a “301 Redirect”, also known as a Permanent Redirect.When you do this, Search engines will update their indexes quickly and you won’t lose your pagerank.you will continue to receive traffic as though nothing had changed. This works for search engines, bookmarks, and links from other sites.

By now, you know how can you change your permalinks without losing the traffic you’re already getting. You can download this Permalink Migration Plugin to achieve this for you.

This plugin will generates a “301 Redirect” when user or spider visit your site through old permalinks,and redirect them to the new permalinks of the same post.

Do not fear to change your permalink structure now, you would never lose any visitors due to changed addresses.

Download Dean’s Permalinks Migration Plugin Version 1.0

Installation

  1. unzip and upload the file into your wp-content/plugins/ directory.
  2. Activate it on your Admin Panel->Plugin Management page.

Usage

  1. goto admin panel->options->PermalinksMigration.set the old permanlink structure of your site.
  2. goto admin panel->options->Permalinks.change the new permalink structure to what you want. (personally I recommend /%category%/%postname%/, you can read @ArunBasilLal’s tour  to learn more about how to Optimizing Permalinks for Better SEO)
  3. Done,enjoy it.

Acknowledgements

Many thanks to all of you, who have encouraged me to update my articles  and code, and who sent in bug reports and fixes.

基于Wu-Manber算法的快速多关键词搜索

很多应用都需要高性能的多关键词搜索功能,网络”扫黄”开始后更是如此,如何在文本内容中快速地搜索出敏感关键字变得越来越重要。

Wu-Manber算法是一个不错的解决方案,尤其是针对包含有大量关键词的搜索。Wu-Manber算法的C语言实现非常丰富,为了方便如C#,VB.net等编程语言使用该算法,我用C/C++写了一个基于改进的Wu-Manber算法的多关键词搜索组件:wu-manber-com

Download wu-manber-com

使用方法

以vb.net/c#为例,使用前,先运行regsvr32 stringsearch.dll注册该组件,然后将stringsearch.dll添加到项目引用中。调用示例代码如下:

StringSearchLib.WuManber s = new StringSearchLib.WuManber();
s.AddPatterns("keyword1,keyword2,keyword3", ",", false);
int index = s.Search("... some text for searching...");
Console.WriteLine(index);

该控件不会搜寻所有存在的关键词,碰到第一个匹配的关键词,即返回该匹配的关键词在原文中的位置索引,没有找到则返回-1。

Compile with /MP flag on my system

The most interesting feature I like in VC 2008 is the parallel build capability.

The /MP option can reduce the total time to compile the source files on the command line. The /MP option causes the compiler to create one or more copies of itself, each in a separate process. Then these copies simultaneously compile the source files. Consequently, the total time to build the source files can be significantly reduced.

Continue reading “Compile with /MP flag on my system”

QT/VC2008:Project is rebuilt every time even though I didn’t make any modifications

I have encountered problem when attempting to compile VC projects created by QT 4.5.2,VC always rebuilds the whole project when I start to run or build the project, even though I didn’t make any modifications to the code.the project is always “out of date”.

that is because the custom build step generated by QT for each header files that contain the Q_OBJECT macro are dependent on mocinclude.tmp,which being created every time the project is built,the mocinclude.tmp’s date is later than the header files,so the custom build rule will be run every time.

to solve this problem,open %QTDIR%/makespecs/features/moc.prf,comment out  these two lines(add ‘#’’ at the start of line):

!isEmpty(INCLUDETEMP):moc_source.depends += $$INCLUDETEMP 
......
!isEmpty(INCLUDETEMP):moc_header.depends += $$INCLUDETEMP

and run qmake –tp vc again to regenerate the project files.

rOptiPng:an modification to OptiPNG to support recursive directory optimization

rOptiPng,hosted on google code, is an modification to OptiPNG to support the optimization of multiple directories with recursion,making it easier to use,especially when optimizing many image files in different directories,such as a website.

Download roptipng

To optimization of multiple directories recursively with rOptiPng,simply by using the ** wildcard in file path.
for examples:
roptipng **/*.png
roptipng c:\photos\**\*.png
roptipng c:\photos\**\*.png d:\website\**\*.png
roptipng c:\photos\**\image8.png

image

if you find it useful, a time saver,or even just mildly interesting,then my effort was worth it.
if you have any suggestions on how to improve it, I’d love to hear it.

Enjoy:)

The power of belief

今天去东山旅游,到了赫赫有名的关帝庙。本想拜一拜这位被神化的英雄,这位视天下英雄如无物,玉可碎而不改其白的真丈夫。只可惜庙里人太多,再加上于我而言,可拜也可不拜所以就作罢了。出了庙门,正好看到一群自台湾远道而来的老年人正在祭拜关公,一路敲锣打鼓,载歌载舞的抬着很多贡品,很虔诚的进行着各种堪称华丽的祭拜仪式。

像所有游客一样,我坐在一边静静的看着。不知过了多久,突然觉得自己和他们相比实在是很渺小,是信仰赋予了他们这样年轻的力量,内心充实而且满是希望。而曾几何时,我已经没有了信仰:对神的,对世界的,甚至于对自己的。

人类文明的奇迹,大部分因信仰而成就。就像云南西山的龙门,谁能想到如此鬼斧神工的人间奇迹,竟是由一个普普通通的石匠用双手造就的。只因信仰,他用尽毕生的精力,在峭壁上雕出栈道,从石头里刻出各种佛像。等一切都快完工,还剩下峰顶最后一个判官的时候,却一不小心琢断了判官手中的那支笔,他眼中一件完美的作品无法承受如此的缺憾,随后他就纵身从几百米高的悬崖上跳了下去。

我曾看着判官手上那支残笔,无数次的试图感受他当时的心情。最后我发现自己其实是在做一件非常可笑的事情:我没有如他般执着的信仰,即便有,也从不曾如他般执着的追求过,所以也就根本没有资格去感受他的感受。

如今的西山游人如织,不会有几个人记得这个工匠的名字,对他而言,这并不重要。人不能选择如何出生,但是可以选择如何结束。在我看来,他的结束方式近乎完美。
想起了最近被骂得很厉害的一部电影的片头:“很久很久以前,这是一个人神共存的世界”。也许,世界从来没有改变过,还是那个世界。只是我们没有了信仰,不再心存敬畏之心。

inffas32.asm: error A2070: invalid instruction operands

I got the following errors while compiling zlib on windows with Visual studio 2005:

1>inffas32.asm(649) : error A2070: invalid instruction operands
1>inffas32.asm(663) : error A2070: invalid instruction operands
1>inffas32.asm(720) : error A2070: invalid instruction operands

these errors are due to an issue with Microsoft Macro Assembler ,included with Visual C++ 2005.it refuses to assemble a MOVD instruction with a memory operand with an implied size, and requires that "dword ptr" prefix the memory operand.

to fix these problems,simply addingDWORD PTR’ before the operands:

movd mm5,dword ptr [esp+4](649)
movd mm7,dword ptr [esi](663)
movd mm7,dword ptr [esi](720)

Continue reading “inffas32.asm: error A2070: invalid instruction operands”

2009,Make some magic happen.

Too many things have changed since last year.too many things seemingly done behind my closed door.I’m tired of going to meeting after meeting where little is said or done.I’m tired of sitting behind my desk, coding something totally useless for 16 hours a day.

anyway,I’ll make some changes to my team and myself this year.to encourage and help them to achieve their dreams,to make some magic happen,to be lively,and happy.

悼念MO:a friend,and a mentor.

得知他因病突然辞世的消息的时候,我根本无法相信这是真的。前不久我们还有过一次长谈,关于生活,关于未来。他送了我一盘DVD,片名叫Planet earth-as you’ve never seen it before。说很值得一看。“要热爱生活”,这是他离开办公室时,最后对我说的一句话。

我还没来得及看这部片子,他却已经突然不在了。出殡前一晚我去给他守灵,为他,也为自己未尽的承诺。看着他静静的躺在那里,我突然觉得他有一种无法言喻的孤独,人走的时候也许都很孤独,活着的时候又何尝不是如此呢?

他喜欢爬山,我很喜欢这张他去年在珠峰拍的照片,每个人心目中都有属于自己的顶峰,可不是每个人都能在上面留下自己的足迹,而他做到了。mo142

生命不会因为短暂而失去光彩,活在其他人的记忆里也是一种永生。MO,一路走好。

YAAPC has upgraded to version 1.1.3 with SEO Enhanced

This version adds a feature that can automatically generate “noindex,follow” meta tag in your paged comments page to avoid duplicate content in search engine.Many thanks to Hank’s for his great comment and advice to YAAPC:

Isn’t that causeing a lot of duplicate content? Do i’ve to stop all “?p=x&cp=x#comments” pages from being indexed via .htaccess/robot.txt or is there a switch to mark them “noindex” in robots meta tag? Every click on another comments page is counted as real pageview, right?

Continue reading “YAAPC has upgraded to version 1.1.3 with SEO Enhanced”

Boost your WordPress performance on Windows IIS 6 with FastCGI and eAccelerator in 5 minutes

First,download and install the FastCgi Extension for IIS 6 from microsoft.The FastCGI protocol enables PHP applications to be hosted on the IIS web server in a high-performance and reliable way.FastCGI re-uses CGI processes for multiple requests, which provides a significant performance boost as compared to CGI.

Once FastCgi is installed,Config FastCGI extension to work with php:

  1. Open a command line window,and change the current directory  to %WINDIR%\system32\inetsrv.
  2. Run
    cscript fcgiconfig.js -add -section:"PHP" -extension:php -path:"C:\PHP\php-cgi.exe"
    to register the PHP CGI program as the one that will be processing .php extensions.
  3. Modify fcigext.ini file in %WINDIR%\system32\inetsrv as the following (assuming you installed PHP to C:\PHP folder):

    [Types]
    php=PHP

    [PHP]
    ExePath=c:\php\php-cgi.exe

Next,download and install eAccelerator.eAccelerator is a free open-source PHP accelerator, optimizer, and dynamic content cache. It increases the performance of PHP scripts by caching them in their compiled state, so that the overhead of compiling is almost completely eliminated. It also optimizes scripts to speed up their execution. eAccelerator typically reduces server load and increases the speed of your PHP code by 1-10 times.

After eAccelerator is downloaded:

  1. Copy eaccelerator.dll to your php extensions folder to c:\php\extensions.(assuming you installed PHP to C:\PHP folder)
  2. Create a folder (with the appropriate permissions) for the temporary cached files.
    For example: c:\tmp\eaccelerator
  3. Add the following to your php.ini (as the first loaded extension):

    extension=eAccelerator.dll
    eaccelerator.shm_size="128"
    eaccelerator.cache_dir="c:\tmp\eaccelerator"
    eaccelerator.enable="1"
    eaccelerator.optimizer="1"
    eaccelerator.check_mtime="1"
    eaccelerator.filter=""
    eaccelerator.shm_max="0"
    eaccelerator.shm_ttl="0"
    eaccelerator.shm_prune_period="0" 
    eaccelerator.shm_only="0"
    eaccelerator.compress="1"
    eaccelerator.compress_level="9"
    eaccelerator.keys = "shm"
    eaccelerator.sessions = "shm"
    eaccelerator.content = "shm"

That’s all,restart your IIS and you’ll get a faster WordPress on windows IIS 6 with highly boosted performance.

Because IIS does not support mod_rewrite module for rewriting URLs,the biggest problem hosting wordpress on iis is that you always get an ‘ugly’ and not SEO-friendly index.php in your permalinks.you can install wp_url_rewriting,an open source URL rewriting for wordpress, to resolve this issue.

Yet another Ajax paged comments plugin for wordpress (YAAPC)

This Plugin provides Ajax enabled comments system with paging,posting and form validation to your WordPress blog.

image

Features:

  • Ajax page navigation

    When the user navigate through the comments via page selector,only the comments area will be send back to the client and refreshed,not the full page.This actually save your server load and bandwidth thus making your blog faster and more responsive. The paging system works even if JavaScript is disabled.

  • SEO friendly

    Pagination can cause a duplicate content issue with search engines.YAAPC can automatically generate “noindex,follow” meta tag in your paged comments page to avoid duplicate content in search engines that may hurt your rankings.(many thanks for Hank’s great comment and advice)

  • Ajax comment posting

    Posting comments via Ajax,without page refreshing.

  • Comment form validation

    validate the user input in comment form before sending to server. 

Continue reading “Yet another Ajax paged comments plugin for wordpress (YAAPC)”

How to create a jabber chat bot based on AIML,the C# way.

I have created a jabber chat bot based on on the A.L.I.C.E(Artificial Linguistic Internet Computer Entity) and AIML(Artificial Intelligence Markup Language).which is named alice@35.cn,you can add alice@35.cn to your contact list and chat with her anytime:

image

It’s really simple to build your own alice chat bot by using agsXMPP and AIMLBot.The following sections is my quick and dirty tour on how to do it(You should know how to use agsXMPP and AIMLBot first):

After downloading and compiling the agsXMPP and AIMLBot,add them as References to your bot project:

image

Initialize AIMLBot :

AIMLbot.Bot myBot = new AIMLbot.Bot();
myBot.loadSettings();
myBot.loadAIMLFromFiles();

Response chat message in XmppClientConnection’s OnMessage Event:

AIMLbot.Request request = new Request(msg.Body, GetUser(msg.From.Bare), myBot);
AIMLbot.Result reply = myBot.Chat(request);
agsXMPP.protocol.client.Message replyMsg = new agsXMPP.protocol.client.Message();
replyMsg.Type = MessageType.chat;
replyMsg.To = msg.From;
replyMsg.Body = reply.Output; 

XmppCon.Send(replyMsg); 

a simple implementation of GetUser:

protected AIMLbot.User GetUser(String jid)
{
   Hashtable myHash = Hashtable.Synchronized(userSessions);
   AIMLbot.User user = (AIMLbot.User)myHash[jid];
   if (user == null)
   {
       user = new AIMLbot.User(jid, myBot);
       myHash[jid] = user;
   }
   return user;
} 

that’s all,it’s really easy and simple,huh?

PS:you can download free AIML sets from here

How to compile TORCS with visual studio 2005(VC 8.0)

TORCS is an open source, highly portable multi platform car racing simulation. It is used as ordinary car racing game, as AI racing game and as research platform.
image

TORCS can be compiled smoothly with Visual C++ 6.0.but you’ll get lots of compilation errors when trying to compile it with Visual Studio 2005(VC 8).here is the steps to resolve this issue:

Continue reading “How to compile TORCS with visual studio 2005(VC 8.0)”

What I’m doing and what will be done

With months of development during off-duty time,I had created an web-based Microsoft SQL Database administration tool in C/C++,which codename is "Labrina".

image 

With Labrina , you will do through a browser almost everything you did before with MS Enterprise Manager.It is intended to handle the administration of SQL Server databases over the Web. It allows you to fully manage your databases even when you don’t want or cannot use MS Enterprise Manager.

Continue reading “What I’m doing and what will be done”