Friday, August 3, 2012

愤怒,偏见和猜疑都将阻碍有效的交流

有时候我就在想,我这种性格是怎么产生的!三个特征相互加强,相互支持,真是无懈可击。
愤怒:我喜欢用自己的感觉来揣度别人的想法,如果猜对了,就沾沾自喜,加强自己的偏见;如果猜错了,就恼羞成怒,不愿意承认,认为自己不会错,从而产生偏见;

偏见:我喜欢用自圆其说来预测别人的想法,有些事自圆其说了,我甚至不会怀疑,有些事不能自圆其说,我就不愿意相信,即使现在,我的脑海里还有一个声音在浮现“这世界上怎么会有不能自圆其说的事”!

猜疑:它是偏见的一种极端表现,对于我认为不能发生的事,即使发生了,我也认为其中定有内因,只是自己没有发现;对于自己认为可能发生的,就深信不疑,不发生我也认为有人从中作梗...

自己的问题最好能自己发现,在主动改正,不然有你好受的!今天是不输房子部署地的关系,明天,估计就不会这么轻松了!

Saturday, July 28, 2012

How to install a C/C++ library on a Linux which you cannot use “su” or “sudo”

If you are working with a remote server, you may not have administrator privilege, or “sudo”, to install a library like “yum install XXXXX” or “configure->make->make install”. But if you really need a C/C++ library and no one you known has administrator privilege, the following steps may save you, in most cases. I will use GNU Scientific Library(GSL) as an example to show you how to get it working in your own directory without administrator privilege.

1. Download GSL source code and input “-prefix=[PATH]” when running “configure”. This operation tells the source code that you want to put the library files in [PATH]. Once the source code is compiled, run “make install”. All the library files generated will be copied to [PATH].

2. Tell the compiler and linker where is the library. For GCC/G++, we could use “-L” to input a library path and “-I” to input a include path to the compiler. So, in your make file, we could define two lines as follows:

GSL_INCLUDE = /home/hanyu/library/gsl/include/
GSL_LIB = /home/hanyu/library/gsl/lib/

Then put those two flags in your make file as follows:

$(CC)  -I$(GSL_INCLUDE) -L$(GSL_LIB)

After doing the steps above, you should successfully compile your code which depends on GSL. However, when you run your program, you may receive a error like “cannot find XXXX.so…”. To fix this, please do the following step.

3. Add the library folder to “LD_LIBRARY_PATH”. Put the following lines at the bottom to your “.bashrc” and log off:

LD_LIBRARY_PATH=/home/hanyu/library/gsl/lib/:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH

Then, log in again. Your program should be executed properly.

Thursday, July 26, 2012

【转】30种编程语言的比较选择问题

本文涉及到的编程语言:C、C++、Java、C#、Prolog、VB、Scala、Clojure、Haskell、Ada、Python、Ruby、Pascal(Delphi)、Fortran、Lisp、matlab、Perl、Erlang、Boo、Tcl、Bash、C shell、Objective-C、PHP、PL-SQL、Transact-SQL、ASP、JSP、Lua、smalltalk、R、D

涉及到的工具:sed、awk、grep

我们现在学一门语言,大部分是要用到了才学(基本上是中国的公司用什么我们学什么),基于兴趣的不多。

比如,大头肯定是C++和java,因为这个最容易混饭吃。最近多玩用了Erlang,还有不少公司跟风上了Erlang,让这个沉默了好久的语言忽然被明星了。

大公司一般除了C++外,都会招Java,事实上,互联网公司,Java占了半壁江山(当然,没选java架构的除外,有不少.net族的)。所以,生活在贫困线上的广大中国程序猿很少有人会去看看诸如scala之类的玩意。不过作为胶水,python、perl还是有一定的用户量的。

似乎,我们生活中只有这么几种语言。。。

貌似,遇到一个问题,我们该选择什么语言呢?虽然每个语言本质上都是图灵完备的,但是能用prolog写出来的东西,如果用别的语言写,会无比痛苦。这就是不同语言存在的原因:不同的问题,不同思考方式(编程范式)。

  • 解决问题case:已知大量事实,和事实之间的约束,要求挖掘关系。
果断用prolog族语言。

例如,汉诺塔、地图着色、数独问题、八皇后问题等这种考验智商,并且需要从已知规则中发现模式的问题。拥有一大堆已知案例的应用(例如大部分的人工智能情况)

  • 应用程序case:从小到超大型应用程序,非完全互联网应用

这也是大部分软件公司遇到的情况。一般有几种没办法分出高下的解决方案:C++,Java,C#,VB。当然,这里面可以有CLR和JVM的不同衍生。例如,理论上,你也可以用scala来代替(不过估计大型公司不会冒这个险)。还是在理论上,你也可以用函数式编程的ClojureHaskell来做(估计没人会那么傻)。还是在理论上,也可以用Ada这种强悍的通用语言,但估计没人愿意接收比C++还复杂的编程语言。理论上(基本只能在理论上),不嫌弃的话smalltalk也行。还是在理论上,python、ruby等配合一定的图形界面库也可以胜任(但项目大到一定的程度是,你会欲哭无泪)。

但是,我另起一行。有个语言:D语言。我个人不认为不可以列入首选名单。但是貌似知名度不行啊。。。。企业支持少啊。。。。。确实是门优秀的语言。C++太尾大不掉,需要一种语言,让C++成为纯粹的C++。

稍小一点规模的,无法接收面向对象的程序员,有不少用C的。虽然OOP程序员看他们像是不开化的人,但是他们有他们的哲学(我从嵌入式开发过来,相当长时间内也拜托不了C,总本能的排斥OOP)

  • 解决问题case:程序规模不是很大的偏数学问题

曾经很多人用Pascal(包括扩展的Delphi),曾经很多人用Fortran,但是都明显在退步。大型通用语言(C++、Java、C#)表明了他们在各种环境的适应能力。lisp系列也在一些问题上展现出古老的魅力。(但这个语言远没有《黑客与画家》的作者给我们描述的那样神奇,个人认为)

另外,读研的一般都用过matlab。这个工具,两个字:强大!不过仅指科学计算方面。脱离了这个方面,就得考虑合不合适了,毕竟固定的矩阵思维不是啥情况都有效的。

  • 特殊应用case:需要大量处理字符串的应用

首选利器是Perl,不过如果你习惯了sed、awk、grep,也能很方便的完成相同的功能,但perl是吸收三家所长做的。

其次是C++,别拍我。诸位用过regex吗?就是boost里的那个,最近被并入C++11啦。有了正则表达式的C++,处理字符,无敌了很多哇。

  • 特殊应用case:需要一个胶水,粘结不同语言写出来的程序

首选是python。俩字:精简(呀,这么说一个强大的语言有点太轻浮了,但比起ruby,确实简单呐。。。)(另外Boo在.net是可以用来取代python)

其次是ruby。俩字:复杂

毕竟,没有rails,ruby根本火不起来。事实证明,python的哲学很对。当然两种语言有很多细节的不同,甚至在编程范式上不同(真想不明白白ruby支持多种范式怎么可能是个优点?市场证明了python的纯粹)

  • 特殊应用case:自动化测试

不用问了,肯定是tcl了。

由于这个特殊应用,所以个人用户基本用不到,大部分是嵌入式公司。华为、数通、迈普等。。。

  • 特殊应用case:系统底层

这个肯定是C了。操作系统,驱动,底层软件,大部分都是C写的,调用API,如果不用微软的Activex之类的技术,还是得老老实实用C API的。

  • 特殊应用case:系统管理

这个系统管理,一般指linux的。首选肯定是各种shell啦:Bash、C shell

  • 特殊情况case:苹果平台

我们没得选。。。。objective-C

  • 特殊领域:嵌入式

大部分都是C了。不过andriod平台和苹果平台就得听话了。

  • 特殊应用:网页

嵌入网页内的,最火的肯定是PHP(后端)和javascript(前端)了。前者代替了古老的cgi。

但是,java系的jsp内嵌java,asp内嵌C#,都是php的强劲对手。

通用语言在各个方面咄咄逼人。

  • 特殊应用:数据库

就是比哪个SQL版本更被人接收。标准sql自然不必说,根据排名,PL(SQL)/Transact-SQL上榜。

  • 特殊应用:并行,分布式

并行越来越重要了。

首选Erlang

但是,基于已有的条件,还是考虑选用通用语言的并行优化。C++、Java、C#等都在这方面做了很多优秀的工作。

  • 特殊应用:特定语言的功能增强

不用问了,我想说的是Lua。用C++写实现,用Lua写逻辑是好多游戏的经典开发策略。(当然像Unity用的javascript,Unreal用的自己的。)

在通用大型语言的基础上学会用Lua加速,是一种很有趣的实践。

特殊应用:人工智能

人工智能上,prologlisp是宠儿。

R语言有时也被用于数据挖掘(但是太慢了)

Sunday, July 22, 2012

追忆曲艺背后的那段乡情...

曲艺不是爷爷奶奶的专利,不是吃大蒜时的下里巴人,更不是过时的老古董。我心目中的曲艺,是一缕乡情,是一丝牵挂,是每个中国人灵魂最深处的文化符号和认同感!身在故乡的你可能每天都重复这相同的曲目,相同的活动,相同的食物,你可能会慢慢厌倦,希望新的精彩!但对于身处海外的我来说,故乡的那些元素都是那么的遥不可及,只有乡音的曲艺,能飘扬过海,轻轻的打开那段尘封的记忆...再次把我带回那个飘雪的年关,热闹的庙会,还有父母的大手,爷爷奶奶姥姥姥爷的微笑。

How to download ringtone from AudioDraft Nokia Tune Contest

I got a new Nokia Lumia 900 and want to use one ringtone(I like Progressive Nokia most) from Nokia Tune Contest. After searching the web, there is not a good guide to tell you how to download them. So I write the following steps, attached screenshot, and hope you enjoy the great works from the contest.

1. Use Google Chrome to open the front page of the contest at Audiodraft;

image

2. Open JavaScript console;

image

3. Open Source tab and open “script_player.js”, then set a break point at line 73;

image

4. play the ringtone you want to download by clicking the little triangle in Audiodraft; then the console will look like the follows; click the variable “data” and copy the link in it.

image

5. paste the link to a new tab and you could download the ringtone, which is a mp3 file. You could use it as your ringtone by synchronizing it with Zune. Please read this to learn how to set mp3 file as your ringtone on Nokia WP phones.

Thursday, July 12, 2012

Have no post for a long time

It is really a long since my last algorithm post. I am really not mean to do it, because I have few hassle problems need to be handled carefully. However, I think I could post a series of post in the coming few days, which will focus on a problem I met and took a lot of my coding efforts. I will call it "CUT AND PASTE" problem.
This problem can be described in the following manner:
When you decomposed your big requirement into a number of small components, which could be executables, those small components are implemented separately. But they may share some common functional units, such as file loader, or format convertor. Those functional units may work very similar to each other, but there may still have some tiny differences. You may directly "CUT AND PASTE" your code from other directories and use them in your new applications. In the near future, you will find your previous implementation is not so good, or add some new functions, this "CUT AND PASTE" may cause many problems, which may take you a lot of time to keep them synchronized. 
You may say that why not use a library? Sure, you could do that, but once you make a library, any changes will affect all code which depends on it. It is not a selective process. 
I have an idea popped in my mind. Can we create a branch based local version control system that lets you choose which file to be updated and how to update. Once you make an update, the system could record your changes and give a name to this change. The shared files are located in a centralized folder, which is monitored by the system. When you compile your code, the further updated which submitted later than the last edited time of the project will be set transparent. Then, if you want to change to another version, or say synchronize some updates, you could select all the versions in the branches, including the newest changes. Once you made the decision, the other versions of the file will be transparent.

Monday, July 9, 2012

献给小美女,献给猥琐男!


老大的女儿马上就要降生了!刚听到这个消息没觉得什么,只是默默的祝福他们!但今天忽然很想笑,而且真的一个人傻傻的笑了很久!
想到当年我们5个人围在老大的台机旁边看AV,一转眼3年过去了!我们也许永远不会再有机会干这么2的事了,但我们这五个老男人,或大男孩,也许某一天会那样围在一起,一起逗小宝宝开心!
也许以后有一天,我们都有了儿女!我一定会鼓励我儿子追你家姑娘,我姑娘嫁你儿子,哈哈!到时候咱们几个亲家也别麻烦儿女了,一起搬到敬老院,也开个6人间!三毛掌灯带饭,文俊建网,我跟老大扛水...然后跟你们这几个老不死的猥琐男打一辈子Dota!

谨以此文,献给我们在一起的四年,献给我们逝去的青春,献给我们即将到来的挑战!
并祝福母女平安!