渴死的火烈鸟
standalone · 共 356 篇文章
Perl的Getopt::Long 模块
处理perl参数的时候最有用的模块,有关使用具体细节参考以下别人的博客: http://www.php-oa.com/2009/04/04/perl_getopt-long.html
2012-12-18 17:27 · perl · 评论(0)
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 · 评论(1)
学习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 · 评论(0)
使用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 · 评论(0)
ExtJs Event Delegation
Event handlers are a common cause of memory leaks and can cause performance degradation when not managed carefully. The more event handlers we create the more likely we are to introduce such problems, so we should try to avoid creating huge numbers of handlers when we don't have to. Event delegatio…
2012-11-15 14:06 · javascript · 评论(0)
ExtJS 的event handler的scope
var button = Ext.create('Ext.button.Button', { text: 'My Test Button', listeners: { click: function(button, e, options){ alert(this.text); } }, renderTo: Ext.getBody() }); button.show(); 上面的代码结果是My Test Button var exampleObject = { text: 'My Test Object' }; var button = Ext.create('Ext.button.Butto…
2012-11-14 22:00 · javascript · 评论(0)
Ext.bind() 方法
var cat = { sound: 'miaow', speak: function(){ alert(this.sound); } }; var dog = { sound: 'woof', speak: function(){ alert(this.sound); } }; cat.speak(); // alerts 'miaow' dog.speak(); // alerts 'woof' Ext.bind(dog.speak, cat)(); // alerts 'miaow' How it works: The Ext.bind method creates a wrapper…
2012-11-14 21:54 · javascript · 评论(0)
extjs mixin example
//1. Define our simple mixin class called HasCamera with a single //method called takePhoto: Ext.define('HasCamera', { takePhoto: function(){ alert('Say Cheese! .... Click!'); } }); //2. Define a skeleton class and use the mixins configuration option //to apply our HasCamera mixin to our Cookbook.S…
2012-11-14 17:29 · javascript · 评论(0)
Hadoop Version Graph
可以到这里看全文: http://cloudblog.8kmiles.com/2012/01/19/apache-hadoop-version-timeline/ 有感于hadoop版本的混乱,看到了这篇文章讲解其发展路线,甚好。但是,注意原文是在2012年一月份写的,所以最新的肯定没在上面,谁要是能再总结一下就好了。
2012-11-14 11:47 · hadoop · 评论(0)
Google Protocol Buffers
http://blog.jeoygin.org/2011/09/rpc-framework-protocol-buffers.html 这是我在网上找到的关于PB的比较好的一个文章.其他的博客都只讲了PB作为序列化的功能,在其用作RPC方面鲜有讲到,这篇给出了一个使用第三方基于PB的RPC实现的一个例子。 就像作者说的: protocol buffers并没有实现RPC通信,可以使用第三方的RPC实现protobuf-socket-rpc,下载地址是: http://protobuf-socket-rpc.googlecode.com/files/protobuf-socket-rpc-2.…
2012-11-09 11:01 · java · 评论(0)
erlang程序解释:冒泡排序
原code参见 http://en.literateprograms.org/Bubble_sort_(Erlang) 虽然原文有解释,可能还是不太好理解erlang写得这么间断晦涩的程序。 1 % Copyright (c) 2012 the authors listed at the following URL, and/or 2 % the authors of referenced articles or incorporated external code: 3 % http://en.literateprograms.org/Bubble_sort_(Erlang)?action…
2012-11-07 18:10 · erlang · 评论(0)
stack with min operation
How would you design a stack which, in addition to push and pop, also has a function min which returns the minimum element? Push, pop and min should all operate in O(1) time. public class StackWithMin extends Stack<NodeWithMin> { public void push(int value) { int newMin = Math.min(value, min()); su…
Rotation of String
Problem: Assume you have a method isSubstring which checks if one word is a substring of another. Given two strings, s1 and s2, write code to check if s2 is a rotation of s1 using only one call to isSubstring (i.e., “waterbottle” is a rotation of “erbottlewat”). 这个问题的trick就是将两个原字符串拼起来,然后检测。。。
算法:去除字符串中的重复字母
问题:去除字符串中的重复字符,不能使用额外空间(1或者2个变量除外)。 很简单的练手题,但是发现很难写正确。 public class DuplicateChar { //return length of the final string public static int removeDuplicateChar(char []str){ int len = str.length; if(len < 2) return len; for(int i=0;i<len-1;i++){ char ch = str[i]; int index = i+1; for(int j=i+1;j<=len-…
找零钱问题
假设有25美分,10美分,5美分,1美分的硬币足够多,假设有N美分钱,问你怎么用这些硬币表示? 用perl重新做这个问题,前面用 java 做过 use strict; use warnings; my $count = 0; sub changes { my ($coins_ref, $factors_ref, $value) = @_; my @coins = @$coins_ref; if($value == 0){ $count++; print "Result $count\n"; foreach my $key (keys %$factors_ref){ print "coin:…