Archive for the 'Programming' Category


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:

October 5th, 2011 in Programming | 2 comments


repoze.who: perform login programmatically

It took me a while to find out how to perform programmatic login using repoze.who.here is the source code:

rememberer = request.environ['repoze.who.plugins']['cookie']
identity = {'repoze.who.userid': user.username}
response.headerlist = response.headerlist + \
	rememberer.remember(request.environ, identity) 

July 8th, 2010 in Programming | 6 comments


Happy birthday,sweet little EQ

No words can express how much I love you from the day you were born until now,you have held a special place in my heart, one that is irreplaceable and invaluable.

35eq

Happy birthday, My sweet little EQ.

December 28th, 2009 in Programming | 4 comments


基于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。

December 21st, 2009 in Programming | 3 comments


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.

September 8th, 2009 in Programming | 1 comment


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

September 8th, 2009 in Programming | 1 comment


LogMicroscope:boost performance for logging system by 43%

Recently,I have rewritten the logging engine for LogMicroscope,using circular-buffer in log writing threads,and WriteFileGather in file writing thread to gathers up the data from these discrete buffers in memory and transfers them "in place" as a single operation.

September 2nd, 2009 in Programming | 1 comment


Moved OpenSSL for windows to google code

Due to the bandwidth limitation and the lack of issue tracking system,I have moved OpenSSL for windows to google code: http://code.google.com/p/openssl-for-windows/

if you have any questions/issues,please submit an issue at http://code.google.com/p/openssl-for-windows/issues/list

July 24th, 2009 in Programming | 3 comments


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:)

July 21st, 2009 in Programming, projects | 6 comments


Online JavaScript Compressor

I have written an online JavaScript compressor using JsMin,It typically reduces filesize by half, resulting in faster downloads.

image

Feel free to use this tool and give me feedback if you have any.

July 20th, 2009 in Programming | 1 comment


英汉翻译机器人:en-cn@35.cn(Jabber translator bot)

en-cn@35.cn是一个英汉/汉英翻译机器人,你可以用任何支持Jabber/xmpp的客户端,比如Gtalk,将机器人添加为好友,然后就能通过与他聊天来获得英汉单词、短句的翻译。目前还不支持全文翻译,下个版本我会增加这个功能:

image

July 17th, 2009 in Programming | 1 comment


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)

April 30th, 2009 in Programming, Windows | No comments yet