2010年9月7日

2010年8月19日

some  material

http://blog.chinaunix.net/u/4206/showart_721067.html

http://blog.csdn.net/wushihua/archive/2010/07/02/5709359.aspx

linux 下:
0. bash
1. 用户任意设置“工作时间”,“休息时间”。目前考虑使用命令行参数 done
2. 动态获取“设备号”,在不同的机子上用可不需修改 (no so urgent)
*3. 时间显示
改进:
1.1 如果休息起来五分钟(默认休息时间)才回来,只剩下不多的工作时间,才做一会儿又要中断。
最好是在锁定键鼠五分钟后,在用户回来电脑时才开始让工作时间计时。
考虑方案一:
等待用户输入后才(解除鼠标锁定)开始进入下一轮工作计时(done)
较高级的方案:
休息时间结束后,捕捉到键盘或者鼠标动作才开始下一轮工作计时。
1.2 工作时间离开电脑,进入休息时间计时。若一定时间键鼠都没反应。
(done, 获取键盘鼠标的空闲,若比休息时间还长,进入新一轮的工作)

2. kill sleep后,可能键盘永远锁住。 解决关闭该程序的善后工作。(done , use signal)
锁住鼠标,不锁住键盘,在锁住鼠标时,Ctrl-C,结束程序,但鼠标没有解锁。

备注:
1. 是否锁定键盘得明确,考虑是否对两需求推出不同方案。暂考虑只锁键盘


some note:
1.
操作/dev/input/event*文件,向它写入个input_event结构体就可以模拟按键的输入
哪个event文件可通过cat /proc/bus/input/devices 查看。
N: Name="AT Translated Set 2 keyboard"
H: Handlers=kbd event3

N: Name="Logitech USB Optical Mouse"
H: Handlers=mouse1 event4
2.
Essentially keyboard and mouse idle time can be
gleaned (indirectly) from certain lines of the /proc/interrupts file. It
seems this file contains a counter for each device
http://software.itags.org/linux-unix/330299/

Sense mouse and keyboard inactivity final solution:
/*
This is a test example.
Ref:
http://coderrr.wordpress.com/2008/04/20/getting-idle-time-in-unix/

gcc -o idle idle_xscr2.c -lXss
*/
#include <stdio.h>
#include <X11/extensions/scrnsaver.h>
#include <unistd.h>
     
int main()
{
      XScreenSaverInfo *info = XScreenSaverAllocInfo();
    Display *display = XOpenDisplay(0);
   
    int i=1;
for(;i<5; i++){
    sleep(3);     
    XScreenSaverQueryInfo(display, DefaultRootWindow(display), info);
    printf("%ld ms\n", info->idle);
}
    return 0;
}


编译:
voide@fit:~/bash$ gcc lock.c -o lock -lXss
lock.c:24:38: error: X11/extensions/scrnsaver.h: No such file or directory
lock.c: In function ‘main’:
lock.c:41: error: ‘XScreenSaverInfo’ undeclared (first use in this function)
lock.c:41: error: (Each undeclared identifier is reported only once
lock.c:41: error: for each function it appears in.)
lock.c:41: error: ‘info’ undeclared (first use in this function)
lock.c:42: error: ‘Display’ undeclared (first use in this function)
lock.c:42: error: ‘display’ undeclared (first use in this function)
root@fit:/home/voide/bash# apt-get install libxss-dev
root@fit:/home/voide/bash# gcc lock.c -o lock -lXss
root@fit:/home/voide/bash# ./lock  1800 300   /* 1800s 300s*/
Use a short time for debug
sh: ./unlock.sh: Permission denied
root@fit:/home/voide/bash# chmod +x *.sh

posted @ 2010-08-19 10:52 Voider 阅读(332) | 评论 (0)编辑 收藏

2009年10月30日

http://www.cplusplus.com/reference/stl/deque/
Deque sequences have the following properties:
  • Individual elements can be accessed by their position index.
  • Iteration over the elements can be performed in any order.
  • Elements can be efficiently added and removed from any of its ends (either the beginning or the end of the sequence)


On the drawback side, unlike vectors, deques are not guaranteed to have all its elements in contiguous连续的 storage locations, eliminating排除 thus the possibility of safe access through pointer arithmetics.
For operations that involve frequent insertion or removals of elements at positions other than the beginning or the end, deques perform worse and have less consistent iterators and references than lists.
posted @ 2009-10-30 14:45 Voider 阅读(172) | 评论 (0)编辑 收藏
 

C++ 运算符优先级列表

http://www.cppreference.com/operator_precedence.html
http://www.cppblog.com/aqazero/archive/2006/06/08/8284.html
Precedence Operator Description Example Associativity
1 ()
[]
->
.
::
++
--
Grouping operator
Array access
Member access from a pointer
Member access from an object
Scoping operator
Post-increment
Post-decrement
(a + b) / 4;
array[4] = 2;
ptr->age = 34;
obj.age = 34;
Class::age = 2;
for( i = 0; i < 10; i++ ) ...
for( i = 10; i > 0; i-- ) ...
left to right
2 !
~
++
--
-
+
*
&
(type)
sizeof
Logical negation
Bitwise complement
Pre-increment
Pre-decrement
Unary minus
Unary plus
Dereference
Address of
Cast to a given type
Return size in bytes
if( !done ) ...
flags = ~flags;
for( i = 0; i < 10; ++i ) ...
for( i = 10; i > 0; --i ) ...
int i = -1;
int i = +1;
data = *ptr;
address = &obj;
int i = (int) floatNum;
int size = sizeof(floatNum);
right to left
3 ->*
.*
Member pointer selector
Member pointer selector
ptr->*var = 24;
obj.*var = 24;
left to right
4 *
/
%
Multiplication
Division
Modulus
int i = 2 * 4;
float f = 10 / 3;
int rem = 4 % 3;
left to right
5 +
-
Addition
Subtraction
int i = 2 + 3;
int i = 5 - 1;
left to right
6 <<
>>
Bitwise shift left
Bitwise shift right
int flags = 33 << 1;
int flags = 33 >> 1;
left to right
7 <
<=
>
>=
Comparison less-than
Comparison less-than-or-equal-to
Comparison greater-than
Comparison geater-than-or-equal-to
if( i < 42 ) ...
if( i <= 42 ) ...
if( i > 42 ) ...
if( i >= 42 ) ...
left to right
8 ==
!=
Comparison equal-to
Comparison not-equal-to
if( i == 42 ) ...
if( i != 42 ) ...
left to right
9 & Bitwise AND flags = flags & 42; left to right
10 ^ Bitwise exclusive OR flags = flags ^ 42; left to right
11 | Bitwise inclusive (normal) OR flags = flags | 42; left to right
12 && Logical AND if( conditionA && conditionB ) ... left to right
13 || Logical OR if( conditionA || conditionB ) ... left to right
14 ? : Ternary conditional (if-then-else) int i = (a > b) ? a : b; right to left
15 =
+=
-=
*=
/=
%=
&=
^=
|=
<<=
>>=
Assignment operator
Increment and assign
Decrement and assign
Multiply and assign
Divide and assign
Modulo and assign
Bitwise AND and assign
Bitwise exclusive OR and assign
Bitwise inclusive (normal) OR and assign
Bitwise shift left and assign
Bitwise shift right and assign
int a = b;
a += 3;
b -= 4;
a *= 5;
a /= 2;
a %= 3;
flags &= new_flags;
flags ^= new_flags;
flags |= new_flags;
flags <<= 2;
flags >>= 2;
right to left
16 , Sequential evaluation operator for( i = 0, j = 0; i < 10; i++, j++ ) ... left to right
posted @ 2009-10-30 10:31 Voider 阅读(167) | 评论 (0)编辑 收藏

2009年8月19日

  转:http://www.cppblog.com/benbendy/archive/2008/05/23/50830.html    

  转:  http://hi.baidu.com/gwabit/blog/item/7a188726f2dc91178a82a1b6.html


 C++/OPP/OOD系列:

层级一:语法/语意(C++)
1.1 [Lippman2000] Essential C++
                  Essential C++,by Stanley B. Lippman Addison Wesley Longman 
                  2000,276 pages
                  Essential C++ 中文版 ,侯俊杰 译,282页  

1.2 [Gregory95] C++:The Core Language 
                  C++:The Core Language by Gregory Satir 1995 O'Reilly
                  C++语言核心,张铭泽 译 ,236页

1.3 [Deitel98] The Complete C++ Training Course 
                  The Complete C++ Training Course 2/e by Harvey M.Deitel 1998 
                  Prentice Hall
                  C++大学教程(第二版),邱仲潘等 译,816页

1.4 [Stevens2000] Standard C++ Bible
                  Standard C++ Bible   2000  Al Stevens   IDG 
                  标准C++宝典,林丽闽等 译,766页

1.5 [Eckel2000] Thinking in C++ 
                  Thinking in C++ 2/e   Bruce Eckel  2000 1470 pages Prentice 
                  Hall
                  C++ 编程思想,刘宗田等 译,420页

1.6 [Lippman98] C++Primer 
                  C++ Primer,3rd Editoin,by Stanley Lippman and Josee Lajoie 
                  Addison Wesley Longman,1998 1237 pages
                  C++ Primer 中文版,侯俊杰 译,1999,1237页

1.7 [Struostrup2000] The C++ Programming Language
                  The C++ Programming Language,Special Editoin,by Bjarne 
                  Stroustrup
                  Addison Wesley Longman,2000,1017 pages
                  C++程序语言经典本,叶秉哲 译,儒林 1999

1.7 [ANSI C++] C++规格书 1998.9.1 PDF格式
                  ANSI C++ 1996 Draft


层级二:专家经验(C++/OOP)
2.1 [Meyers96] More Effective C++
                  More Effective C++,by Scott Meyers,Addison Wesley,1996,318pages
                  More Effective C++中文版,侯俊杰,培生 2000. 318页

2.2 [Meyers98] Effective C++ 
                  Effective C++,Second Edition,by Scott Meyers,Addison Wesley 
                  Longman,1998.256pages
                  Effective C++ 2/e 中文版,侯俊杰,培生 2000.256页

2.3 [Sutter99] Exceptional C++
                  Exceptional C++,by Herb Sutter,Addison Wesley 
                  Longman,2000.208pages
                  Exceptional C++中文版,侯俊杰,培生 2000.248页

2.4 [Sutter2001]More Exceptional C++ 
                  More Exceptional C++ by Herb Sutter,Addison Wesley 
                  Longman,2001.

层级三:底层机制(C++ Object Model)

3.1  [Ellis90] The Annotated C++ Reference Manual
                  The Annotated C++ Reference Manual,by Margaret A.Ellis and 
                  Bjarne Stroustrup 
                  Addison Wesley Longman,1990,447 pages.

3.2  [Lippman96] Inside the C++ Object Model
                  Inside the C++ Object Model,by Stanley Lippman,Addison Wesley 
                  Longman,1996,280pages
                  深度探索C++物件模型,侯俊杰 译                   

 层级四:设计观念的复用(C++/Patterns)
 

4.1  [Gamma95] Design Patterns:Elements of Reusable Object Oriented 
                  Software,
                  by Erich Gamma,Richard Helm,Ralph Johnson,and John 
                  Vlissides,Addison Wesley,1995.395pages
                  设计模式,李英军等译,机械工业出版社,2000.254页

4.2   [Alex2001]Modern C++ Design: Generic Programming and Design 
                  Patterns Applied
                  by Andrei Alexandrescu,Addison-Wesley,2001,352Paper


 Genericity/STL系列:

 第一个境界是使用STL:
  [Josuttis99]:The C++ Standard Library -A Tutorial and 
                  Reference,by Nicolai M.Josuttis,
                  Addison Wesley 1999.799pages

  第二个境界是了解泛型技术的内涵与STL的学理:
   [Austern98]:Generic Programming and the STL -Using and 
                  Extending the C++ Standard 
                  Template library,by Matthew H.Austern,Addison Wesley 
                  1998.548page


  第三个境界是扩充STL:
   [Stepanov2001]:C++ Standard Template Library by 
                  P.J.Plauger,Alexander A.Stepanov,
                  Meng Lee,David R.Musser,Prentice Hall 2001 

  这些就是你应该看的书,如果你想成为高手。

posted @ 2009-08-19 09:55 Voider 阅读(330) | 评论 (0)编辑 收藏

2008年9月7日

作者risc700
1, 简历上写着了解c++, 实际上不知道mfc 根 VC有什么区别. 0级
2, 简历上写着精通c++, 但是仅仅知道mfc, 认为VC就是C++的一切。 1级
3, 总是使用malloc,或者 char[100] 来获得内存,但不知道怎么在指定内存上面创建对象。 2级
4, 感觉std::string 没有 CString 好用! 听说过g++ 3级
5, 会使用std::string, 认为 "c/c++" 很不科学,完全就不是一个语言嘛. 知道4种以上c++ compiler. 感觉自己什么都会。 4级
6, 看山是山,看水是水。崇拜boost source code, 呕心沥血的研究经典库的代码. 感觉自己什么都不会。5级
7, 看山不是山,看水不是水。为自己钟情的函数库而奋斗着,恨不得用尽各种tricks 和 traits, 因为各种经典设计模式想得头疼. 稍有走火入魔迹象。 6级
8,看山仍然山,看水仍然是水。 看到每行代码,都是汇编的指令和内存数据的移动。 代码中几乎不出现for 和 while 关键字. 不停地否定自己的过去. 7级
9, 维护着g++,或者Watcom C++ 之类的项目,头发也比较长,有艺术家气质. 8级
10, 参与 C++ Standards Committee, 代表不同的利益集团发言. 9级
11, 彻底走火入魔, 成天幻想修改C++的语法, 添加自己的关键字, 重新实现一个C++的改进, 还想把c++变成脚本,解释执行.已经超越了利益. 10级.

C++的四层境界


1。程序员。
有时被称为蓝领,在C++开发小组扮演有用的角色,
但是遇到设计难题时,需要高级程序员指导


2。高级程序员
与普通程序员的区别是,能独立地解决大多数C++设计难题。
要达到这一层次需要至少经过三个复杂的C++PROJECT,并积累了一些设计失败的教

训。

经过努力,大多数C++编程人员都能达到这一高级程序员的境界。

3。一个公司里的GURU
也就是常说的一软件公司里的牛人,可称为一个公司里的GURU,
他们拿着相当高的薪水。,领导一个公司的技术设计。
这样的人需要十年以上OO的经验并经历多个大型软件成功和失败。


4。工业界的GURU

这样人在所在的领域如雷贯耳,几乎很少有公司能够雇得起他们。
他们通常经营着自己的咨询公司。达到境界4的GURU们,几乎在每天的空闲散步时间

里都在思考技术。

对大多数程序员来说,想达到他们的境界,是不现实的。


-------C++ FAQ
三位作者:
Cline : Internet offical Forum C++FAQ 主持人,给数千名C++工程师上过课,
计算机专业博士
Lomow: 高级机构设计师,15年OO开发经验,计算机专业博士
Girou: 国际C++标准委员会成员,数学专业博士
posted @ 2008-09-07 21:12 Voider 阅读(185) | 评论 (0)编辑 收藏
 
//file1.c
#include <stdio.h>

char ch[10];
//file2.c
#include <stdio.h>

extern char *ch;

int main()
{
  ch[0]=1; 
  return 0;
}
---------------------------------------
gcc file1.c file2.c -o ap
./ap
段错误
-----------------------------------------------
1,array vs pointer
file2,c ch[i]实际上得到的是一个字符,但编译器把它当成是一个指针,因为此文件中声明为指针
先取地址ch的内容,加上i,当作字符ch[i]的地址。实际上所谓的地址是ch[0]+i;
char ch[10]; 符号ch具有一个地址,ch[i],只需将i+ch具有的地址相加,再取其指向的内容
extern char *ch; ch[i],得到地址p的内容,把它加上i,再取所得地址指向的内容。
而事实上p指向的内容是ch[0]//one char.而非地址。

2.定义vs声明
定义只有一次,且分配内存,一种特殊的声明。
声明可多次,不分配内存。

3.编译器不为指针指向的对象分配空间,只是分配指针本身的空间。
除非在定义时赋一string初始化,且只可以是字符串常量。只读不可修改。
 char *p="Hello world";
  p[0]='h'; //段错误。


posted @ 2008-09-07 20:59 Voider 阅读(160) | 评论 (0)编辑 收藏
仅列出标题