白衣如雪
我们孤独,我们并肩
makefile中自动生成对头文件的依赖
一个目标文件经常依赖很多的头文件,且经常会有#inculde语句的添加与删除.
这样每次加了include后,还得改makefile. 这一步可以自动化, make的文档里有提到
从文档里提取的规则:
%.d: %.c
@set -e; rm -f $@; \
$(CC) -M $(CPPFLAGS) $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
gcc的-M选项:
[tangyi@search043040.sqa.cm4 src]$ gcc -M object.c
object.o: object.c redis.h fmacros.h config.h /usr/include/stdio.h \
/usr/include/features.h /usr/include/sys/cdefs.h \
/usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \
/usr/include/gnu/stubs-64.h \
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/stddef.h \
/usr/include/bits/types.h /usr/include/bits/typesizes.h \
object.d : object.c
经过sed处理一下会生成的规则:
object.o object.d : object.c redis.h fmacros.h config.h /usr/include/stdio.h \
/usr/include/features.h /usr/include/sys/cdefs.h \
/usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \
/usr/include/gnu/stubs-64.h \
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/stddef.h \
/usr/include/bits/types.h /usr/include/bits/typesizes.h \
lcp链式拷贝
位置: /home/admin/asearch/bin/lcp.sh
用来分发builder建好的索引.
usage:
调用时,最后一个0是没有用到的.
用时注意: "$list"里已经没有本机了,不然会出现给本机多传一次.
flag的意思表明本进程是发起进程,不用做跳过的判断.注意在递归调用lcp时,在最后有一
个&,是放到后台的.
假设A上有一个文件file,要从A传到B,再传到C, 再从C到D. A会先传给B,如果失败,则向
C传. 假设成功. 然后ssh调用B上的lcp(后台执行). 执行到同样的循环,先跳过前面所有
已经传过的机器,向排在自己后面的一个机器(C)传file, 再ssh到C, 调用lcp,如此循环下
去.
用来分发builder建好的索引.
usage:
for file in $file_list do $BASE_HOME/bin/lcp.sh "$list" $AUCTION_DIR/index/$file $DEST_HOME/rundata/auction/index.0/$file 1 0 done
调用时,最后一个0是没有用到的.
用时注意: "$list"里已经没有本机了,不然会出现给本机多传一次.
主要代码
for server in $server_list do if [ $flag -eq 1 ]; then echo "==== scp $hostn:$src_file => $server:$dest_file =====" scp -p -o ConnectTimeout=5 $src_file $server:$dest_file >/dev/null 2>&1 0>&1 ret=$? if [ $ret -ne 0 ]; then echo "SCP失败: $hostn:$src_file => $server:$dest_file" writeLog "SCP失败: $hostn:$src_file => $server:$dest_file" continue; fi ssh -o ConnectTimeout=5 $server "$DEST_HOME/bin/lcp.sh '$server_list' $dest_file" >/dev/null 2>&1 0>&1 & pid=$! echo $pid >> $DEST_HOME/logs/lcp.pid break; fi if [ $hostn == $server ]; then flag=1 fi done
flag的意思表明本进程是发起进程,不用做跳过的判断.注意在递归调用lcp时,在最后有一
个&,是放到后台的.
假设A上有一个文件file,要从A传到B,再传到C, 再从C到D. A会先传给B,如果失败,则向
C传. 假设成功. 然后ssh调用B上的lcp(后台执行). 执行到同样的循环,先跳过前面所有
已经传过的机器,向排在自己后面的一个机器(C)传file, 再ssh到C, 调用lcp,如此循环下
去.
Makefile里命令解释及转义
新安装的 org-mode 7.5有一个warnings.
故想uninstall之,没想到没有make uninstall.
自己添加了一个.
install规则是:
install: install-lisp
doc: doc/org.html doc/org.pdf doc/orgcard.pdf doc/orgcard_letter.pdf doc/orgguide.pdf doc/orgcard.txt
p:
${MAKE} pdf && open doc/org.pdf
g:
${MAKE} pdf && open doc/orgguide.pdf
install-lisp: $(LISPFILES) $(ELCFILES)
if [ ! -d $(lispdir) ]; then $(MKDIR) $(lispdir); else true; fi ;
$(CP) $(LISPFILES) $(lispdir)
$(CP) $(ELCFILES) $(lispdir)
照样写一个uninstall:
uninstall: uninstall1 uninstall2
uninstall1:
for f in $(LISPFILES); do \
if [ -f $(lispdir)/`basename $$f` ]; then rm $(lispdir)/`basename $$f`; fi;\
done
uninstall2:
for f in $(ELCFILES); do \
if [ -f $(lispdir)/`basename $$f` ]; then rm $(lispdir)/`basename $$f`; fi;\
done
故想uninstall之,没想到没有make uninstall.
自己添加了一个.
install规则是:
install: install-lisp
doc: doc/org.html doc/org.pdf doc/orgcard.pdf doc/orgcard_letter.pdf doc/orgguide.pdf doc/orgcard.txt
p:
${MAKE} pdf && open doc/org.pdf
g:
${MAKE} pdf && open doc/orgguide.pdf
install-lisp: $(LISPFILES) $(ELCFILES)
if [ ! -d $(lispdir) ]; then $(MKDIR) $(lispdir); else true; fi ;
$(CP) $(LISPFILES) $(lispdir)
$(CP) $(ELCFILES) $(lispdir)
照样写一个uninstall:
uninstall: uninstall1 uninstall2
uninstall1:
for f in $(LISPFILES); do \
if [ -f $(lispdir)/`basename $$f` ]; then rm $(lispdir)/`basename $$f`; fi;\
done
uninstall2:
for f in $(ELCFILES); do \
if [ -f $(lispdir)/`basename $$f` ]; then rm $(lispdir)/`basename $$f`; fi;\
done
注意看是 $$f, 这是为了转义$符号.
具体的要翻文档了.
bash命令行的执行过程
~$ name=ngn echo $name
这个不能输出ngn,而只是一个空行.
翻bash的手册找到这么一段:
3.7.1
When a simple command is executed, the shell performs the following expansions, assignments, and redirections, from left to right.
这个不能输出ngn,而只是一个空行.
翻bash的手册找到这么一段:
3.7.1
When a simple command is executed, the shell performs the following expansions, assignments, and redirections, from left to right.
- The words that the parser has marked as variable assignments (those preceding the command name) and redirections are saved for later processing.
- The words that are not variable assignments or redirections are expanded (see Shell Expansions). If any words remain after expansion, the first word is taken to be the name of the command and the remaining words are the arguments.
- Redirections are performed as described above (see Redirections).
- The text after the ‘=’ in each variable assignment undergoes tilde expansion, parameter expansion, command substitution, arithmetic expansion, and quote removal before being assigned to the variable.
原来echo的参数 $name 在 name=ngn 这个赋值之前就已经被扩展了.这时自然是空了.所以不会输出内容.
验证:
~$ name=ngn perl -e 'print $ENV{name}'
ngn
~$
sicp 1.16的答案
看了sipc前面一两节, 主要就明白了迭代和循环的不同.
习题1.16
Design a procedure that evolves an iterative exponentiation process that uses successive squaring and uses a logarithmic number of steps, as does fast-expt. (Hint: Using the observation that (bn/2)2 = (b2)n/2, keep, along with the exponent n and the base b, an additional state variable a, and define the state transformation in such a way that the product a bn is unchanged from state to state. At the beginning of the process a is taken to be 1, and the answer is given by the value of a at the end of the process. In general, the technique of defining an invariant quantity that remains unchanged from state to state is a powerful way to think about the design of iterative algorithms.)
用迭代实现的一个exp
(define square
(lambda (x)
(* x x)))
(define exp-iter
(lambda (base n product)
(cond ((= n 0) product)
((even? n) (exp-iter (square base) (/ n 2) product))
(else (* base (exp-iter base (- n 1) product))))))
(define exp2
(lambda (base n)
(exp-iter base n 1)))
(exp2 2 10)
sicp在线版本
习题1.16
Design a procedure that evolves an iterative exponentiation process that uses successive squaring and uses a logarithmic number of steps, as does fast-expt. (Hint: Using the observation that (bn/2)2 = (b2)n/2, keep, along with the exponent n and the base b, an additional state variable a, and define the state transformation in such a way that the product a bn is unchanged from state to state. At the beginning of the process a is taken to be 1, and the answer is given by the value of a at the end of the process. In general, the technique of defining an invariant quantity that remains unchanged from state to state is a powerful way to think about the design of iterative algorithms.)
用迭代实现的一个exp
(define square
(lambda (x)
(* x x)))
(define exp-iter
(lambda (base n product)
(cond ((= n 0) product)
((even? n) (exp-iter (square base) (/ n 2) product))
(else (* base (exp-iter base (- n 1) product))))))
(define exp2
(lambda (base n)
(exp-iter base n 1)))
(exp2 2 10)
sicp在线版本
core war的一些笔记
core war的wiki页: core war
大学里看过这游戏, 忘得差不多了. 做一个备忘.
Mars的特点
1. 地址是循环的, 就是一个Ring.
假设内存大小是8000的话,则第一个内存的地址是0,最后一个是7999,它的下一个又是0.
2.没有绝对地址,只有相对地址.
当前指令的地址是0,下一个是1,前面一个单位的地址是-1.
3. 存储的最小单位不是Byte,而是指令.
Mars里,所有指令的大小都是1.
4. Mars是多任务的
Mars内部有一个pqueue (process queue).
一个进程可以SPL(fork). eg. A战士有3个进程A1,A2,A3,了只有一个B1
则在pqueue的排列是 A1 B1 A2 B1 A3 B1 ...
5. 传统的Mars初始时每一个内存都是DAT #0,#0
6.胜负条件是有一方所有进程退出.
程序执行了非法指令(DAT)会退出.
Redcode的语法
label opr A field, B field.
寻址方式
1. 立即寻址 #.
MOV #7, 1
将7(数字)移动到下一条指令的B field.
2. 直接寻址, $, ($可以省略)
MOV 0, 1
将本条指令(整个) copy到下一个位置
3. A Field 间接寻址*
同B Field间接寻址.
4. B Field间接寻址 @
DAT #0, #4
MOV 0, @-1 (下一条要执行的语句)
将当前指令copy到后面第4条指令的位置.
5.
这个同间接寻址, 只是在这之前会先把算出来的地址减1, 同时本身减1. (没讲清楚,看下面的链接)
6. 还有3个与<类似的寻址方式
>,{,}
redcode的经典文章: http://vyznev.net/corewar/guide.html
Example
1. imp
最经典的战士,只有一行:
;name imp
;assert 1
MOV 0, 1
很好懂, 将自身copy到下一个指令, 如此循环下去. 没有攻击性,除非其它战士执行非法指令退出.
杀伤力为0.
2. Gate
专门针对上面说到的imp
;name gate
;strategy ...
gate EQU wait - 10
wait JMP 0, <gate
END wait
EQU和END是宏指令, 不是真的redcode.
END表明程序从wait开始.
JMP 0, <gate的意思是程序一直跳到当前行, 同时将-10的B Field减1.
当imp来到gate时, 会被变成 MOV 0, 0 imp执行MOV 0,0后,会执行下一个非法的指令而退出.
MOV 0, 0
DAT #0, #0
redcode集锦: http://www.koth.org/planar/by-date/idx.htm
指令集
DAT 存放数据用的.
MOV
ADD,SUB,MOD,MUL,DIV
JMP, JMN, JMZ,SPL
大学里看过这游戏, 忘得差不多了. 做一个备忘.
Mars的特点
1. 地址是循环的, 就是一个Ring.
假设内存大小是8000的话,则第一个内存的地址是0,最后一个是7999,它的下一个又是0.
2.没有绝对地址,只有相对地址.
当前指令的地址是0,下一个是1,前面一个单位的地址是-1.
3. 存储的最小单位不是Byte,而是指令.
Mars里,所有指令的大小都是1.
4. Mars是多任务的
Mars内部有一个pqueue (process queue).
一个进程可以SPL(fork). eg. A战士有3个进程A1,A2,A3,了只有一个B1
则在pqueue的排列是 A1 B1 A2 B1 A3 B1 ...
5. 传统的Mars初始时每一个内存都是DAT #0,#0
6.胜负条件是有一方所有进程退出.
程序执行了非法指令(DAT)会退出.
Redcode的语法
label opr A field, B field.
寻址方式
1. 立即寻址 #.
MOV #7, 1
将7(数字)移动到下一条指令的B field.
2. 直接寻址, $, ($可以省略)
MOV 0, 1
将本条指令(整个) copy到下一个位置
3. A Field 间接寻址*
同B Field间接寻址.
4. B Field间接寻址 @
DAT #0, #4
MOV 0, @-1 (下一条要执行的语句)
将当前指令copy到后面第4条指令的位置.
5.
< -- B-field indirect with predecrement这个同间接寻址, 只是在这之前会先把算出来的地址减1, 同时本身减1. (没讲清楚,看下面的链接)
6. 还有3个与<类似的寻址方式
>,{,}
redcode的经典文章: http://vyznev.net/corewar/guide.html
Example
1. imp
最经典的战士,只有一行:
;name imp
;assert 1
MOV 0, 1
很好懂, 将自身copy到下一个指令, 如此循环下去. 没有攻击性,除非其它战士执行非法指令退出.
杀伤力为0.
2. Gate
专门针对上面说到的imp
;name gate
;strategy ...
gate EQU wait - 10
wait JMP 0, <gate
END wait
EQU和END是宏指令, 不是真的redcode.
END表明程序从wait开始.
JMP 0, <gate的意思是程序一直跳到当前行, 同时将-10的B Field减1.
当imp来到gate时, 会被变成 MOV 0, 0 imp执行MOV 0,0后,会执行下一个非法的指令而退出.
MOV 0, 0
DAT #0, #0
redcode集锦: http://www.koth.org/planar/by-date/idx.htm
指令集
DAT 存放数据用的.
MOV
ADD,SUB,MOD,MUL,DIV
JMP, JMN, JMZ,SPL
悲从中来 -- 我的一年陈
去年的今天正式离开学校从武昌去南昌,在爸爸妈妈哪里呆了2天后,坐D95到杭州,赶着来百淘, 7月1号正式入职. 想一想,一年了,而一切晃如隔日.
周五时,百淘4期waka队的10来号人聚了一下,因为有段时间没有一起吃饭了,又因为梅锷即将要离职了.一般这种聚会,吃饭不是重要的,重要的叙叙旧.从6点多吃到了9点多.
从金秋园出来时,巴真.钱树和我一起朝回走,回各自的办公地点. 一路上钱树和我俩了很多. 谈了一些她为什么跳去兄弟公司,谈得更多的是如何做事. 其中有几点对我触动很大. 1. 和老大的关系就像谈恋爱 2. 你可以抄了你的boss
3. 从小事做起,小事也可以做出不一样,可以做精彩.
在她想换工作时,面试了很多公司,但有一半是在第一面就拒了她的,她分析是和公司不match,另一方面她觉得反正要换工作了,不防多试几家,也好见识见识.
听了钱树的一番话后,再想想现在的自己, 觉得这一年来是白过了, 成长不大, 钱没存的, 就连手机都换不起, 一起进来的,就我没有换手机吧, 混得最惨了. 女朋友都没影子.
周日早上老爸打电话来, 语重心长地和我说了好多, 问我年初到现在存了多少钱, 这个我都没敢和他说清楚...又担心我的工作,担心我的身体,认为我不能照顾好自己, 担心我找女朋友的事, 担心我过多的和同事聚会,乱花钱.让我有时间和家里打打电话.
想想家人期待的眼神, 再看现在的自己, 不禁悲从中来~
CC Mode
一、CC Mode的几个概念
三、缩进的原理
分两步:
五、有用的交互式的按键
在看wget的代码的时候有些别扭,缩进是2个空格,if语句要这样写:
if ( a > b)
{
return a;
}
{,}都也是缩进了2个空格.
1. 最基本的设置 c-basic-offset
定义了缩进一级的大小,即符号+,-在c-offset-alist中代表的数量.
在wget代码里,要设置:
(setq c-basic-offset 2)
2.
- Clean-Ups
"Clean-ups" are mechanisms which remove (or exceptionally, add)
whitespace in specific circumstances and are complementary to colon and
brace hanging. You enable a clean-up by adding its symbol into
`c-cleanup-list', e.g. like this:
(add-to-list 'c-cleanup-list 'space-before-funcall)
一些clean-up要在启用了auto-newline minor mode的情况下才能生效,另外一些总是有效. - Line-Up
The most flexible way to customize indentation is by writing custom
line-up functions, and associating them with specific syntactic symbols
(*note c-offsets-alist::).
google-c-style.el里定义了一个line-up函数.
如何自己写一个Line-up函数:http://www.gnu.org/software/emacs/manual/html_mono/ccmode.html#Custom-Line_002dUp - Fill 与 Breaking
- c-basic-offset
- c-cleanup-list
- c-offsets-alist
很重要的一个变量,关联的值可以是一个int,一个函数,lambda表达式(参见lineup部分),或者+,++,-,--,/
三、缩进的原理
分两步:
- 分析当前行的语法符号
- 去c-offsets-alist查找该符号的offset
五、有用的交互式的按键
- C-c C-s 显示当前行的语法符号,和缩进的基准point.
- C-c C-o 交互式的设置缩进.
在看wget的代码的时候有些别扭,缩进是2个空格,if语句要这样写:
if ( a > b)
{
return a;
}
{,}都也是缩进了2个空格.
1. 最基本的设置 c-basic-offset
定义了缩进一级的大小,即符号+,-在c-offset-alist中代表的数量.
在wget代码里,要设置:
(setq c-basic-offset 2)
2.
babel的设置
;;; babel.el --- interface to web translation services such as Babelfish
不是每个人都像北飞一样过了6级 :P . 像我这种刚过cet4的, 还是有很多单词是不认识滴,关键时候还得翻译一下.
经常在emacs里看man pages,info之类的文档的时候,有不认识的单词,这个时候,复制去词霸什么的里去翻译,费时费力, 不爽.
babel就是在emacs里调用google translate这类翻译服务的接口.只是用起来有些不方便.
加了个babel-word函数.
写了个babel-word函数,让babel调用google去翻译光标下的英文. 默认的babel函数太难用了, 让我输入要翻译的词, 选择from,选择to,还要选择服务. #emacs# #bable.el#
;;;
(defun babel-word ()
"translate word under cursor use a web service, use preferred settings"
(interactive)
(let (
(word (thing-at-point 'word))
)
(if word
(babel word nil t))))
最后,babel的开发主页: https://github.com/juergenhoetzel/babel/blob/master/babel.el
最后的最后, 用firefox的话,inline translater这个插件很给力. 最大的特色: 可以翻译local文件里的单词. 另外, 支持语种多, 使用方便.
不是每个人都像北飞一样过了6级 :P . 像我这种刚过cet4的, 还是有很多单词是不认识滴,关键时候还得翻译一下.
经常在emacs里看man pages,info之类的文档的时候,有不认识的单词,这个时候,复制去词霸什么的里去翻译,费时费力, 不爽.
babel就是在emacs里调用google translate这类翻译服务的接口.只是用起来有些不方便.
加了个babel-word函数.
写了个babel-word函数,让babel调用google去翻译光标下的英文. 默认的babel函数太难用了, 让我输入要翻译的词, 选择from,选择to,还要选择服务. #emacs# #bable.el#
;;;
(defun babel-word ()
"translate word under cursor use a web service, use preferred settings"
(interactive)
(let (
(word (thing-at-point 'word))
)
(if word
(babel word nil t))))
最后,babel的开发主页: https://github.com/juergenhoetzel/babel/blob/master/babel.el
最后的最后, 用firefox的话,inline translater这个插件很给力. 最大的特色: 可以翻译local文件里的单词. 另外, 支持语种多, 使用方便.
using cscope with GNU Emacs
遇到一个问题:
-q cscope: -q option mismatch between command line and old symbol database.
cscope: removed files cscope.po.out and cscope.in.out
google后无果, 直接用cscope提供的interface也是同样的, 发现在建索引的时候如果用了,-q选项, 在查的时候不加,就会把这两个文件删掉.
ok,现在的问题是如何让xemacs.el在调cscope的时候加上-q选项, 直接看xcscope.el, 文档很丰富的,说得也很明白. 要setq cscope-database-regexps变量, 这里可以指定一个项目源代码对应的cross-reference database所在目录, 以及调用cscope时的参数.
现在的设置:
(setq cscope-database-regexps
'(
("^/home/tangyi/program/cc/freebsd8/"
(t ("-q" "-d"))
t
)
("^/home/tangyi/program/cc/nginx-0.8.54/"
(t ("-q" "-d"))
t
)
))
指定-d参数可以让调用时不更新database,在浏览代码时,一般只是加些注释,不会加新的变量,函数,也就是不会更新tag.
btw, 在大项目里加-q很有必要,会建倒排索引,速度快不少.
-q cscope: -q option mismatch between command line and old symbol database.
cscope: removed files cscope.po.out and cscope.in.out
google后无果, 直接用cscope提供的interface也是同样的, 发现在建索引的时候如果用了,-q选项, 在查的时候不加,就会把这两个文件删掉.
ok,现在的问题是如何让xemacs.el在调cscope的时候加上-q选项, 直接看xcscope.el, 文档很丰富的,说得也很明白. 要setq cscope-database-regexps变量, 这里可以指定一个项目源代码对应的cross-reference database所在目录, 以及调用cscope时的参数.
现在的设置:
(setq cscope-database-regexps
'(
("^/home/tangyi/program/cc/freebsd8/"
(t ("-q" "-d"))
t
)
("^/home/tangyi/program/cc/nginx-0.8.54/"
(t ("-q" "-d"))
t
)
))
指定-d参数可以让调用时不更新database,在浏览代码时,一般只是加些注释,不会加新的变量,函数,也就是不会更新tag.
btw, 在大项目里加-q很有必要,会建倒排索引,速度快不少.
订阅:
博文 (Atom)