Tuesday, 25 September 2012

sed 去掉windows下的回车符

用 sed 去掉 去掉windows下的回车符
 (注意^M 在linux 下写法 按^M 是回车换行符,输入方法是按住CTRL+v,松开v,按m)
sed -i 's/^M//g' df.txt  

word swith field

Switch field codes [Alt]+[F9]

Monday, 12 March 2012

check if a year is a leap year.

read this codes from Linux Device Driver, think it is good :)
record it here.

/*
 * return 1 if year is leap year, 0 otherwise.
 */
static int inline
leap_year(int year)
{
    return !(year % 400) || ( !(year % 4) && (year % 100)) ;
}

/* Number of days in each month (not leap year). */
static const char no_of_days[] =
{ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};