随笔 - 60  文章 - 5  trackbacks - 0
<2024年12月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

常用链接

留言簿(2)

随笔分类(42)

随笔档案(60)

文章档案(2)

我收藏的博客

搜索

  •  

最新评论

阅读排行榜

评论排行榜

the formulation of a problem is often more essential than its solution,which may be merely a matter of mathematical or experimental skill.
爱因斯坦,提出一个问题往往比解决一个问题更重要。
posted @ 2012-01-04 16:06 黄剑父 阅读(175) | 评论 (0)编辑 收藏
一、tcmalloc
1、tcmalloc是什么?
2、安装tcmalloc

二、mysql
1、mysql的编译

2、把tcmalloc编译到mysql中

三、memcache
1、memcache是什么?
2、安装memcache
posted @ 2011-11-22 08:52 黄剑父 阅读(273) | 评论 (0)编辑 收藏
官网地址:http://scratch.mit.edu
Scratch是一种计算机编程语言,利用它可轻松地创建自己的互动故事,动画,游戏,音乐和艺术- 和在网络上分享你的作品。 当学生创建和共享自己的Scratch动画时,他们能学习到重要的数学和计算知识,同时也得到创造性的思考,系统推理,和协同工作的机会。

为什么要用Scratch学习编程?
1、Scratch上手非常容易,适于8岁以上孩子,成人也可以玩。积木,我想大多数人应该有玩过吧,没实际玩过至少也听说过吧。用Scratch编程就像玩积木一样,非常简单,把像一个个积木一样的脚本命令,按照一定的逻辑堆积起来,就可以做出自己的动画或游戏了。有图才有真相,各位看官请先看图。


2、Scratch简单,但能做很多事。你可以到官网看看一些优秀的作品,就知道Scratch能做些什么呢。
3、Scratch虽然不用你去敲代码,但它同其它计算机语言的编程思想是完全一样的,和C,C++,Java的编程思想没什么两样。如果你懂C、C++或Java,那些堆积起来的脚本,也是可以翻译成C、C++、Java代码的,并且非常简单,绝对要比英语翻译简单很多很多。
4、Scratch是免费的,可以在Mac,Windows和Linux上运行,并且软件的语言是可以设置,不懂英文也不要怕,可以把软件界面语言设置为简体中文。官网的站点也有中文的版面。
5、网站的用户参与度非常高,用户可以上传自己的作品到该网站,可以欣赏其他用户的作品,看到喜欢的也可以下载下来研究研究,当然也可以用到自己的作品中哦。

Scratch的一些统计数据,从其中你就可以看出此软件有多优秀,看过之后是否选择此编程语言做为自己的入门语言,那就看你的了。
第一幅图:scratch网站的访问者都来自哪些城市
scratch网站的访问者都来自哪些城市

第二幅图:scratch网站的注册用户年龄分布图(蓝色代表男性,红色代表女性)
scratch网站的注册用户年龄分布图
posted @ 2011-10-24 14:54 黄剑父 阅读(2948) | 评论 (1)编辑 收藏

原文地址:http://www.cprogramming.com/whyc.html

为什么学习C

Why Learn C?

现在大家在用的计算机语言的数量多得可怕。从高级语言(比如VB)到低级语言,有非常多的选择(Perl,Ruby和Python语言,对于很多任务的实现都是不错的选择)。Java已经成为了一些项目非常受欢迎的语言,某种程度上也是因为它拥有大量的API和虚拟机机制提供了比较好的安全性。(内存垃圾收集器也是一个非常不错的功能,可以使得程序员更有效率。)
There are an awful lot of programming languages available right now -- everything from the extremely high level (such as Visual Basic) to the low level power of assembly, and a good variety of specialized options in between (Perl, Ruby, and Python are good choices for many tasks). Java has also become quite the hot programming language for some tasks, in part because of its large API and in part because the virtual machine provides some elements of security. (Garbage collection is another nice feature and can make programmers much more efficient.)
然而,学习c语言编程,也有很多很好的理由。第一,历史悠久:C语言已有30多年的历史了(译者注:到现在已有近40年了),能找到大量的有效的源代码。这也意味着有很多可以学习的例子,也有很多是可以直接拿来用的代码。而且,语言的很多问题都已经说明的很清楚--它可以更好的理解,并且你可以找到很多很不错的教程。另外,对于C,你可以获得很多你能理解的看法和见解。
Nevertheless, there are some good reasons to learn to program in C. First, age has its advantages: C has been around for 30 years, and there is a ton of source code available. This means there's a lot to learn from, and a lot to use. Moreover, many of the issues with the language have been clearly elucidated -- it's well understood, and you can find a lot of tutorials available. Plus, with C, you get lots of strong opinions mixed with insights that you can understand.

由于历史的原因,C做为Unix的一个系统编程语言,C已经成为了一门通用的编程语言。有时候用C语言来表达一些编程上的想法,大部分人都会感觉到比较舒服。
As a result of its age and its use as the language of system programming for Unix, C has become something of the lingua franca of programming. C is a great language for expressing common ideas in programming in a way that most people are comfortable with. Moreover, a lot of the principles used in C -- for instance, argc and argv for command line parameters, as well as loop constructs and variable types -- will show up in a lot of other languages you learn so you'll be able to talk to people even if they don't know C in a way that's common to both of you.

第三,C是比较接近机器语言。
Third, C is reasonably close to the machine. When you're working with pointers, bytes, and individual bits, things like optimization techniques start to make a lot more sense. There's also utility in knowing exactly how something works underneath the hood -- this helps a great deal when something you're trying to do in a higher level language seems way slower than expected, or just doesn't work at all. You also tend to get a better picture of advanced topics like exactly how networking works. A higher level language will make it a little bit simpler, but it'll be harder to understand what's going on, and when things stop working, it's much better to know exactly what's going on so you can fix it. Additionally, if you like computer science as a discipline, or just like knowing how things work learning the details of the system is great fun.

实际上,很多有趣的编程都可以用C来做--比如,系统软件和数据管理系统(Berkeley DB)。如果你想写一个比较复杂的web程序,C也是一个很不错的选择。如果你想写一个非常好的,快的,C也是很好的选择。你可以用C来写整个操作系统,想用Java来做这个事情是非常难的,对于脚本语言来说是几乎不可能的。而且C是一门非常简洁精炼的语言,它使得非常有趣的编程看起来更优雅,你的编程之旅将会有一个很好的开始。
In fact, a lot of fun programming is done in C -- for instance, system software and data managers such as Berkeley DB. If you want to be able to do more than write a simple web app, C is a great language. If you want to write a great, fast game, C is again a great choice. You can write an entire OS in C. It'll be much harder to do so in Java, and nearly impossible in a scripting language. And the language, being succinct as C is, will probably make your fun program more elegant looking to boot.


我对于这篇文章所谈的话题,想补充几点。
1、学好C,可以帮助理解其他语言中的一些概念。
比如Java中的引用的概念,如果理解了C语言中的指针的概念,就能很好的理解“引用”这个概念了,而不理解指针的概念想把引用的概念理解的很透彻,是比较难的。

2、学会了C语言,再学习其他语言会感觉到更轻松。
Object-C,Java,C++等等很多高级语言的语法都与C是相似的。学会了C后,基本上只要花上一周的时间了解一下其他语言的特性,就基本上可以看懂其他语言的源代码了。

3、从现实角度来考虑,学好C,找到一份好工作的可能性也是大大增强,特别是对于刚毕业的大学生,或工作经验比较少的程序员。现在需要有C语言基础,擅长于C语言的,工作岗位也是比较多。比如拿现在非常流行的iPhone,iPad等设备的应用程序,开发语言就是Objective-C语言。Objective-C是苹果Mac OS X、iOS平台的开发语言,Objective-C是基于C语言的,增加面向对象的相关特性。你可以认为Objective-C就是另一个版本的C++,也就是采用了与C++不同的语法,但也实现了面向对象。你有了C语言的基础,再学Objective,难度就不大了。
你可以到那些招聘网站去看看,查查iPhone相关的开发工程师的要求,是不是很多都要求有C/C++的基础和经验。
还有一些系统开发和底层比较相关的,很多都是需要用C语言开发的。拿信息安全行业来讲,很多安全产品都是用C语言来开发的。还有游戏行业很多都是用C或C++。

还有一点,很多初学者认为学习C很难。其实我想说的是难并不是计算机语言的问题,难的是因为你用计算机解问题的思维还没建立起来。因为你进入的是一个新的领域,以前没有接触过计算机编程,对于怎么用计算机来解决现实中的问题的这种思维你还没有建立起来,毕竟用计算机解题的思维,和用数学解题的思维还是有些不一样的,所以你会觉得学习C语言很难。
如果你在学习C语言的同时,再进行一些程序员的思维训练,我觉得情况就会大有改善。
posted @ 2011-10-20 17:07 黄剑父 阅读(2603) | 评论 (1)编辑 收藏
Over the past decade-and-a-half of teaching introductory computer programming I have noticed increasingly that students have difficulty with solving problems. It is common to see learners read a programming problem description  and immediately try to write the programming language source code (usually whilst sitting at a PC typing straight into the editing window of the compiler environment). When they ask for help it is often the case that their difficulty lies not with manipulating the programming language syntax (C, Pascal, Java, or whatever) but in understanding what it is they're trying to solve. In fact, many times they confuse their syntax-handling difficulties with their problem-solving difficulties and blame their frustration on programming itself or on the chosen programming language. Some of them then become so downhearted that they decide they cannot do computer programming and transfer to a course that doesn't require them to study it.

这个话题挺有意思,我看了他的练习题,还真不错,有时候觉得。算法和计算机的语言的学习应该是有另外一种方式。
换句话说,在深入学习语言和算法,可以先来一碟开胃菜。
网站地址:
http://www.howtothinklikeaprogrammer.com/forum/index.php
书名是:《How to Think Like a Programmer: Program Design Solutions for the Bewildered》By Paul Vickers。
posted @ 2011-10-19 23:03 黄剑父 阅读(1977) | 评论 (0)编辑 收藏
原文:http://www.cprogramming.com/tutorial/thinking.html
很多人通过Email问我,怎样开始写一个程序。也许最好的建议非常简单,把程序的步骤写下来:一旦你开始把想法或者代码写下来后,你就会对你的项目有一些感觉了。通常程序设计有两种通用的做法:从上到下的方式和从下到上的方式。
A lot of people email me asking the way to start some program or another. Perhaps the best advice is simply to start writing down a layout for the program: once you start writing down ideas or code you'll start to get a feel for your project. There are two standard methods of program design: the top-down approach and the bottom-up approach. Top-down programming involves writing code that calls functions you haven't defined and working through the general algorithm before writing the functions that do the processing. Top-down programming is, to a good degree, a very abstract way of writing code because it starts out by using functions you haven't designed, and that you perhaps do not know how to design. The bottom-up approach to programming is the opposite: the programmer writes the basic functions she realizes will be necessary at some point in the programming and then work up to the more complex parts of the program.

比较有意思的是,那两种方法都是关注程序中要执行的动作或方法,而不是关注程序要处理的数据。很多时候,写程序最好的方法是,写出你将要用到或处理的数据,然后再从上到下的想怎么样去处理这些数据,最后才能得到你需要的结果。首先定义数据,然后再写出那些要处理这些数据的相关的函数。,这样你才会得到你的程序应该怎样写的基本思路,
It's interesting that both of these approaches focus on the actions of the program rather than the objects the program manipulates - variables. Many times, the best way to write a program is to figure out the variables you need to work with and then progress with a top-down approach to the program that manipulates those variables. By defining variables first and then working with functions that work on them, you will always maintain a basic foundation of what your program should be doing. Once you have an idea of what variables you will be using, then you can write functions to perform the operations you need to perform on the variables while maintaining sight of the goal. Finally you can write the code for each individual function.

Another value to defining variables before writing code is that many times you can accomplish an entire program without many functions; this fact is especially true when you are a beginner making simple programs. The variables give you the raw materials you need to begin working with the tools: loops, if statements, library functions, and perhaps user defined functions.


现在让我们来看一个关于怎样开始写一个完整程序的例子。假设你要写的程序是要模拟一个DVD商店的租售系统,这个系统需要计算出出租DVD的总收入。你的程序有可能要求,需要输入一个代码,告诉你这个DVD租售的价格是2元一天还是是3元一天,然后还需要它出租了多少天,最后如果这个输入的代码是0,整个程序就结束了。你应该要分别计算出租金为3元/天和2元/天的DVD的出租的总天数。拿这个程序来说,思考设计程序的最好的方式是,想象为了计算出租金的收入,你需要存储哪些信息:

 

  • 你需要一个变量用来存储总收入,当程序结束时;
  • 你需要一个临时变量用来存储代表DVD的租金的代号;
  • 你需要一个临时变量用来存储某个DVD出租的天数;
  • 你需要一个变量来存储租金为3元/天的所有DVD出租了多少天的总数;
  • 最后,你还需要一个变量来存储租金为2元/天的所有DVD出租了多少天的总数;

 

Let's take a look at an example of how to go about thinking about a program. If you were to write a program to simulate a video store rental system that calculates the gross revenue from rentals, you might be asked to write a program that accepts a code telling you whether a certain video was rented at $2.00 (input as 2) a day or $3.00 (input as 3) a day and then asks for how many days it was rented out for; finally, if the code for the cost of rental is 0 the program should terminate. You should also count the number of days videos were rented at $3.00 per day and $2.00 per day. The best way to think about the design for a program such as this one is to imagine what information you need to store in order to calculate the revenue:

  • you need a variable to store the total dollar amount at the end of the program;
  • you need a temporary variable to store the code for the cost of a transaction;
  • you need a temporary variable to store the number of days a specific video was rented;
  • you need a variable to store the number of days each video was rented;
  • you need a variable to count the total number of days $3.00 videos were rented;
  • finally, you need a variable to count the total number of days $2.00 videos were rented.

一旦你认识到你需要这些数据,那么你就很容易想出如何处理这些数据:比如,你知道租金2元/天的DVD的总收入=所有租金为2元/天DVD的出租天数之和*2;类似的也可以计算出租金3元/天的DVD的总收入。你也会理解这个“代表DVD的租金的代号”,这个变量的用处是,当用户输入某个DVD出租的天数时,决定哪个变量会被操作。在你的程序中你需要一个循环结构。


Once you realize you need these variables, you can easily imagine how to translate them in terms of each other: for example, you know the total amount of revenue is the number of days videos at $2.00 were rented times $2.00; in similar fashion, you know the relationship for $3.00 a day videos. You should understand that the transaction 'code' determines which variables are manipulated when the user inputs the number of days a specific video was rented (for example, whether to add to the count of days for $2.00 videos or $3.00 videos). You'll probably need a loop in your program (although you can't necessarily infer this from the variables).

 

程序的代码有可能会像下面那样:

The code might look as follows:

 1 
 3 int main()
 4 {
 5   int total_dollars = 0;
 6   int total_days_at_3_dollars = 0;
 7   int total_days_at_2_dollars = 0;
 8   int transaction_code = 0;
 9   int days_for_one_video = 0;
10   do
11   {
12     if(transaction_code==2)
13       total_days_at_2_dollars+=days_for_one_video;
14     if(transaction_code==3)
15       total_days_at_3_dollars+=days_for_one_video;
16     cout<<"Please enter a transaction code and number of days a video was rented: ";
17     cin>>transaction_code>>days_for_one_video;
18   }while(transaction_code!=0)
19   return 0
20 }

我希望,你现在已经有了一个基本的思路,在写代码之前,应该如何安排你的程序的结构。

Hopefully, you now have a basic idea of how to lay out your program structure in your mind before you begin to write code.

 

posted @ 2011-10-19 11:00 黄剑父 阅读(1876) | 评论 (0)编辑 收藏

application文件夹为ext js4的应用程序目录,
ext文件夹为ext js 4资源的目录,
其他文件或文件夹则为yii框架所涉及到的。
posted @ 2011-07-27 14:50 黄剑父 阅读(2079) | 评论 (1)编辑 收藏
Apache服务器下yii的urlManager设置
step1:Yii的配置文件config/main.php中
'components'下增加
 1 'urlManager'=>array(
 2     'urlFormat'=>'path',
 3     'showScriptName' => false,
 4     'rules'=>array(
 5         'urls.js' => 'workspace/urls',
 6         'env.js' => 'workspace/env',
 7                 '<controller:\w+>/<id:\d+>'=>'<controller>/view',
 8                 '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
 9                 '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
10             ),
11         ),
step2:开启Apache的配置文件httpd.conf中LoadModule rewrite_module modules/mod_rewrite.so和AllowOverride属性设置为All
step3:编写一个.htaccess文件放在app的根目录,添加以下几行到文件中
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php
posted @ 2011-07-26 14:20 黄剑父 阅读(5306) | 评论 (0)编辑 收藏
网站:
http://www.sencha.com/products/extjs/
posted @ 2011-07-18 11:03 黄剑父 阅读(263) | 评论 (0)编辑 收藏

printf的格式控制的完整格式:
%  -  0  m.n  l或h  格式字符
下面对组成格式说明的各项加以说明:
①%:表示格式说明的起始符号,不可缺少。
②-:有-表示左对齐输出,如省略表示右对齐输出。
③0:有0表示指定空位填0,如省略表示指定空位不填。
④m.n:m指域宽,即对应的输出项在输出设备上所占的字符数。N指精度。用于说明输出的实型数的小数位数。为指定n时,隐含的精度为n=6位。
⑤l或h:l对整型指long型,对实型指double型。h用于将整型的格式字符修正为short型。

---------------------------------------
格式字符
格式字符用以指定输出项的数据类型和输出格式。
 ①d格式:用来输出十进制整数。有以下几种用法:
%d:按整型数据的实际长度输出。
%md:m为指定的输出字段的宽度。如果数据的位数小于m,则左端补以空格,若大于m,则按实际位数输出。
%ld:输出长整型数据。
②o格式:以无符号八进制形式输出整数。对长整型可以用"%lo"格式输出。同样也可以指定字段宽度用“%mo”格式输出。
例:
   main()
   { int a = -1;
     printf("%d, %o", a, a);
   }
  运行结果:-1,177777
  程序解析:-1在内存单元中(以补码形式存放)为(1111111111111111)2,转换为八进制数为(177777)8。
③x格式:以无符号十六进制形式输出整数。对长整型可以用"%lx"格式输出。同样也可以指定字段宽度用"%mx"格式输出。
④u格式:以无符号十进制形式输出整数。对长整型可以用"%lu"格式输出。同样也可以指定字段宽度用“%mu”格式输出。
⑤c格式:输出一个字符。
⑥s格式:用来输出一个串。有几中用法
%s:例如:printf("%s", "CHINA")输出"CHINA"字符串(不包括双引号)。
%ms:输出的字符串占m列,如字符串本身长度大于m,则突破获m的限制,将字符串全部输出。若串长小于m,则左补空格。
%-ms:如果串长小于m,则在m列范围内,字符串向左靠,右补空格。
%m.ns:输出占m列,但只取字符串中左端n个字符。这n个字符输出在m列的右侧,左补空格。
%-m.ns:其中m、n含义同上,n个字符输出在m列范围的左侧,右补空格。如果n>m,则自动取n值,即保证n个字符正常输出。
⑦f格式:用来输出实数(包括单、双精度),以小数形式输出。有以下几种用法:
%f:不指定宽度,整数部分全部输出并输出6位小数。
%m.nf:输出共占m列,其中有n位小数,如数值宽度小于m左端补空格。 
%-m.nf:输出共占n列,其中有n位小数,如数值宽度小于m右端补空格。
⑧e格式:以指数形式输出实数。可用以下形式:
%e:数字部分(又称尾数)输出6位小数,指数部分占5位或4位。
%m.ne和%-m.ne:m、n和”-”字符含义与前相同。此处n指数据的数字部分的小数位数,m表示整个输出数据所占的宽度。
⑨g格式:自动选f格式或e格式中较短的一种输出,且不输出无意义的零。

---------------------------------------
关于printf函数的进一步说明:
如果想输出字符"%",则应该在“格式控制”字符串中用连续两个%表示,如:
printf("%f%%", 1.0/3);
输出0.333333%。

---------------------------------------
对于单精度数,使用%f格式符输出时,仅前7位是有效数字,小数6位.
对于双精度数,使用%lf格式符输出时,前16位是有效数字,小数6位.

######################################拾遗########################################
由高手指点
对于m.n的格式还可以用如下方法表示(例)
char ch[20];
printf("%*.*s\n",m,n,ch);
前边的*定义的是总的宽度,后边的定义的是输出的个数。分别对应外面的参数m和n 。我想这种方法的好处是可以在语句之外对参数m和n赋值,从而控制输出格式。


今天(06.6.9)又看到一种输出格式 %n 可以将所输出字符串的长度值赋绐一个变量, 见下例:

int slen;

printf("hello world%n", &slen);

执行后变量被赋值为11。

又查了一下, 看到一篇文章(查看)说这种格式输出已经确认为一个安全隐患,并且已禁用。再搜搜果然这种用法都被用来搞什么溢出、漏洞之类的,随便找了一个:格式化字符串攻击笔记。
posted @ 2011-04-26 16:18 黄剑父 阅读(291) | 评论 (0)编辑 收藏
仅列出标题  下一页