Sunday, August 15, 2010

4年前在做什麼

在google lucene 與gais搜尋到一個有趣的事情。
原來有這段歷史。

參考來源:

"回想起来:从Jack Xu确定我们使用Lucene这个方向到项目上线:我们用了将近4个月左右的时间:而当时Lucene 1.2还是一个在SourceForge孵化的项目。还要感谢当时网易的搜索产品经理:肖尚雷给我的机会,是他带我进入这个行业,让我能有时间从头到尾学习了Lucene这个项目的源代码。在Lucene之前,各个门户网站的搜索用的还是台湾中正大学中正大学资工所创立的一个索引/查询引擎GAIS,GAIS不提供源代码,只有可执行版本的工具包(有不同平台下的binary发布版)。四年过去了:Lucene项目发展很快并应用到大量的WEB和桌面应用中。网易也许是第一个使用Lucene引擎的,我也很高兴将Lucene推广并应用到了更多的项目中,包括:"
- 911 四年前的今天你在做什么? (车东[Blog^2]) (在「Google 網頁註解」中檢視)

socialtext介紹-價值中國

socialtext介紹-價值中國
唐鳳講到socialtext
很好奇

參考來源: “商业开源”的创新者 - 人物专访 - 价值中国网 (在「Google 網頁註解」中檢視)

Saturday, August 14, 2010

NodeJS探索

NodeJS探索

一、什么是NodeJS?
第一眼看到这个词,估计你和我一样,以为它不过是一个JavaScript框架吧?如果是,那么首先恭喜你,说明你的思维是正常的。其次鄙视你:凭什么带 JS的就一定是JavaScript框架?你丫做技术的吧?最看不起你们这帮做技术的了,跟姓韩的那谁似的,没一点文化。
生活经验告诉我们,牛人往往都不怎么正常,正常人往往都成不了牛人。比如说NodeJS的发明者,这家伙就曾叫嚣说:其实JavaScript更适合做服务器端的并发编程。估计很多人听到这话都笑了,嗯,原谅我的可耻,我也笑了。令人欣慰的是上帝没有笑。当年上帝说要光,于是就有人脱了个精光。今天,上帝说我相信这个人能成,于是这个人还真成了,他弄了这么个东西:NodeJS--基于V8引擎的,使用事件驱动模型而不是复杂的多线程来获得可伸缩性,类似 Ruby的EventMachine和Python的Twisted的轻量级WEBServer。
是不是很有意思?这意味着什么我想大伙都清楚吧?嗯,如果这东东真的可用,那就是说,以后前段后端都可以都用JavaScript来编程了,这对于JS程序员来说,真是一个莫大的福音,因为你们再也不用看着那帮做后台的孙子的脸色干活了,可以翻身做后端了。
好,废话到此,那接下来就请跟着我,开始NodeJS的探索之旅。

參考來源: NodeJS探索 « 老韩 (在「Google 網頁註解」中檢視)

Friday, August 06, 2010

Quanta Plus簡介

簡介

參考來源:

"一直都想介绍一下Quanta Plus这款linux下的IDE (基于Qt的程序)。这是我目前使用过的最好用,最上手的网页编辑器了,D.K的所有代码也都是在这个编辑器下写的。我曾经推荐过另一款linux下的IDE: Aptana。那相比Aptana,Quanta Plus有什么优势呢?"
- Quanta Plus : A Brief Review of an IDE under Linux (在「Google 網頁註解」中檢視)

Linux下Web開發工作介紹

Using Linux for Web Design and Development (Ubuntu)
Tags:

* Web Design Tools
* Linux
* Ubuntu

2006, August 28 - 12:48pm — Webmaster Tips

[Note: to install the following programs on Ubuntu, make sure that you have the Universe repository enabled. You can either use the terminal, or Synaptic. For more information on how to install software on Ubuntu, see this article. Generally you can just type the following in the terminal:

參考來源:

"Using Linux for Web Design and Development (Ubuntu)"
- Using Linux for Web Design and Development (Ubuntu) | Webmaster Tips (在「Google 網頁註解」中檢視)

Thursday, August 05, 2010

strcasestr

类似的还有strcasestr,是strstr的忽略大小写版本
memmem,是对付内部包含0值字节的版本,因为0会被str族函数认为是结束符

參考來源:

"类似的还有strcasestr,是strstr的忽略大小写版本 memmem,是对付内部包含0值字节的版本,因为0会被str族函数认为是结束符"
- strstr函数的功能 - C语言论坛 - 编程论坛 (在「Google 網頁註解」中檢視)

mememe1 like strstr

#include

/* ----------------------------------------------------------------------------
* memmem()
* ----------------------------------------------------------------------------
* function
* Like strstr(), but for binary data -- seeks to find 'tofind' in 'source'.
*
* returns
* A pointer to the matching data.
* NULL if not found.
*/
const void* memmem(
const void* source, size_t sourcesize,
const void* tofind, size_t tofindsize
) {
int value;
const void* found;

/* If either 'source' or 'tofind' are missing or blank then we are done */
if (!source || !tofind || !sourcesize || !tofindsize) return source;

value = *(const unsigned char*)tofind;

/* While we can find potential matches */
while ((found = memchr( source, value, sourcesize )))
{
/* Keep track of what amount remains of the source */
sourcesize -= (const unsigned char*)found - (const unsigned char*)source;

/* If there isn't enough of the source left to match, then return 'not found' */
if (sourcesize < tofindsize) return NULL;

/* Did we find an exact match? */
if (memcmp( found, tofind, tofindsize ) == 0) return found;

/* Ready to find the next potential match */
source = (const unsigned char*)found + 1;
sourcesize--;
}

/* No match found */
return NULL;
}

參考來源:

"Since you are working with binary data, you should avoid using string functions. Unfortunately, there is no equivalent of strstr() for binary memory, but it is easy enough to construct one:"
- Checking for null characters in the midd... - C++ Forums (在「Google 網頁註解」中檢視)

memmem strstr

strstr這個fucntion是針對搜尋C字串設計的
而memmem是針對搜尋某個character buffer設計的
聽出來有什麼不一樣了嗎
如果你的character buffer裡面包含有多個null terminator的話
用strstr就有可能會搜尋不到substring
因為strstr只會搜尋第一個null terminator之前的字串內容
這時候就需要memmem啦
不過這個function是GNU的extension喔
所以記得要定義#define _GNU_SOURCE才可以使用喔
又學到一課啦~

參考來源:

"strstr這個fucntion是針對搜尋C字串設計的 而memmem是針對搜尋某個character buffer設計的 聽出來有什麼不一樣了嗎 如果你的character buffer裡面包含有多個null terminator的話 用strstr就有可能會搜尋不到substring 因為strstr只會搜尋第一個null terminator之前的字串內容 這時候就需要memmem啦 不過這個function是GNU的extension喔 所以記得要定義#define _GNU_SOURCE才可以使用喔 又學到一課啦~"
- Infinite Waiting: strstr與memmem有啥差別!? - yam天空部落 (在「Google 網頁註解」中檢視)

Reading image file in binary mode

#include
#include
#include
#include

int main()
{
int rc = 0;
char buffer[BUFSIZ] = {0};

FILE* p_infile = 0;
FILE* p_outfile = 0;

int length = 0;
int done = 0;

printf( "Enter the file name for the input file to be copied: " );
fgets( buffer, BUFSIZ, stdin );
buffer[ strlen( buffer ) -1 ] = 0;

p_infile = fopen( buffer, "rb" ); /* the b is added for Windoze/DOS systems... */
if( !p_infile )
{
rc = errno;
printf( "error opening %s for reading\n", buffer );
}
else
{
printf( "Enter the file name for the output file to be written: " );
fgets( buffer, BUFSIZ, stdin );
buffer[ strlen( buffer ) -1 ] = 0;

p_outfile = fopen( buffer, "wb" ); /* the b is added for Windoze/DOS systems... */
if( !p_outfile )
{
rc = errno;
printf( "error opening %s for writing\n", buffer );
}
else
{
do
{
length = fread( buffer, 1, sizeof( buffer ), p_infile );
done = length < (int)sizeof( buffer );
fwrite( buffer, 1, length, p_outfile );
}
while( !done );
}
}

if( p_infile )
{
fclose( p_infile );
p_infile = 0;
}

if( p_outfile )
{
fclose( p_outfile );
p_outfile = 0;
}
return rc;
}

參考來源:

"Here is an example that may help if all you're doing is looking to copy the file. I call this code filecopy.c, but you can call it anything that you want."
- Please Help - Reading image file in binary mode - GIDForums (在「Google 網頁註解」中檢視)

my_strlen

unsigned int my_strlen(const char *szString)
{
unsigned int iBytes = 0;
while(*szString++ != '\0')
iBytes++;
return iBytes;
}

參考來源:

"unsigned int my_strlen(const char *szString) { unsigned int iBytes = 0; while(*szString++ != '\0') iBytes++; return iBytes; }"
- Explanation on strlen(buffer) (在「Google 網頁註解」中檢視)

Wednesday, August 04, 2010

範例:有一個檔案(points.bin)用整數記錄全班50位同學的成績, 寫一程式讓使用者查尋學生成績

範例:有一個檔案(points.bin)用整數記錄全班50位同學的成績, 寫一程式讓使用者查尋學生成績

#include < iostream.h >
#include < stdio.h >

void main(void)
{
int num;
int data;
FILE *file=fopen("points.bin","rb");
do
{
printf("num=");
scanf("%d",&num);
if ( num>=50 || num<0 )
break;
fseek(file, num*sizeof(int), SEEK_SET);
fread(&data, sizeof(int), 1, file);
printf("Student(%d)=%d\n",num,data);
} while(1);
fclose(file);
}

參考來源:

"fseek( input, 0, SEEK_END); // 先把讀寫位置移到檔尾 filelen = ftell( input ); // 再傳回檔案目前的讀寫位置 範例:有一個檔案(points.bin)用整數記錄全班50位同學的成績, 寫一程式讓使用者查尋學生成績"
- 第八章:檔案 (在「Google 網頁註解」中檢視)

Minidx.com

minidx.com search engine

參考來源:

"一时想不出博客叫什么名字好,因为是放在Minidx.com下面的,所以就叫全文检索博客好了。不过内容五花八门,可能什么都有吧。Minidx是我于05年开始开发的一个全文检索引擎,关于Minidx全文检索的信息,请访问:http://minidx.com,中文请到:http://cn.minidx.com。 如有问题请联系minidxer(at)gmail.com,谢谢配合! 相关技术交流类的问题请尽量通过在http://blog.minidx.com/guestbook或者相关文章里留言而不要发邮件,因为你的邮件很有可能被自动归类到SPAM里导致我没办法看到……"
- About | 中文Flex例子 (在「Google 網頁註解」中檢視)

dump_buffer

void dump_buffer(void *buffer, int buffer_size)
{
int i;

for(i = 0;i < buffer_size;++i)
printf("%c", ((char *)buffer)[i]);
}

參考來源:

"void dump_buffer(void *buffer, int buffer_size) { int i; for(i = 0;i < buffer_size;++i) printf("%c", ((char *)buffer)[i]); }"
- C, howto read binary file into buffer (在「Google 網頁註解」中檢視)

Tuesday, August 03, 2010

strstr c语言中的字符串分割(strstr)

1. int main(int argc,char **argv)
2. {
3. char temp[10];
4. char *haystack="aaa||a||bbb||c||ee||";
5. char *needle="||";
6. char* buf = strstr( haystack, needle);
7. while( buf != NULL )
8. {
9. strncpy(temp, haystack, buf-haystack);
10. temp[buf-haystack] =0;
11. printf( "%s\n ", temp); //haystack);
12.
13. haystack = buf + strlen(needle);
14.
15. buf = strstr( haystack, needle);
16. }
17. return 0;
18. }

參考來源:

"在前面C语言中利用strtok函数进行字符串分割介绍的strtok函数,比较适合多个字符(也就是字符串)作分隔符的场合,而很多时候我们仅仅需要某一个特定的字符来分割字符串,当然利用strtok也可以实现,不过这里介绍的strstr效率上来说更加适合。"
- c语言中的字符串分割(strstr) - ubuntu,debian,redhat -linuxany.com (在「Google 網頁註解」中檢視)

Monday, August 02, 2010

strtok

在搞了很久的search時,今天好像被雷打到,
懂了一些東西。
strtok的第二個NULL

在 Microsoft C strtok() 函數會採用兩個字串,做為引數。第一個是一系列的第二個字串所定義的分隔符號隔開的零個或多個語彙基元。strtok() 第一次呼叫傳回第一個引數中第一個語彙基元的指標。在原始字串中取得下一個語彙基元 (Token),strtok() 的呼叫必須由使用 NULL 做為第一個引數會告訴 strtok() 搜尋下一個在前一個語彙基元字串語彙基元。

使用 strtok() 時,請牢記下列資訊:

* 每次呼叫函式時使用相同的字串,所以由 strtok() 使用修改原始字串 strtok() 將會以 NULL 取代原始字串中的分隔符號。
* strtok() 到第二個引數可以隨時變更為不同的分隔符號。
* 只有單一字元都被視為分隔符號。

http://www.cplusplus.com/reference/clibrary/cstring/strtok/

http://life.iiietc.ncu.edu.tw/xms/forum/show.php?id=22791

參考來源: 資訊: strtok(): C 函式--補充的文件 (在「Google 網頁註解」中檢視)

General topics on UNIX programming

邊找regexec的時候剛好也找到解決opt的問題的網頁:
裏面有regex在C的範例,跟一些 Unix-like下的 programming教學。

http://mij.oltrelinux.com/devel/unixprg/
General topics on UNIX programming
The following entries cover some general programming topics under UNIX:

* Regular expressions
o notes
o summary
o example
* Parsing the command line
o notes
o summary
o examples
* Tasks, fork(), wait() and waitpid()
o notes
o summary
o examples
* Threads
o notes
o summary
o examples

Interprocess communication / UNIX IPC programming
The following entries cover topics specific to Inter-process communication mechanisms under UNIX:

* IPC: signals
o notes
o summary
o examples
* IPC: pipes
o notes
o summary
o examples
* IPC: named pipes
o notes
o summary
o examples
* IPC: BSD sockets
o notes
o summary
o examples
* IPC: POSIX Message queues
o notes
o summary
o examples
* IPC: POSIX Semaphores
o notes
o summary
o examples
* IPC: POSIX shared memory
o notes
o summary
o examples
* IPC: notes on POSIX objects -- the POSIX objects mess
o notes

參考來源:

"General topics on UNIX programming The following entries cover some general programming topics under UNIX: Regular expressions notes summary example Parsing the command line notes summary examples Tasks, fork(), wait() and waitpid() notes summary examples Threads notes summary examples"
- UNIX programming examples (在「Google 網頁註解」中檢視)

Saturday, July 31, 2010

出拳手必要不要打直

出拳手必要不要打直
因為這個問題,所以找了一下並且參考一些資料。
這裡個blog 提到一些人對於出拳要不要出打直提出看法,就算是同屬於JKD的系統,也有不一樣的見解。

2010年6月前,我之前是奉行手畢完全打直的。後來,發現有點卡卡的有時手還會有點痛。

後來有聽一位柔道教練說,伸直受敵容易傷到手肘。
後來出拳,改成拳頭往下扣一點。

參考一些人的照片,跟看寶師出拳的樣子。
發現,自己上臂的肌肉其實是不發達的。如果是發達的,就沒有個問題,因為伸直剛好是"不折的手"(合氣道裏面稱的),那整條肌腱剛好彎曲護住。

所以也就沒有這個問題了。

參考來源:

"截拳道在出拳時強調《手臂不可完全打直》有幾個原因: 1.自然;人的手在放鬆自然垂下時是微彎的(我們稱為九分直或自然彎度)(如下圖),沒有人是完全直的,除非你在用力! 2.拳打直一旦落空,很容易震傷自己的手肘,或失控。 3.避免被反擊手肘關節(拳打直一旦對手反擊你的關節,只要輕輕一震你的手就會受傷甚至斷掉,而在九分直時還有一分的緩衝空間可以瞬間抵抗,不致於立即受傷)。 4.拳頭收回的《速度》比起完全打直時更快速!"
- 截拳道之《手臂不可完全打直》之根本概念 - 台灣截拳道(J.K.D) - 阿峰 - Yahoo!奇摩部落格 (在「Google 網頁註解」中檢視)

Thursday, July 29, 2010

你的時間不夠用嗎

這是個不錯的分享網址
叫作惜墨,也就是都是珍藏,珍貴的意思。
副標題是,你有一個夢想,你要保護它。
裏面有不錯的文章,滿值得一看。

-----
你的时间不够用么?
2010年07月28日 | 个人提升, 提高效率, 时间管理, 简化生活, 简单生活 | 作者:博华gravatar关闭作者: 博华 姓名: 博华
Email: bhzhang1@gmail.com
博客: http://www.apple4.cn
个人介绍: 博华喜欢打篮球,喜欢看书,喜欢听歌,喜欢简单的生活。每天只专注于最重要的事情,不去想其他的杂事。喜欢水滴石穿的道理,因为寓意很简单:专注+坚持。人生的座右铭是:既然你已经决定在生活中放手一搏,为什么不去倾尽全力干到极致?看他的所有文章 (138)

我们经常会说一句话“我没有时间。”我不禁反问,我们为什么没有时间?同样的人,每天都有同样的24小时,为什么有些人出色的完成了工作,有些人甚至要去加班加点完成昨天的工作?我想,这不仅仅是一个效率问题,更是一个生活态度的问题。
一、管理时间=管理金钱?

參考來源:

"你的时间不够用么? 2010年07月28日 | 个人提升, 提高效率, 时间管理, 简化生活, 简单生活 | 作者:博华关闭作者: 博华 姓名: 博华 Email: bhzhang1@gmail.com博客: http://www.apple4.cn个人介绍: 博华喜欢打篮球,喜欢看书,喜欢听歌,喜欢简单的生活。 每天只专注于最重要的事情,不去想其他的杂事。 喜欢水滴石穿的道理,因为寓意很简单:专注+坚持。 人生的座右铭是:既然你已经决定在生活中放手一搏,为什么不去倾尽全力干到极致?看他的所有文章 (138) 我们经常会说一句话“我没有时间。”我不禁反问,我们为什么没有时间?同样的人,每天都有同样的24小时,为什么有些人出色的完成了工作,有些人甚至要去加班加点完成昨天的工作?我想,这不仅仅是一个效率问题,更是一个生活态度的问题。 一、管理时间=管理金钱?"
- 你的时间不够用么? | 惜墨,关注自我成长,个人提升,时间管理,简化生活,学习方法,生活技巧 (在「Google 網頁註解」中檢視)

大文本文件逆序(fread/fwrite操作

大文本文件逆序(fread/fwrite操作)
2010-03-05 13:52

备份

#include
#include
#include

void reverse(char *s,int len) //逆序函数
{
int i;
char temp;
for(i=0;i0) //待改进的一段
{
rewind(fp);
fseek(fp,(i-1)*SIZE,0);
fread(p1,SIZE,1,fp);
reverse(p1,SIZE-1);
fseek(fp,-i*SIZE,2);
fread(p2,SIZE,1,fp);
reverse(p2,SIZE-1);
fseek(fp,(i-1)*SIZE,0);
fwrite(p2,SIZE,1,fp);
fseek(fp,-i*SIZE,2);
fwrite(p1,SIZE,1,fp);
i++;
}
last = filelen-2*count*SIZE;
char *p = (char *)malloc(sizeof(char)*last);
if(last<2*SIZE)
{
fseek(fp,(i-1)*SIZE,0);
fread(p,last,1,fp); // 得大改的一段
reverse(p,last-1);
fseek(fp,(i-1)*SIZE,0);
fwrite(p,last,1,fp);
}

fclose(fp);
free(p1);
free(p2);
free(p);
system("pause");
return 0;
}

return 0;
}

当然,下面的也能逆序文件

#include
void reverse(FILE *fp)
{
char ch;
if ((ch=fgetc(fp))!=EOF)
reverse(fp);
else
rewind(fp);
if (ch!=EOF)
fputc(ch,fp);
}
int main(int argc, char* argv[])
{
FILE *fp=fopen("test.txt","r+");
if (fp)
{
reverse(fp);
fclose(fp);
}
return 0;
}

參考來源:

"大文本文件逆序(fread/fwrite操作) 2010-03-05 13:52 备份 #include <stdio.h> #include <stdlib.h> #include <string.h>"
- 大文本文件逆序(fread/fwrite操作)_巫山上云雨的空间_百度空间 (在「Google 網頁註解」中檢視)

This program reads a file and counts the words in it.

/*

* word_cnt.c

* This program reads a file and counts the words in it.

*/

參考來源:

"/*  * word_cnt.c  * This program reads a file and counts the words in it.  */"
- Ron Wein's C Examples: word_cnt.c (在「Google 網頁註解」中檢視)