- 博客(96)
- 资源 (16)
- 收藏
- 关注
原创 new contor 与 new contor()的区别
#include using namespace std;class default{private:int a;public:int geta() const { return a; }};int main(){default *p1 = new default;default *p2 = new default();cout << "p1 i
2010-01-25 21:37:00 672
原创 开始看重构的书
刚刚开始看,觉得重构中有几个点:持续的集成,small step, 完善的Unit Test等等。 首先,重构并不包治百病,有些项目限于时间,限于项目的组成等等,并不适合使用重构。重构是在不改变functional方面,改善代码的结构,改善代码的可读性等(具体可以去查看大牛们的书籍)。 (1)基础是有完善的Unit Test环境。如果希望进行持续的refactor,搭建一个完
2009-12-24 21:32:00 586
原创 汇编的hello world
调用linux system call.section .rodataoutput: .string "Hello, World/n".section .text.globl _start nop movl $4, %eax movl $1, %ebx movl $output, %ecx
2009-10-28 17:59:00 704
翻译 constructor和destructor概述(c++ only)
原文请参考http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=/com.ibm.xlcpp8l.doc/language/ref/cplr374.htmconstructor和destructor概述(c++ only)对象的初始化和清除比简单的数据结构复杂的多,这是因为类有比较复杂的内部
2009-10-28 14:36:00 14529
原创 一道简单点的面试题目
填写下面的代码void dec2hex(int c){ char hex[64] = {0}; printf("int %d, hex %s/n", c, hex);} 将int值按照16进制输出,可以使用%x转换void dec2hex(int c){ char hex[64] = {0}; if
2009-10-27 21:18:00 685
原创 汇编写的一个冒泡排序
.section .datavalues: .int 105, 235, 61, 315, 134, 221, 53, 145, 117, 5.section .text.globl _start_start: nop movl $values, %esi movl $9, %ecx movl $9, %ebxloop:
2009-10-26 16:13:00 1080
原创 函数名是个特殊的咚咚
函数名就是指针,但是&func得到的还是这个指针 有人会认为这是一个比较简单的东西,不过有时还是很容易弄混 在回答下面这个帖子的时候,我就弄混了http://topic.csdn.net/u/20091015/20/2242f1e9-2b86-4307-979e-ac6e7d60b596.html?35119 比如void function(void){/*
2009-10-15 21:35:00 518
转载 moto的18道C++面试题...
原帖子,看下面链接http://topic.csdn.net/u/20080720/11/a52179aa-b128-4686-bf64-fc138ab78e42.html jscn123789abc同学的问题请大家讨论一下:moto的18道C++面试题... 1.介绍一下STL,详细说明STL如何实现vector。 2.如果用VC开发程序,
2009-10-14 00:18:00 869
原创 在控制台画acos
/******************************************************************************* * /file acosline.c * /brief draw acos line on terminal * /date 10/11/2009 08:46:22 PM * /author CH
2009-10-12 23:17:00 522
原创 开始尝试使用valgrind
10/09/09 10:14:23 PM Magic刚刚看到csdn上面有个帖子在推荐里面,标题和地址如下:一段小代码,是否出现了野指针? 请大家发表一下对野指针理解!(希望能Show出代码)http://topic.csdn.net/u/20090208/20/122a108f-b8a0-4dfc-bdea-3206804b0ffb.html?87197如下于是我在自
2009-10-09 23:29:00 1231
原创 c++ primer 3rd 练习223 总结
template elemType miniter(const vector &vec) { elemType m = *vec.begin(); /* take care using const_iterator instead of non-const iterator */ typename vector::const_iterator iter = v
2009-09-29 16:47:00 550
原创 kmp算法理解(纯收集)
对kmp算法的理解可以参考Introduction to Algorithm 3rd Edition Chapter 32.4 如果没有这本书的同学,可以看看下面KMP-MATCHER(T, P) 1 n ← length[T] 2 m ← length[P] 3 π ← COMPUTE-PREFIX-FUNCTION(P) 4 q ← 0
2009-09-26 13:01:00 699
原创 ubuntu上面如何安装system/develop library的man page
也就是比如我们需要 man 3 fwrite,却提示没有的时候,可以使用下面的命令 $ sudo apt-get install manpages-dev 这样就可以使用了 实际上,对应自己使用的版本有下面几种可能manpages-dev, manpages-posix, manpages-posix-dev, freebsd-manpages./* 200
2009-09-25 15:45:00 1449
原创 (size_t)-1代表了什么
printf("(size_t)-1 is %d/n",(size_t)-1); 在我的ubuntu9.04上面,得到的结果是4294967294,对比中的宏UINT_MAX,可以发现这两个数字是相同的. 知道了上面的方法,如果要得到UINT_MAX - 1,可以使用(size_t)-2 实际上面,我这台机器(32位系统)使用补码表示数字的,-1在内存中实际就
2009-09-25 12:03:00 4915 1
翻译 【BASH】让你的脚本文档化
问题:介绍shell脚本或变量之前,先说下怎样使得你的脚本文档化。很明显,你可能需要几个月之后还能读懂你自己写的脚本。 解决方案:通过注释使得你的脚本文档化。#标识了一个注释的,该行#后所有的内容将被shell忽略。##This is a comment.##Use comments frequently.#Comments are y
2009-05-08 12:51:00 666
翻译 【BASH】脚本接触之shell变量
bash脚本编程跟其他的编程一样,都是有保存string/number的变量,这些变量可以用来赋值,比较,作为参数传递等。但是bash脚本中的变量有一些特殊的操作符可以方便你使用它们,同时bash提供一系列提供丰富信息的内嵌变量。接下去几天会看到的都是跟bash变量的使用相关。 通常情况,bash变量使用全大写名称,这不是强制的。变量不必像c语言中提前声明,哪里需要就可以在那里使用,
2009-05-07 14:56:00 2094
翻译 【BASH】运行目录下面的所有脚本
问题:你期望运行一系列的脚本,这些脚本名字不断变化,并且你总是不停的添加新的脚本,但是你不希望总是更改主脚本。 解决方案:将所有要运行的脚本放入同一个目录,让bash去运行。Bash去查找目录下的脚本而不是维护一个要运行的脚本的列表。forSCRIPT in /path/to/scripts/dir/*do if[ -f $SCRIPT -a -x
2009-05-06 12:56:00 1377
翻译 【BASH】通过变量运行命令
问题:你希望根据实际情况运行不同的命令,怎么去实现呢? 解决方案:有很多问题解决这个问题,这也是脚本要解决的。后面的章节中有很多的编程逻辑可以解决这个问题,比如if/then/else,case语句。FN=/tmp/x.xPROG=echo$PROG$FNPROG=cat$PROG$FN 讨论:我们可以将程序名赋给变量上面的例子是$PR
2009-05-05 15:07:00 2758
翻译 【BASH】出错时显示错误信息
问题:你期望你的脚本显示尽量多的错误提示信息。你期望在某个命令失败的时候看到错误信息,不过你不希望改变原有的脚本流程(ps.增加if判断) 解决方案:shell脚本程序员的一个惯用方法是使用||分隔命令和调试或错误信息,下面是一个例子:cmd|| printf "%b" "cmd failed. Youre on your own/n" 讨论:跟&
2009-04-30 13:26:00 2615
翻译 【BASH】非交互运行耗时长的任务
问题:你让工作在后台进行,并且退出shell去喝个咖啡,当你回来查看的时候,发现工作没有运行并且没有完成,实际上工作没有进行多少,跟你离开工作台的时候差不多。 解决方案:如果你希望在后台运行某个任务,并且在任务完成前退出shell,可以使用nohup命令:$nohup long &nohup:appending output to `nohup.out$
2009-04-29 13:30:00 887
翻译 【BASH】使用更少的if语句
问题:前面的问题,判断一个命令是否成功执行,如果每个命令都有一个if语句去判断,你会发现你的脚本很难阅读。那么思考一下,如果每个命令都要检查上个命令的返回值,是不是有其他简单的方案呢? 解决方案:使用bash提供的条件判断操作符&&$cd mytmp && rm * 讨论:用&&分隔的两个命令,首先执行第一个,当第一个成功执行之后才会执行第二个(e
2009-04-28 13:35:00 1331
翻译 【BASH】判断命令是否成功执行
问题:需要在成功执行某个命令之后执行一个命令。比如,你需要进入某个目录,删除其中所有的文件,但是如果cd命令失败,你就不去执行删除的动作(比如权限不允许,或者你把目录的名字输入错误) 解决方案:可以使用cd命令的返回值($?)并结合if语句进行判断。cdmytmpif(( $? )); then rm * ; fi 讨论:很明显,直接输入命令的时候
2009-04-27 13:08:00 14309
翻译 【BASH】同时执行多个命令
问题:需要执行三个程序,它们是独立的,不需要等待其他命令执行结束。 解决方案:在命令后放一个&,使得命令在后台运行。这样你可以用如下的方法同时执行这三个程序。$long &[1]4592$medium &[2]4593$short$更好的方法是把这几个命令放在同一行:$long & medium & short[
2009-04-24 13:26:00 20771
翻译 【BASH】顺序执行一系列的命令
<!-- @page { margin: 0.79in } P { margin-bottom: 0.08in } -->问题:你需要执行一系列的命令,有的命令执行需要一定的时间,而你却不想等待执行到最后一个再执行下个命令。 解决方案:有三个方案,不过第一个有些微不足道:justkeeptyping(不知道怎么翻译好,理解是在前面命令执行的
2009-04-23 13:40:00 4677
翻译 【BASH】检测命令执行的结果
问题:你需要知道所运行的命令是否成功 解决方案:如果命令失败shell变量$?会被置为非零值,命令或shell脚本的编写者可以建立下面的习惯$somecommanditworks...$echo $?0$badcommanditfails...$echo $?1$ 讨论:程序的exitstatus会被
2009-04-22 13:15:00 8273
翻译 【BASH】运行可行性文件
问题:需要在Linux或者Unix系统下执行某个程序。 解决方案:使用bash,在bash的提示符后敲入你要执行的命令。 讨论:这表面上看起来简单,但是简单的背后有一系列的事情是我们没有看到的。理解bash的重点就是要知道bash的基本操作就是加载和执行可执行程序。当然bash还有其他的成分,比如shell变量,控制语句(for,if/them/else),还有控
2009-04-21 14:32:00 3219
原创 添加小的命令行程序,提高工作效率
我发现最近经常进行的操作是在cpp,h文件中查找某个字符串,我使用下面的命令grep -w -l -i -r --include "*.cpp" --include "*.h" "string" .每次都要输入这么长的命令,实在是一件比较令人头痛的事情,懒惰的人就得想个办法解决一下 在windows目录下面写一个简单的批处理,自己添加一个小的命令grepcpp.bat
2009-04-21 10:42:00 514
翻译 【BAST】提示输入密码
问题:你希望提示用户输入密码,但是你不希望密码回显在屏幕上面。 解决方案:read -s -p"password: " PASSWDprintf "%b""/n" 讨论:-s选项告诉read不要回显用户输入,-p选项则是提示从用户处读取的输入保存到环境变量$PASSWORD中。紧随read,使用了printf来打印一个新行,因为read-s
2009-04-20 13:13:00 694
翻译 【BASH】如何从选项列表中选择
问题如何提供给用户选项列表,并且只有在必要的时候,用户才需要进行选择 解决方案使用bash内置的select命令来创建选项列表,用户通过对应的序号进行选择。#!/bin/bash#cookbook filename: select_dirdirectorylist="Finished $(ls/)"PS3=Directory to process?
2009-04-17 13:48:00 2006
翻译 【BASH】如何得到用户输入的YES或NO
<!-- @page { margin: 0.79in } P { margin-bottom: 0.08in } --> 问题:你需要从用户那里得到简单的yes或no的输入,并且你期望做到用户界面的友好,做到能够区分大小写,并且提供用户点击Enter的默认选项。 解决方案如果是简单的行为,可以使用下面这个函数。#cookbook file
2009-04-16 13:40:00 3988
翻译 【BASH】如何读取用户输入
<!-- @page { margin: 0.79in } P { margin-bottom: 0.08in }-->Bash脚本如何从用户处读取输入呢? 1.使用read命令2.或者read-p “answer me this “ ANSWER3.或者 readPRE MID POST 最简单的方式就是直接使用read命令
2009-04-15 13:18:00 17689
翻译 【BASH】如何避免Here-Document的奇怪行为
【BASH】如何避免Here-Document的奇怪行为 如果不了解Here-Document,请看bashman page中here-documents的部分,也可以看本文后面附录的在manpage 中截取的here-document说明。 如果您的Here-Document行为怪诞,比如您维护捐赠者的名单,并且创建了如下面这样的donor文件: $ cat
2009-04-14 14:51:00 2006
翻译 【BASH】从文件中取得输入
【BASH】从文件中取得输入如果你希望你的shell命令从文件中读取数据,请看下面的介绍使用输入重定向wc <my.file对比下>将输出重定向,那么理解就会比较简单了。很多shell命令会使用一个或者多个文件名作为参数,但是当没有给出文件名的时候会把标准输入作为输入那么使用command filename 或者command 会取得相同的效果典
2009-04-13 10:26:00 963
原创 【BASH】在设定了noclobber之后,如何强制覆盖现有文件
如果设定了noclobber,那么每次想要在重定向的时候覆盖现有文件改如何做呢? 使用>| 来重定向,因为即使没有设定noclobber,bash会忽略它,并且覆盖现有文件。 请看下面的例子$ echosomething > my.file$ set -onoclobber$ echo somemore >| my.file$ cat my.f
2009-04-10 10:01:00 1130
翻译 【BASH】如何防止在重定向时覆盖现有文件
【BASH】如何防止在重定向时覆盖现有文件 通常我们都不希望因为操作失误而错误的删除文件,但在使用重定向保存结果的时候却很容易出现这种情况。那么如何解决呢? 通过shell通过设定bash的选项noclobber,在默认的情况下,这个选项是打开的set -onoclobber noclobber这个选项告诉bash在重定向的时候不要覆盖已有文件。
2009-04-09 14:31:00 1458
转载 Howto: Ubuntu install From USB
原帖地址http://www.teamteabag.com/2008/05/17/howto-easy-install-ubuntu-804-hardy-heron-or-most-other-distros-from-usb/防止找不到HOWTO: Ubuntu Install From USB - Works For Other Linux Too!Author: Rees |
2009-04-08 23:15:00 1698
原创 如何在windows批处理中添加自定义函数
@echo offcall :helloworld helloworldgoto :EOF:helloworldsetlocalecho %1endlocal&goto :EOF 上面就是简单的helloword 可以看到自定义函数也是一个label,不过label的开头是 setlocal 结尾为 endlocal&goto :EOF
2009-04-08 00:16:00 7254 6
原创 求两个整型数字的最大公约数问题
Question给出两个正的整型数字,m和n,求它们的最大公约数 Euclid Algorithm第一步: 假设m>n,m除以n得到的余数为r第二步: 如果r=0,那么n就是最大公约数,结束,否则第三步第三步: m #include #include #include struct testSuit { unsigned int ma
2009-03-31 22:45:00 911
转载 15条 linux Find 命令实际使用方法
This article is written by SathiyaMoorthy作者: SathiyaMoorthy Apart from the basic operation of looking for files under a directory structure, you can also perform several practical operations using f
2009-03-17 23:07:00 7596 1
原创 练习 3.16 删除一组数据中的相同数据
假设我们有一个基于数组的表A[0..N-1],并且我们想删除所有相同的元素给出一个算法以O(Nlog(N))解决该问题。1. 题目给出的引子2. 目前我的方法下面是题目中给出的引子for (i = 0; i < LastPostion; i++){ j = i + 1; while( j < LastPostion) if ( A
2009-01-14 13:30:00 964
C.Plus.Plus.Template.Metaprogramming.
2012-06-18
o'reilly - perl testing - a developer's notebook (2006).chm
2009-04-14
Addison.Wesley.xUnit.Test.Patterns.Refactoring.Test.Code.May.2007.pdf
2009-04-04
Compilers:Principles, Techniques, and Tools
2008-10-05
Compilers:Principles, Techniques, and Tools
2008-10-05
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人