ITeye博客

2012 年文章归档

共 66 篇文章

Perl Idioms Explained - my $string = do { local $/; <FILEHANDLE> };

http://www.perlmonks.org/index.pl?node_id=287647 open FILEHANDLE, 'somefile.txt' or die $!; my $string = do { local $/; }; The above idiom is a consise way to "slurp" the entire contents of a file into a scalar without using a loop, such as: open FILEHANDLE, 'somefile.txt' or die $!; my $string = '…

2012-12-28 16:25 · perl

Java的Generics的几点限制

参见 http://docs.oracle.com/javase/tutorial/java/generics/restrictions.html To use Java generics effectively, you must consider the following restrictions: Cannot Instantiate Generic Types with Primitive Types Cannot Create Instances of Type Parameters Cannot Declare Static Fields Whose Types are Typ…

2012-12-28 15:00 · java

Overriding Method Using Parameter That is a Subclass?

参见 http://www.coderanch.com/t/389279/java/java/Overriding-Method-Parameter-Subclass 本来想用汉语写标题,发现实在不好说这个逻辑。。。 好吧,这个问题的答案是“ 这是overload不是override ”。 可以参考一下程序验证: public class Animal { public void talkTo(Animal a){ System.out.println("animal"); } } public class Cat extends Animal { public void talkTo(Ca…

2012-12-27 22:14 · java

Java的Generics和c++的Template到底有什么不同?

先了解Java的Generics: 根据Java的文档,Java引入Generics一是为了在编译时提供更强的类型检查,二是为了泛型编程。 编译时,Java靠type erasure来实现Generics: 1. 将所有的泛型参数替换为限定(bound这里如何翻译?)的类型,如果没有限定,就替换为Object类。因此然生的字节码和普通的类文件一样; 2. 为了保证类型安全,必要的时候会是使用cast; 3. 为了维护继承的泛型类型之间的多态的正确性,必要的时候会生成bridge methods。 考虑下面的泛型类,这个类代表单链表的节点。(一下例子均出自java doc) public cl…

2012-12-27 16:21 · c++ · java

关于Erlang里没有global variable的吐槽

当我也开始为erlang不支持全局变量开始感到不爽的时候,看到了某人的吐槽: http://osdir.com/ml/erlang-questions-programming/2002-12/msg00142.html I don't know a single professional programmer that can't get by without global variables. Furthermore, if a programmer feels he/she cannot get their work done without globals they (IMHO) ei…

2012-12-26 14:06 · erlang

怎么不开根号算平方根?

写一个函数,不用开根号算平方根。 这是网上一个题目,一开始一筹莫展,看了答案恍然大悟,就是用二分法去逼近。 const double error = 0.000000001f; double findSqrt(double t){ double high = t; double low = 0; while(high-low >= error){ double mid = (high+low)/2; if(mid*mid > t){ high = mid; }else { low = mid; } } return low; }

2012-12-24 22:55 · algorithm

What's Xen?

Xen的介绍。

2012-12-23 17:19 · cloud

java并发编程

从网上下载到一个文档,翻译的非常好。 付原版和翻译版。 文档末附有作者信息。

2012-12-23 16:37 · java

UML类图中的关系

此篇总结 不错。

2012-12-23 15:58 · java

static blocks in java

这篇 文章可谓极好。 java里面的static code block在jvm装载类文件的时候按照顺序执行,如果其中调用了其他的static方法会去执行那些static方法。

2012-12-21 14:45 · java

【转载】正则表达式30分钟入门教程

有时候忘记一个正则该怎么写了,可以到这个地方看一下。 http://deerchao.net/tutorials/regex/regex.htm

2012-12-20 15:53 · regex

Java的annotation

从oracle的官方文档来学习annotations: 地址在: http://docs.oracle.com/javase/tutorial/java/javaOO/annotations.html 总结如下: Annotations我理解就是程序的一些元数据,没有它程序也是ok的。它的主要用途体现在以下几个方面: 替代以前简单的注释; 比如以前的注释可能是: /* author: Benjamin Franklin date: 3/27/2010 */ class My Class {} 用Annotations可以写成: @Author( name = "Benjamin Frankl…

2012-12-20 15:32 · java

转载一篇CAP理论的文章

http://code.alibabatech.com/blog/dev_related_728/brewers-cap-theorem.html

2012-12-18 18:34

Perl DBI 使用详解

每次使用DBI的时候都忘记该使用哪个函数,下面这个博客讲得很详细! http://blog.csdn.net/fan_zhen_hua/article/details/6078337

2012-12-18 18:32 · perl

使用XML::Simple来读写XML文件

有时对于一个XML配置文件需要简单的将其load到内存生成perl的data structure,然后做了相应改动之后再写到文件中去, 用XML::Simple就比较方便。 但是在使用的过程中发现如果不小心很容易将原文件的结构跟最后dump出去的文件的结构变得不一致,此时要注意使用options。 以下使用example: my $xml = XML::Simple->new(); my $data = $xml->XMLin($file, ForceArray => 1); some changes to $data open my $fh, '>', $file or die $!; $…

2012-12-18 17:38

crontab定期执行命令详解,以及实例

使用时可以参考这个博客: http://blog.51yip.com/linux/1046.html

2012-12-18 17:29 · linux

Perl的Getopt::Long 模块

处理perl参数的时候最有用的模块,有关使用具体细节参考以下别人的博客: http://www.php-oa.com/2009/04/04/perl_getopt-long.html

2012-12-18 17:27 · perl

erlang中的冒号 分号 和 句号

I think erlang beginners like I can be confused about the commas, semicolons and periods used in the end of lines. Here is an explanation when you should use which. http://stackoverflow.com/questions/1110601/in-erlang-when-do-i-use-or-or

2012-11-26 12:00 · erlang

学习hadoop之基于protocol buffers的 RPC

现在版本的hadoop各种server、client RPC端通信协议的实现是基于google的protocol buffers的,如果对这个不熟悉,读code的时候会比较痛苦一些,所以花了些时间学习了一下,然后仿照写了个比较简单的例子,麻雀虽小,五脏俱全,看懂了我这个或许对你读hadoop的code有帮助! :) 我现在实现一个简单的server-client方式的calculator,client将计算请求序列化成protocol buffers形式然后发给server端,server端反序列化后将完成计算然后将结果序列化后返回给client端。 先看一下最后整体的package结构(模…

2012-11-15 23:23 · hadoop

使用ExtJS做动画效果

这是个动画效果的例子,作出一个小球弹跳然后静止. 先是一个div: 然后ExtJS代码: Ext.onReady(function(){ Ext.create('Ext.fx.Animator', { target: 'ball', duration: 5000, keyframes: { 0: { y: 50 }, 20: { y: 300 }, 40: { y: 175, backgroundColor: '#0000FF' }, 60: { y: 300 }, 80: { y: 275, backgroundColor: '#00FF00' }, 100: { y: 300 } } }…

2012-11-15 15:11 · javascript