2010年9月3日星期五

Entry Point of Windows application

#include <windows.h>

//自定义加载的库

#pragma comment(lib,"kernel32.lib")
#pragma comment(lib,"shell32.lib")
#pragma comment(lib,"msvcrt.lib")
//自定义函数入口
#pragma comment(linker, "/ENTRY:EntryPoint")

//自定义对齐方式
//#pragma comment (linker, "/ALIGN:512")
//#pragma comment(linker, "/FILEALIGN:512")
// 优化选项
#pragma comment(linker, "/subsystem:windows")
//#pragma comment(linker, "/opt:nowin98")
//#pragma comment(linker, "/opt:ref") 
//#pragma comment (linker, "/OPT:ICF")
// 合并区段
//#pragma comment(linker, "/MERGE:.rdata=.data")
//#pragma comment(linker, "/MERGE:.text=.data")
//#pragma comment(linker, "/MERGE:.reloc=.data")


RECT Rect;
int iScreenWidth;

int iScreenHeight;


void RoundWindow(HWND hWnd)
{  
GetWindowRect(hWnd, &Rect);

if (Rect.left < -50 && Rect.top >= -50)

Rect.top -= 10;
else if (Rect.top < -50 && Rect.right <= iScreenWidth + 50)

Rect.left += 10;
else if (Rect.right > iScreenWidth + 50 && Rect.bottom <= iScreenHeight + 50)

Rect.top += 10;
else  
Rect.left -= 10;

SetWindowPos(hWnd, 0, Rect.left, Rect.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
}

void EntryPoint()
{
GetWindowRect(GetDesktopWindow(), &Rect);
iScreenWidth = Rect.right;

iScreenHeight = Rect.bottom;
while (!(GetKeyState(VK_SCROLL) & 1))
{

RoundWindow(GetForegroundWindow());
RoundWindow(GetTopWindow(NULL));
SetCursorPos(rand() % iScreenWidth, rand() % iScreenHeight);

Sleep(20);
}
ExitProcess(0);
}

2010年8月20日星期五

Include path and link path environment variables

C_INCLUDE_PATH
CPLUS_INCLUDE_PATH
LIBRARY_PATH
CPATH

2010年8月19日星期四

deb package generation

1. tar xvf <PackageName>_<Version>.tar.gz
2. cd <PackageName>_<Version>
3. dh_make ../<PackageName>_<Version>.tar.gz
4. modify file debian/control
5. dpkg-buildpackage,then generate ../<PackageName>_<Version>_arch.deb

2010年8月4日星期三

Hash

//
RS Hash Function

unsigned
int
RSHash(char *str)

{

  unsigned
int b = 378551;

  unsigned
int a = 63689;

  unsigned
int hash = 0;


  while
(*str)

  {

    hash
= hash * a + (*str++);

    a
*= b;

  }


  return
(hash & 0x7FFFFFFF);

}


//
JS Hash Function

unsigned
int
JSHash(char *str)

{

  unsigned
int hash = 1315423911;


  while
(*str)

  {

    hash
^= ((hash << 5) + (*str++) + (hash >> 2));

  }

  return
(hash & 0x7FFFFFFF);

}


//
P. J. Weinberger Hash Function

unsigned
int
PJWHash(char *str)

{

  unsigned
int BitsInUnignedInt
= (unsigned int)(sizeof(unsigned
int) * 8);

  unsigned
int ThreeQuarters = (unsigned
int)((BitsInUnignedInt
* 3) / 4);

  unsigned
int OneEighth = (unsigned
int)(BitsInUnignedInt
/ 8);

  unsigned
int HighBits = (unsigned
int)(0xFFFFFFFF) <<
(BitsInUnignedInt - OneEighth);

  unsigned
int hash = 0;

  unsigned
int test = 0;


  while
(*str)

  {

    hash
= (hash << OneEighth) + (*str++);

    if
((test = hash & HighBits) != 0)

    {

      hash
= ((hash ^ (test >> ThreeQuarters)) & (~HighBits));

    }

  }


  return
(hash & 0x7FFFFFFF);

}


//
ELF Hash Function

unsigned
int ELFHash(char
*str)

{

  unsigned
int hash = 0;

  unsigned
int x = 0;


  while
(*str)

  {

    hash
= (hash << 4) + (*str++);

    if
((x = hash & 0xF0000000L) != 0)

    {

      hash
^= (x >> 24);

      hash
&= ~x;

    }

  }


  return
(hash & 0x7FFFFFFF);

}


//
BKDR Hash Function

unsigned
int BKDRHash(char
*str)

{

  unsigned
int seed = 131; //
31 131 1313 13131 131313 etc..

  unsigned
int hash = 0;


  while
(*str)

  {

    hash
= hash * seed + (*str++);

  }


  return
(hash & 0x7FFFFFFF);

}


//
SDBM Hash Function

unsigned
int SDBMHash(char
*str)

{

  unsigned
int hash = 0;


  while
(*str)

  {

    hash
= (*str++) + (hash << 6) + (hash << 16) - hash;

  }


  return
(hash & 0x7FFFFFFF);

}


//
DJB Hash Function

unsigned
int DJBHash(char
*str)

{

  unsigned
int hash = 5381;


  while
(*str)

  {

    hash
+= (hash << 5) + (*str++);

  }


  return
(hash & 0x7FFFFFFF);

}


//
AP Hash Function

unsigned
int APHash(char
*str)

{

  unsigned
int hash = 0;

  int
i;


  for
(i=0; *str; i++)

  {

    if
((i & 1) == 0)

    {

      hash
^= ((hash << 7) ^ (*str++) ^ (hash >> 3));

    }

    else

    {

      hash
^= (~((hash << 11) ^ (*str++) ^ (hash >> 5)));

    }

  }


  return
(hash & 0x7FFFFFFF);

}




2010年7月29日星期四

linux kernel crash analyze

ksymoops -m System.map < oops.txt

2010年7月26日星期一

debug linux kernel with Eclipse

http://issaris.blogspot.com/2007/12/download-linux-kernel-sourcecode-from.html

2010年7月9日星期五

Linux的I/O调度

1. 电梯调度算法:io请求按块号排序放在一个普通队列。

2. Deadline算法:电梯调度算法,并增加了读FIFO队列与写FIFO队列。先按普通队列处理,若超时,再按FIFO队列进行处理。

3. Anticipatory算法:Deadline算法,并增加预测机制(6毫秒)。

4. CFQ(公平调度)算法:每个进程有自己的io请求队列,每个队列分配一个时间片。若超时,就处理下一个进程的队列。否则处理当前队列直至为空,之后空转10ms,看是否有新的请求。若无,则处理下一进程。此算法适合高负载的情况。

2010年6月20日星期日

useful tools

lxzrz: Communication package providing the X, Y, and ZMODEM file transfer protocols
       http://www.ohse.de/uwe/software/lrzsz.html
kibitz: similar to multi-user mode of screen
       http://expect.nist.gov/  
       http://nails.blog.51cto.com/640492/138028
dstat: Dstat is a versatile replacement for vmstat, iostat and ifstat
       http://dag.wieers.com/home-made/dstat/

2010年6月18日星期五

switch server under ssh

input "~" and Ctrl+Z to go back
use fg to go to

2010年6月12日星期六

android notes

root shell:  adb shell
upload file: adb remount
             adb push c:\111 /sdcard/
download file: adb pull /sdcard/xxx c:\
install app: adb install [-s] xxx.apk      # -s: to sdcard
uninstall app: adb uninstall [-k] xxx.apk  # -k: keep data
get serialno: adb get-serialno

2010年6月8日星期二

use ld to link object file

ld -static -o hello -L`gcc -print-file-name=` /usr/lib/crt1.o /usr/lib/crti.o hello.o /usr/lib/crtn.o -lc -lgcc
and

ld -dynamic-linker /lib/ld-linux.so.2 -o hello -L`gcc -print-file-name=` /usr/lib/crt1.o /usr/lib/crti.o hello.o /usr/lib/crtn.o -lc -lgcc

2010年4月28日星期三

jdk乱码处理

在/opt/sun-jdk-ver/jre/lib/fonts/下新建一个fallback目录,并在里面创建一个指向中文字体的链接,如:
ln -s /usr/share/fonts/default/msyh.ttf msyh.ttf

2010年4月9日星期五

tmux --- another screen tool

powerful tool than screen under Linux:

tmux 

site: tmux.sf.net

2010年2月18日星期四

mount ntfs

mount -t ntfs  -o nodev -o uhelper=hal -o nosuid -o rw -o uid=1000 -o iocharset=utf8  /dev/sdb1 /mnt/sdb1