民意调查显示,平,PubSub的,pubsubhub,pubsubhubbub
的情况下,你是持怀疑态度,有一个在上面疯狂的方法,在文章标题。 在高科技界,这是不可能,你没有听到pubsubhubbub的。 在快速的几个月中,它一直谈论的事情的前三名之一。 其他两个分别是同态加密和谷歌波 [ 1 ]。 回来到目前的职位 - 在标题上注明你从其他人的内容如何。 以下细节变得更加清晰,如果你能想象博客的事情发生,即使它们概念并不局限于博客。
投票是指在客户端要求服务器,如果新的东西拿出的情况下。 经常要求更新,将始终是一个投票过于频繁或过于频繁的问题,但作为一个读者指出, 在这里 ,一个伟大的 ,投票的事情是该服务器不维护状态。
平是指在发表文章时,您(或您的软件)也更新了一些流行(中央)更新服务的情况下。 这里的一些背景。
接下来是PubSub的发布/订阅,最早的球场之一,因为它是站在这里,埃文亨肖-普拉斯和凯兰埃利奥特-麦克雷(72张幻灯片,但值得经历)。 引人注目的例子,他们给了反对 - 在某一特定日期,FriendFeed上抓取Flickr的290万次,45754用户得到最新的照片,其中6721的24小时访问Flickr和可能潜在的“上传照片。 请注意,他们提出的是不是一种新技术,为他们指出“革命性的新的20岁的技术”。 如果你的博客,然后使用XMPP的主要问题之一 - 存在数据的开销,这可能是高达60-70%,可以减少很多。
pubsubhub代表发布订阅枢纽和pubsubhubbub是一个协议,其中核心是pubsubhub的想法。 其中出版商(比如博客)更新枢纽(驻留“在云的地方”,每个协议,可以推或拉,每协议,但在接下来的环节,可能是多个集线器,互相交谈)链,枢纽到客户端(比如读者)它总是推模型。为pubsubhubbub起点, 这个页面是好的,概述幻灯片都不错。 曾经雄辩的阿尼尔·达什介绍, 这里按钮网页。
另外两个相关的读取webhooks基本上是HTTP回调。 Github上使用它,所以贝宝付款IPN的异步通知,所以许多人。 相关的概念是rsscloud这又是PubSub的枢纽。 按照此链接查看详情。
你可能想知道,在这里写这些点是什么,有两个1。 这些东西都是值得了解,微创至少2。 这个博客是通过Feedburner的,链接在这里启用pubsubhubbub通过appspot使用该WordPress中心现在启用插件和饲料也是pubsubhubbub
-
[ 1 ]。 -很好的入门读完全同态加密, 这是由Bruce Schneier的文章, 这个讲座是或多或少谷歌波浪的唯一来源。
更新- 这个职位说明公共服务器回调的要求如何可以工作的桌面客户端周围使用XMPP网关(pubsubhubbub为)。
有点集会
看完这篇文章有关锁空闲缓冲区,看到使用了CAS(比较和交换),我发布的汇编代码,做同样的感觉。 使用的情况下,那边是写一个本地方法,并调用它从Java(1.5,当在Java并发数据结构不存在或多或少)。 事不宜迟,我会释放到你的代码
。 首先是中科院和计算GCD的第二个是用欧几里德算法(此人可以发现,在许多地方和教程以及)。
编译和运行指示 gcc file_name.c ; ./a.out
比较和交换
#包括#包括 / /交换 - newvalue,comperand是旧的/预期值 / * *函数实际上做以下的事情 - 如果在* dest的值是等于oldvalue然后newvalue其他不改变它取代:做所有这些原子 * *有两个返回值的选项 * 1.is初始值* dest的离开,调用fxn负担比较与OLDVAL * 2。 在这里做,并返回0或1,这应该是更有效 ** / / *后来改变成宏* / INT CAS(INT * dest中,oldvalue,INT newvalue){ 输出(“(%D,为%d,%d个)”,* dest中,oldvalue,newValue)以; / * CAS(目的INT,INT oldvalue,newValue)以{* / / * CAS(INT目的,newvalue INT oldvalue){* / 结果= 1 ;/ * 1可以看出,CAS成功,0表示失败* / / * BTW需要设置标志重挫CC! * / __asm__ __ volatile__( “MOVL%2,%eax中\ N \ T” “MOVL%3,%ebx中\ N \ T” “MOVL%0%ECX \ N \ T” “锁\ N \ T” \ N \ T“CMPXCHG%EBX(%ECX)”/ *应该锁定在同一行* / “JZ \ N \ T” “MOVL $ 0%1 \ N \ T” “DONE:\ N \ T” “M”(DEST),“克”(结果) :“G”(oldvalue),“G”(newValue)以“M”(DEST) :“%eax中”,“%ebx中”,“ECX”,“CC” ); 输出(“(%D,为%d,%d个)”,* dest中,oldvalue,newValue)以; 返回结果; } / *的TODO *写在一个while循环以上fxn了另一个ASM fxn的不断尝试,除非它成功* / 诠释的主要(){ A = 5,B = 6; INT * C =(INT *)malloc的(如sizeof(int)); * C = 6; / * C = 6 * / printf(“请为%d \ N”,CAS(C,B,B)); printf(“请为%d \ N”,CAS(C,B,A)); 输出(“%d个\ N”,CAS(C,A,A)); printf(“请为%d \ N”,CAS(C,B,B)); * C = 6; / * C = 5; * / 输出(“变化值* C至%d条\ n”,* C); printf(“请为%d \ N”,CAS(C,B,B)); printf(“请为%d \ N”,CAS(C,B,A)); 输出(“%d个\ N”,CAS(C,A,A)); printf(“请为%d \ N”,CAS(C,A,B)); printf(“请为%d \ N”,CAS(C,B,A)); 返回0; }
格式化笔记 - 像WP语法高亮似乎增加 在年底,忽视这一点。
最大公约数
#包括GCD INT(INT A,INT B){ int结果; / *计算最大公约数使用Euclid的算法* / __asm__ __ volatile__(“MOVL%1,%eax中;” “MOVL%2,%ebx中;” “cmpl续完:$ 0,%ebx中;” “JE; 的“xorl%EDX,%edx中;” 的“idivl%EBX; “MOVL%%EBX,EAX%; “MOVL%%,%%ebx中EDX; “JMP续完; “DONE:MOVL%eax中,%0”:“克”(结果):(一)“G”,“G”(二) ); 返回结果; } 诠释的主要(){ int的第一,第二; printf的(“请输入两个整数:”); scanf函数(“%d的%d”,与第一及第二); 输出(“%d的%d的最大公约数是%d \ N”,第一,第二,GCD(第一,第二)); 返回0; }
板球的世界等待着一个新的世界秩序
经过一系列跨越五个测试和大约两个月,英国再生骨灰。
让我们的冠军球队的先谈谈 - 他们中间的顺序是“平均”,如果你不想关键。 greame斯旺与蝙蝠的贡献将计算不超过球的贡献。 斯图尔特 - 最广泛多面手是第5次试验的非起动。 安德鲁·施特劳斯是一致的击球手和吉米·安德森是唯一一致的投球手。
这里的关键是没有,痛斥冠军球队所取得的成就,但角度提出的事实,尽管所有这些,澳大利亚失去。 你想几秒钟,如果被问及他们的最佳投球手。 正确的,它是:体重Hilfenhaus。 hauritz跑赢everbody的期望,但仍然不够好五个测试中的两个选择。 南非从来没有一个世界级微调成为世界打浆机,澳大利亚不能希望仍然没有一个足够好的一个至少之一。 魔术师离开了舞台,它看起来并不像艺术了,忘了魔术。 庞廷高高耸立之间较小凡人和迈克尔·克拉克经常站起来,但是,使他们与一些非常优秀的球员,而不是一支非常好的球队的队。
骨灰2009会被记住安德鲁Flintoff的最后灰烬,斯图尔特广泛的抵达1所有全才(如果他增加了一些灰烬民俗到他的前途开始),并在所有的时间最有说服力的首演由特洛特世纪,但它会也成为IFS和澳大利亚的优势但是终于把休息点记住,这是结束了。 不要误会,他们仍然可以挖掘迈克·赫西或斯图尔特·克拉克,但你觉得所有伟大的贡献,当他们失踪。 有时他们来提醒自己,你在彩光,但他们仍然无法替代的。 让我们觉得沃恩,麦格拉思和Gilchrist一起玩支持由Waughs,庞廷,Hyden,马丁和兰格看到祝福。
展望未来,南非将始终保持一支非常好的球队,但他们需要赢得半决赛和世界各地更加一致,巴基斯坦将保持神秘辉煌,印度年轻的枪可能会发现很难填补非凡的前辈的鞋。 斯里兰卡应继续显示在工艺艺术的影子。 但是,我们可能不得不等待一段时间之前,有全力以赴主导的团队或前一个队长抱怨缺乏竞争,史蒂夫·沃做一次。
在一个相关的说明 - 让我们欢迎的,阿西夫未来回来,他有1潜在的地狱了很多,让我们的希望来看到的一些和也欢迎安迪的新awatar花,权利,你不能保持长久的好男人下来。
红宝石1层,创建哈希
昨天,同时通过我的老节目之一,我发现我写的一段时间回来:
#begin magic
hash=Hash[*CGI.unescape(raw_text).split('&').map{|x| b=x.split("=");b.push(nil) if b.size==1;b}.flatten]
#end magic
杀一些悬念,让我透露,raw_text看起来像
,权利,它已被切断,从Paypal付款确认。
如果在零件坏了上面的行读取更好:
unescaped_array CGI.unescape(raw_text)。分裂('&') = unescaped_array unescaped_array.collect {| X | B = x.split(“=”); b.push(零)如果b.size == 1;} flattened_array = unescaped_array.flatten 哈希散列[* flattened_array]
让我们做在irb中的各个步骤:
IRB(主):009:0> unescaped_array = CGI.unescape(raw_text)分裂('&') => [“侨”,“mc_gross = 10.00”,“protection_eligibility =不合格”,“payer_id = U7PPJJ4TSJ47E”,“税= 0.00”,“payment_date = 9点45分30秒2009年07月10日,PDT”,“PAYMENT_STATUS =待定“] IRB(主):013:0> unescaped_array = unescaped_array.map {| X | B = x.split(“=”); b.push(零)如果b.size == 1;} => [“侨”,无],[的“mc_gross”,“10.00”],[“protection_eligibility”,“不合格”,“payer_id”,“U7PPJJ4TSJ47E”],[“税收”,“0.00”] [“payment_date”,“9点45分30秒7月10日,2009 PDT”],[“PAYMENT_STATUS”,“待定”。]] IRB(主):014:0> flattened_array = unescaped_array.flatten =>“成功”,无“mc_gross”,“10.00”,“protection_eligibility”,“不合格”,“payer_id”,“U7PPJJ4TSJ47E”,“税法”,“0.00”,“payment_date”,“09:45: 30日2009年07月10日,PDT“,”PAYMENT_STATUS“,”待定“] IRB(主):015:0> 哈希散列[* flattened_array] => {“税”=>“0.00”,“PAYMENT_STATUS”=>“挂起”,“payer_id”=>“U7PPJJ4TSJ47E”,“mc_gross”=>“10.00”,“成功”=>“零”payment_date“= “九时45分三十秒07月10,2009 PDT”,“protection_eligibility”=>“不合格”}
顺便说一句,*被称为红宝石的图示操作员
从“对数组的哈希创建的另一种方法是使用注:
哈希= [1,2],[3,4]注入({})。{|结果,元素|结果element.first] =结果[element.last];结果} 有一个方法
写一个循环,我会留给读者作为练习!
这里是位从阵列创建哈希无关的使用情况:
IRB(主):005:0> [1,2,3,4,7,9] GROUP_BY {| X | X <5? 更低::更大} => {:较小的=> [1,2,3,4]:更大=> [7,9]}
你可以做更多的事情,基本上块的结果作为使用中产生的哈希元素的关键。
Gmail时,mutt和msmtp会修复
如果您使用mutt和SMTP访问Gmail。 这里是(坏)消息。 在谷歌酷哥再次改变证书。 哦,你问 - 如何知道? 简单的小狗开始抱怨自己的证书时,尝试使用的msmpt,臭名昭著的“msmtp会:TLS证书验证失败:证书还没有得到一个已知的发行人 迎接我在屏幕上。
交叉确认 -
只要运行以下
$ msmtp --serverinfo --host=smtp.gmail.com --tls=on --port=587 --tls-certcheck=off
在地方老Thwate服务器现在你在发行人段
Issuer:
Common Name: Google Internet Authority
Organization: Google Inc
Country: US
幸运的修复很简单,这里是你需要做的在debian
# apt-get install ca-certificates
# dpkg -s ca-certificates|grep Version
Version: 20090814
在此之后只是改变下面一行在你〜/。msmtprc的
tls_trust_file /certs/Thawte SSLWeb Server Roots/thawte Premium Server CA/Thawte Premium Server CA.pem
tls_trust_file /certs/Thawte SSLWeb Server Roots/thawte Premium Server CA/Thawte Premium Server CA.pem
至
tls_trust_file /usr/share/ca-certificates/mozilla/Equifax_Secure_CA.crt
Git和真棒调查
这里有两个环节调查的git(版本控制系统)和真棒(窗口管理器)社区。 如果你使用这些,请拿出一些时间来填写问卷。 把它看成是最简单的方式回馈给您使用的软件。
这里是链接:
GIT - http://www.survs.com/survey?id=2PIMZGU0&channel=Q0EKJ3NF54
真棒- http://www.survs.com/survey?id=8BVEV3FO&channel=BH07CQ040D
注 - (由于在这些网页上,但在底部发现
) -
“如果你启用了Cookie,你可以随时提交部分填写的调查,并在稍后时间回你的答案,完成以后。”
在YAML conf文件合并哈希
YAML是相当方便的编写配置文件。 主要优点是,它像文本文件中读取。 这个作品真的很好,如果你的配置文件是平坦的(不分层),并没有重复。
如果您的配置文件中有重复,然后分离出这些元素和重用它们是有意义的。 我的意思是 - 让我们说你的配置文件看起来像这样:
发展: input_location:common_input output_location:dev_location 邮箱: smtp_server:您的服务器 登录:your_login 密码:top_secret 生产: input_location:common_input output_location:dev_location 邮箱: smtp_server:您的服务器 登录:your_login 密码:top_secret
假设上面的代码在/ tmp / test.yml这里你可以看到如何在Python和Ruby
$cat readyml.py
#!的/ usr / bin中/ env的蟒蛇 从pprint为PP进口pprint #Debian中需要安装python-YAML 从的YAML进口负载,load_all,转储 哈希=负载(开放(“/ TMP / test.yml的”)) PP(哈希['发展'])
$ cat readyml.rb
#!/ USR / BIN / env的红宝石 需要“PP” 哈希= YAML的::负载(的File.Open(“/ TMP / test.yml的”)。) PP哈希['发展']
这里是一个方便的Ruby版本的班轮
$ ruby -rpp -e 'pp YAML::load(File.open("/tmp/a.yml"))["development"]'或者你可以尝试在irb或Python控制台相同。
请注意,在上面的代码片断,一切都以外的输出位置是相同的开发和生产的一部分。 这是YML节点标识符来抢救。 想法很简单,有一组默认值和重写他们在不同的地方。
你可以把它拆开如下:
默认:与默认 input_location:common_input output_location:dev_location 邮箱: SENDER_NAME:发送方 smtp_server:您的服务器 登录:your_login 密码:top_secret 发展: <<:*默认 生产: <<:*默认 output_location:prod_location
$ ruby -rpp -e 'pp YAML::load(File.open("/tmp/a.yml"))["development"]["mail"]["login"]'
"your_login"
$
伟大的,它的工作原理(TM)。
可以说,我们交易有点像魔术,一些清晰度。 这里是一个小说明:&,*和<<: - 这是锚标记,可以理解为节点标识符,*是节点的参考和<<:哈希合并。
详细内容见或者YAML规格或维基
到目前为止,那么好,但有一个陷阱,在这里,这些哈希合并不是递归的。 它的意思是这样的:让我们说你要在两个环境不同的邮件发送者的名字,你可能会受到诱惑,做到以下几点:
默认:与默认 input_location:common_input output_location:dev_location 邮箱: SENDER_NAME:发送方 smtp_server:您的服务器 登录:your_login 密码:top_secret 发展: <<:*默认 邮箱: SENDER_NAME:sender_dev 生产: <<:*默认 output_location:prod_location 邮箱: SENDER_NAME:sender_prod
让检查
$ ruby -rpp -e 'pp YAML::load(File.open("/tmp/a.yml"))["development"]["mail"]["login"]'
nil
$
哎呀,出事了,上述问题是不是递归哈希合并,合并时,它取代默认的邮件,邮件只有一个关键的生产。 展开多层次的解决方案/工作大约是:
common_settings:&common_settings input_location:common_input output_location:dev_location mail_defaults:&mail_defaults SENDER_NAME:发送方 smtp_server:您的服务器 登录:your_login 密码:top_secret 默认:与默认 <<:* common_settings 邮箱: <<:* mail_defaults 发展: <<:*默认 生产: <<:*默认 邮箱: <<:* mail_defaults SENDER_NAME:sender_prod
让我们再次检查
$ ruby -rpp -e 'pp YAML::load(File.open("/tmp/a.yml"))["development"]["mail"]["login"]'
"your_login"
$
你说你多了一个嵌套级别,你绝对可以展开一个级别,但后来它变成一个烂摊子。 所以,如果你不尝试写河内塔在conf文件的解决方案,它是更好地挖成YAML或别的东西restucture比conf文件。 但是,这是你的电话了。
伟大的程序员找到简单的解决复杂问题
很长一段时间后,我能找到的源报价
初级程序员创建简单的问题简单的解决方案。 高级程序员创建复杂的解决方案到复杂的问题。 伟大的程序员找到解决复杂问题的简单解决方案。
这是一篇文章,呼吁由查尔斯·康奈尔美丽的软件 。
另一个我最喜欢的是Python的禅 -
美丽优于丑陋。
明确的是比隐含更好。
简单比复杂好。
复杂的是比复杂。
平板是优于嵌套。
稀疏较密集更好。
可读性罪名。
特殊情况下,是不是够特别,打破规则。
虽然实用性击败纯度。
错误应该永远默默传递。
除非明确沉默。
在模糊的脸,拒绝猜测的诱惑。
应该有一个,最好只有一个显而易见的方式做到这一点。
虽然这种方式可能起初并不明显,除非你是荷兰人。
现在是总比没有好。
虽然从未往往比*权*现在。
如果实现是很难解释的,这是一个坏主意。
如果实现是很容易解释,它可能是一个好主意。
命名空间是一个鸣喇叭伟大的想法 - 让我们做这些!
-------------------------
再有就是经典编程之道
-
学分链接网站
杰弗里·詹姆斯译
转录由杜克Hillard
转交Anupam Trivedi,Sajitha Tampi和Meghshyam Jagannath
重新HTML化的和由Kragen Sittler的编辑
-
本书第1 - 寂静的虚空
的编程大师如是说:
“当你已经学会从陷阱帧,抢夺错误代码,
将是你离开的时候了。“1.1
神秘的东西正在形成,出生在寂静的虚空。 等待单独与
一动不动,仍然是一次,但在不断地运动。 这是源
所有的程序。 我不知道它的名字,所以我将它称为陶
编程。如果道是伟大的,那么操作系统是巨大的。 如果操作系统
系统是伟大的,那么编译器是伟大的。 如果编译器是伟大的,
然后,应用程序是伟大的。 用户高兴和存在
在世界的和谐。编程之道流远,早上风的回报。
1.2
道生机器语言。 机器语言诞生了
汇编。生下汇编编译器。 现在有一万
语言。每一种语言都有其目的,但谦虚。 每种语言都表达
以阴阳软件。 每一种语言都有其内道的地方。但不要用COBOL编程,如果你能避免它。
1.3
在开始时道。 陶生下了空间和时间。
因此,空间和时间是编程的阴阳。总是不理解道的程序员的时间不多了
为他们的程序和空间。 程序员理解陶总是
有足够的时间和空间来实现他们的目标。否则怎么会这样呢?
1.4
聪明的程序员告诉陶,并遵循它。 平均
程序员告诉涛和它的搜索。 愚蠢的程序员
约陶告诉它笑。如果不笑,就不会有陶。
最高声音是最难听到。
展望未来,是一种撤退。
伟大的天才,显示自己在生命的晚期。
即使是一个完美的方案仍然有错误。-------------------------
第2册 - 古代大师
的编程大师如是说:
“经过三日不编程,生活变得毫无意义。”
2.1
老程序员是神秘而深刻。 我们无法捉摸
他们的想法,所以我们所做的一切是描述自己的外貌。知道,像狐狸过水。 提醒,像一般上
战场。 一种,像一个女主人,迎接她的客人。 简单的,像
呆若木鸡。 不透明的,就像在黑暗的洞穴黑池。谁可以告诉他们的心和头脑的秘密是什么?
答案只存在于陶。
2.2
超级大师图灵曾梦见自己是一台机器。 当他醒来时,他
惊呼:“我不知道我是否图灵梦见我是一台机器,或
做梦,我图灵机!“2.3
从一个非常大的电脑公司的程序员参加一个软件
会议后,报告给他的经理,他说:“什么样
程序员的工作,为其他公司吗? 他们表现不好,
与外表冷漠。 他们的头发长,蓬头垢面,
衣服是满脸皱纹,老。 他们坠毁好客套房和他们
在我的演讲粗鲁的声音。“经理说:“我应该让你参加这次会议,。 那些
程序员生活在现实世界之外。 他们认为生活是荒谬的,
偶然的巧合。 他们来来去去,不知道的局限性。
无牵挂,他们只住他们的节目。 他们为什么要打扰
社会习俗?“他们是活在道。”
2.4
一个初学者问大师:“这是一个程序员,他从来没有设计,
文件或测试他的程序。 然而,所有谁知道他,认为他是一个
在世界上最好的程序员。 这是为什么?“大师回答道:“那个程序员掌握了道。 他已经走了
超出了设计的需要;他不生气时系统
崩溃,但接受的宇宙,而不用担心。 他已经超越了
需要的文件;他不再在乎别人看到他的代码。
他已经超越了需要进行测试,他的每一个方案是完美的
在自我,平静而优雅,其目的不言自明。 诚然,
他已进入道的奥秘。“-------------------------
本书3 - 设计
的编程大师如是说:
“程序被测试时,它是为时已晚,使设计
的变化。“3.1
曾经有一个人去计算机展览。 因为他的每一天
进入,该名男子在门口的警卫告诉:“我是一个伟大的小偷行窃功勋闻名。 是
谅解,为这个贸易展会,不得逃避unplundered。“这个讲话扰乱警卫很大,因为有百万
美元的计算机设备里面,所以他仔细观看的人。 但
这个人只是从一个摊位逛到另一个摊位,悄悄给自己哼唱。该名男子离开时,警卫把他拉到一边,搜查了他的衣服,但
什么也没有发现。在展览会的第二天,男子返回,并斥责卫兵
他说:“我逃昨天满载而归,但是今天我会连
更好。“所以警卫更加紧密地看着他,但无济于事。在展览会的最后一天,警卫再也不能忍住他的好奇心
不再。 “小偷先生,”他说,“我很困惑,我不能住在
和平。 请赐教。 这是什么,你偷了吗?“该名男子笑了。 “我在偷想法,”他说。
3.2
曾经有一位编程大师,谁写非结构化的程序。 一
初学者刻意模仿他,也开始写
非结构化的程序。 当初学者问大师评价他的
进步时,大师批评他写非结构化的程序,
没有适当的说,“什么是适当的主
新手。 在超越结构化之前,你必须明白的道。“3.3
曾经有程序员一名军阀法院的
吴。 军阀问程序员:“哪个更容易设计:
会计包或操作系统吗?““操作系统”,这位程序员回答说。
军阀发出一声难以置信的惊叹号。 “当然,会计
包旁边的一个操作系统的复杂性是微不足道的,“他
说。“事实并非如此,”程序员说,“当设计一个会计包,
程序员的工作作为一种人与人之间有不同的调停
思路:它必须如何运作,如何其报告中必须出现,以及如何就必须
符合税法。 相反,一个操作系统不仅限于
外露面。 当设计一个操作系统,程序员
寻求最简单的机器和思想之间的和谐。 这就是为什么
操作系统是更容易设计。“吴笑着说。 “那都是很好很好,但
这是更容易调试吗?“程序员没有回答。
3.4
一位经理到编程大师,显示了他的要求
一个新的应用程序文件。 经理问大师:“多久
将它设计这个系统,如果我给你5个程序员呢?““这将需要一年时间,”大师说。
“但我们需要这种系统立即或更早! 多久
采取如果我给你10程序员呢?“编程大师皱起了眉头。 “在这种情况下,这将需要两年时间。”
“如果我给你一百个程序员呢?”
主程序员耸耸肩。 “然后设计将永远
完成后,“他说。-------------------------
书4 - 编码
的编程大师如是说:
“一个精心编写的程序是它自己的天堂;欠佳的书面程序
它自己的地狱。“4.1
一个程序应该是轻灵,像一个子程序连接
字符串的珍珠。 应保留方案的精神和意图
整个。 应该既不太少或太多,既不
不必要的循环也不是无用的变量,既不缺少结构,也不
至于僵硬呆板。一个程序应该遵循最小惊讶“`”。 这是什么法?
它仅仅是该计划的方式向用户应该总是回应
他至少让人惊讶。一个方案,不管多么复杂,应作为一个单一的单位。 该方案
应直接由内部逻辑,而不是由外表。如果该计划未能在这些要求,这将是在一个国家
无序和混乱。 只有这样,才能纠正这种改写
方案。4.2
一个初学者问大师:“我有一段时间运行一个程序,
有时中止。 我已经完全遵循编程的规则,但我
完全莫名其妙。 是什么原因呢?“主人回答说:“你困惑是因为你不明白陶。
只有傻瓜预计从他的同胞的人类理性的行为。 你为什么
期望从一个人类建造的机呢? 计算机模拟
决定,只道是完美的。“编程的规则是暂时的,只道是永恒的。 因此
你必须考虑涛之前收到的启示。““但问:我怎样才能知道当我收到的启示呢?”
新手。,“大师回答说:”你的程序将正常运行。
4.3
法师解释道的性质,他的一个新手。 “
陶体现在所有的软件 - 无论多么微不足道,说:“
主。初学者问:“是在一个手持计算器之道吗?”。
“是的,”他回答说。
“是道,在视频游戏吗?”持续的新手。
“即使是在一个视频游戏,”师傅说。
“道为一台个人电脑,在DOS”
主咳嗽,并略有改变他的位置。 “这个教训是超过
今天,“他说。4.4
王王子的程序员编写的软件。 他的手指跳舞后
键盘。 没有错误信息,程序编制的程序
像一个温柔的风跑。“好极了!”王子感叹道,“你的技术是无可挑剔的!”
说程序员转向从他的终端,“我”技术?“
遵循的是道 - 超越了所有的技术! 当我第一次开始的节目,我
会看到我之前在一个大规模的问题。 三年后,我没有
看到的是。 相反,我用的子程序。 但现在我什么也看不见。
我的整个存在在无形无效。 我的感觉是闲置的。 我的精神,
自由地工作,没有计划,遵循自己的本能。 总之,我的程序
写入本身。 诚然,有时也有难以解决的问题。 我看到他们
来了,我放慢,静静地观察。 然后,我改变了一行代码
和困难,像一阵轻烟消失。 然后我编译
方案。 我坐不住了,并让工作的喜悦。 关闭我的
一会儿眼睛,然后注销。“王王子说,“会,我的程序员都是明智的!”
-------------------------
预订5 - 维护
的编程大师如是说:
“尽管一个程序,但三线长,总有一天它必须
保持下去。“5.1
需要一个良好的使用门在铰链上的油。
迅速流动的流不增长停滞。
无论是声音和思想都不能在真空中传播。
如果不使用软件腐烂。这些都是伟大的奥秘。
5.2
经理问程序员多久,会带他来完成
程序上,他的工作。 “明天,将完成”
程序员及时回答。“我想你是不切实际的,”经理说,“说实话,如何
需要多长时间?“程序员想了一会儿。 “我有一些特点,我想
添加。 这将需要至少两个星期,“他最后说。“即使是太多期望,”经理坚持,“我一定会
满意,如果你只是告诉我,当程序是完整的。“程序员同意这一点。
几年后,经理退休。 在他退休的方式
午餐时,他发现程序员在他的终端睡着了。 他曾
编程整夜。5.3
曾经被分配到一个新手程序员编写一个简单的财务方案。
他疯狂地工作了很多天,但是当他的主人检讨
他的计划,他发现,它包含一个屏幕编辑器,一套
图形程序,人工智能接口,但
没有丝毫提及任何财务。当主对此问,新手成为愤慨。 “不要
等的不耐烦了,“他说,”我最终把财务的东西。“5.4
一个好的农民不会忽视他的庄稼?
一个好的老师不会忽视,即使最不起眼的学生吗?
一个好的父亲不会允许任何一个孩子挨饿?
一个好的程序员不会拒绝,以维护自己的代码吗?-------------------------
预订6 - 管理
的编程大师如是说:
“Let the programmers be many and the managers few – then all will be
productive.”6.1
When managers hold endless meetings, the programmers write games. 何时
accountants talk of quarterly profits, the development budget is about to
be cut. When senior scientists talk blue sky, the clouds are about to roll
in.Truly, this is not the Tao of Programming.
When managers make commitments, game programs are ignored. 何时
accountants make long-range plans, harmony and order are about to be
restored. When senior scientists address the problems at hand, the
problems will soon be solved.Truly, this is the Tao of Programming.
6.2
Why are programmers non-productive?
Because their time is wasted in meetings.Why are programmers rebellious?
Because the management interferes too much.Why are the programmers resigning one by one?
Because they are burnt out.Having worked for poor management, they no longer value their jobs.
6.3
A manager was about to be fired, but a programmer who worked for him
invented a new program that became popular and sold well. As a result, the
manager retained his job.The manager tried to give the programmer a bonus, but the programmer
refused it, saying, “I wrote the program because I thought it was an
interesting concept, and thus I expect no reward.”The manager upon hearing this remarked, “This programmer, though he holds
a position of small esteem, understands well the proper duty of an
employee. Let us promote him to the exalted position of management
consultant!”But when told this, the programmer once more refused, saying, “I exist so
that I can program. If I were promoted, I would do nothing but waste
everyone's time. Can I go now? I have a program that I'm working on.”6.4
A manager went to his programmers and told them: “As regards to your work
hours: you are going to have to come in at nine in the morning and leave
at five in the afternoon.” At this, all of them became angry and several
resigned on the spot.So the manager said: “All right, in that case you may set your own
working hours, as long as you finish your projects on schedule.” The
programmers, now satisfied, began to come in at noon and work to the wee
hours of the morning.————————————————————————–
Book 7 – Corporate Wisdom
Thus spake the master programmer:
“You can demonstrate a program for a corporate executive, but you can't
make him computer literate.”7.1
A novice asked the master: “In the east there is a great tree-structure
that men call `Corporate Headquarters'. It is bloated out of shape with
vice presidents and accountants. It issues a multitude of memos, each
saying `Go, Hence!' or `Go, Hither!' and nobody knows what is meant. 一切
year new names are put onto the branches, but all to no avail. How can
such an unnatural entity be?”The master replied: “You perceive this immense structure and are
disturbed that it has no rational purpose. Can you not take amusement from
its endless gyrations? Do you not enjoy the untroubled ease of programming
beneath its sheltering branches? Why are you bothered by its
uselessness?”7.2
In the east there is a shark which is larger than all other fish. 它
changes into a bird whose wings are like clouds filling the sky. When this
bird moves across the land, it brings a message from Corporate
Headquarters. This message it drops into the midst of the programmers,
like a seagull making its mark upon the beach. Then the bird mounts on the
wind and, with the blue sky at its back, returns home.The novice programmer stares in wonder at the bird, for he understands it
不。 The average programmer dreads the coming of the bird, for he fears
its message. The master programmer continues to work at his terminal, for
he does not know that the bird has come and gone.7.3
The Magician of the Ivory Tower brought his latest invention for the
master programmer to examine. The magician wheeled a large black box into
the master's office while the master waited in silence.“This is an integrated, distributed, general-purpose workstation,” began
the magician, “ergonomically designed with a proprietary operating
system, sixth generation languages, and multiple state of the art user
interfaces. It took my assistants several hundred man years to construct.
Is it not amazing?”The master raised his eyebrows slightly. “It is indeed amazing,” he
said.“Corporate Headquarters has commanded,” continued the magician, “that
everyone use this workstation as a platform for new programs. Do you agree
to this?”“Certainly,” replied the master, “I will have it transported to the
data center immediately!” And the magician returned to his tower, well
pleased.Several days later, a novice wandered into the office of the master
programmer and said, “I cannot find the listing for my new program. Do
you know where it might be?”“Yes,” replied the master, “the listings are stacked on the platform in
the data center.”7.4
The master programmer moves from program to program without fear. 没有
change in management can harm him. He will not be fired, even if the
project is cancelled. 这是为什么? He is filled with Tao.————————————————————————–
Book 8 – Hardware and Software
Thus spake the master programmer:
“Without the wind, the grass does not move. Without software, hardware is
useless.”8.1
A novice asked the master: “I perceive that one computer company is much
larger than all others. It towers above its competition like a giant among
dwarfs. Any one of its divisions could comprise an entire business. Why is
this so?”The master replied, “Why do you ask such foolish questions? That company
is large because it is large. If it only made hardware, nobody would buy
它。 If it only made software, nobody would use it. If it only maintained
systems, people would treat it like a servant. But because it combines all
of these things, people think it one of the gods! By not seeking to
strive, it conquers without effort.”8.2
A master programmer passed a novice programmer one day. The master noted
the novice's preoccupation with a hand-held computer game. “Excuse me,”
he said, “may I examine it?”The novice bolted to attention and handed the device to the master. “我
see that the device claims to have three levels of play: Easy, Medium, and
Hard,” said the master. “Yet every such device has another level of
play, where the device seeks not to conquer the human, nor to be conquered
by the human.”“Pray, great master,” implored the novice, “how does one find this
mysterious setting?”The master dropped the device to the ground and crushed it underfoot. 和
suddenly the novice was enlightened.8.3
There was once a programmer who worked upon microprocessors. “Look at how
well off I am here,” he said to a mainframe programmer who came to visit,
“I have my own operating system and file storage device. I do not have to
share my resources with anyone. The software is self- consistent and
easy-to-use. Why do you not quit your present job and join me here?”The mainframe programmer then began to describe his system to his friend,
saying “The mainframe sits like an ancient sage meditating in the midst
of the data center. Its disk drives lie end-to-end like a great ocean of
machinery. The software is as multifaceted as a diamond, and as convoluted
as a primeval jungle. The programs, each unique, move through the system
like a swift-flowing river. That is why I am happy where I am.”The microcomputer programmer, upon hearing this, fell silent. But the two
programmers remained friends until the end of their days.8.4
Hardware met Software on the road to Changtse. Software said: “You are
Yin and I am Yang. If we travel together we will become famous and earn
vast sums of money.” And so the set forth together, thinking to conquer
the world.Presently they met Firmware, who was dressed in tattered rags and hobbled
along propped on a thorny stick. Firmware said to them: “The Tao lies
beyond Yin and Yang. It is silent and still as a pool of water. It does
not seek fame, therefore nobody knows its presence. It does not seek
fortune, for it is complete within itself. It exists beyond space and
time.”Software and Hardware, ashamed, returned to their homes.
————————————————————————–
Book 9 – Epilogue
Thus spake the master programmer:
“It is time for you to leave.”
————————————————————————–
If you liked these, you may also like to read worse is better
A bit of shell redirection
Here is how we normally do shell redirection
$ ./pgm.sh args >out.txt 2>err.txt
I wanted to modify it a bit and run as follows
$ ./pgm.sh args
with the requirement that output and error should go to some filename computed inside pgm.sh based on args. One illustrative case could be when date is part of args. So you would like stdout to go to say /your/directory/pgm_out_YYYYMMDD.txt 1
The problem with standard way of redirecting N>file.txt ie, associating file descriptor N to file.txt , is that it works only for the newly forked process and not for the current process.
所以
$ echo hi 1>out.txt ; echo hii will send hi to out.txt but will print hii to stdout. 2
This is where exec comes to our rescue. If we add exec 1>somefile.txt then output from rest of the script will go to somefile.txt
$./test.sh will redirect hi as well as hii to out.txt
$ cat test.sh
#!/usr/bin/env bash
exec 1>out.txt
echo hi
echo hii
Similarly to redirect stdout as well as stderr we'll do something like this
cat test2.sh
exec 1>out.txt
exec 2>err.txt
echo out text
echo 1>&2 err text
somenoneexitent command
ls -ld /tmp
Now coming back to original point of redirecting to some file from inside the shell, let's say program computed the filename in some variable OUTFILE, we could have just done exec 1>$OUTFILE
That solves the current problem. But you may like to go through following example which achieves 'random access' of file in shell script. Example is from here
echo 1234567890 > File # Write string to "File".
exec 3<> File # Open "File" and assign fd 3 to it.
read -n 4 <&3 # Read only 4 characters.
echo -n . >&3 # Write a decimal point there.
exec 3>&- # Close fd 3.
cat File # ==> 1234.67890
With comments, this code is self explanatory.
-
1 It can also be done by $ ./pgm.sh args >pgm_out`date +%Y%m%d` but idea is to generate this file name based on some logic in program itself.
2 1 in 1>out.txt is redundant but it clarifies here that we are redirecting fd 1
Sony VAIO review
A month back I bought a vaio NS25G and have been planning to write this post since then. This post is primarily notes to self and review of the same. Let's get off the mark quickly -
Post has two parts -
I. Review of hardware
二。 Installing debian and things to setup
Since I am not a VAIO marketing guy, I'll start other way round -
Why you may not like to buy this laptop :
- No bluetooth : believe me, in 2009 sony sells laptop without bluetooth. Sure you can use usb stuff but …
- Screen size is 15.4 inches : if you travel a lot then this laptop may not be very handy and also 2.9kg laptop is not exactly the lightest around.
- No HDMI output.
- No separate graphics card and the likes.(and no dedicated video memory
Now , why you may like to buy it :
- This laptop is a damn good desktop. What I mean is this if your requirement is like me – mostly writing programs and trying to use it 25 out of 24 hrs, then with a big screen , extremely comfortable keyboard layout with spacious palm rest and good compute power , it makes a very good combination.
- It L2 cache is 2MB and processor/memory system bus are 800MHz. I don't play games so can't say about that but for anything else but a core 2 duo processor with 2GHz freq is good, this is more than enough.
- From my usage, I see processor mostly clocks at 1.2GHz, and memory usage ~500MB. That just reinforces previous point.
- Battery backup is good, ~2 hrs is what I get.
Just one more thing here – being Sony, it will cost you a bit than other laptops with similar configuration, but that is a call u have to make.
II. Configuring linux (to run out of box ! ) :
It came pre installed with Vista( I think home premium or some fancy name like that). Dungara booted once and created another partition of 150 GB. Debian testing is what I always install and then up(down?)grade to 'unstable' sid.
Things which worked without any problem:
- X - unsurprisingly X server had not problem with starting or resolution. After one of the upgrades X refused to start though, but 'X -configure' generated a conf file which worked pretty well.
- Audio - Audio output and external mic work fine. kernel version 2.6.29-1-686 #1 SMP and alsa version 1.0.17. This is what you get from
$ lspci -v |grep Audio 00:1b.0 Audio device: Intel Corporation 82801I (ICH9 Family) HD Audio Con1.0.17troller (rev 03) - Video cam – just works
- Hibernate to disk and back – no problem
- Wireless - in short – just works.
$ lspci |grep -i wireless
03:13:55 04:00.0 Network controller: Atheros Communications Inc. AR928X Wireless Network Adapter (PCI-Express) (rev 01) .
I think kernel 2.6..27 onwards it works with the stock kernel source. You dont have to install ndiswrapper or things like t
hat. As a note, please say good buy gnome-network-manager and welcome wicd, it is just a gui layer but behind the scene they have fixed lot of config stuff like wpasupplient and more.
What doesn't work -
- Somehow internal mic refuses to work
External mic works fine though. Latest alsa sources did not compile cleanly on debian, so for the time being I bought external Internal mic, will try to dig into it sometime in future though.
Few more misc hints for deiban:
- Package for devnagri font- ttf-indic-fonts
- Package for flash player – flashplugin-nonfree
- Entry in sources.list for mplayer and likes – deb http://www.debian-multimedia.org sid main
- Entry in sources.list for e17 – deb http://debian.alphagemini.org/ unstable main
- Entry in sources.list for skype – http://download.skype.com/linux/repos/debian/ stable non-free
oneliner for increasing and decreasing the brightness -
[root]prashant@vaio09:12 PM$ cat bin/incbrightness.sh
#!/usr/bin/env bash
echo $[1+`cat /sys/class/backlight/acpi_video0/brightness `] >/sys/class/backlight/acpi_video0/brightness
you'll have to put this in sudo though.
and to decrease change + to – and … you get the idea, right !
A bit more, if you use enlightenment(e17) here are few more hints -
[enlightenment key bindidings]
You can use following key code and mapping
mute :
KEY="Keycode-160" ACTION="exec" PARAMS="/usr/bin/amixer -q set Master toggle"
hibernate :
KEY="Keycode-165" ACTION="exec" PARAMS="sudo /usr/sbin/hibernate-disk"
volume decrease :
KEY="Keycode-174" ACTION="exec" PARAMS="/usr/bin/amixer -q set Master 2-"
volume increase:
KEY="Keycode-176" ACTION="exec" PARAMS="/usr/bin/amixer -q set Master 2+"
increase brightness :
KEY="Keycode-212" ACTION="exec" PARAMS="sudo /root/bin/incbrightness.sh"
decrease brightness
KEY="Keycode-101" ACTION="exec" PARAMS="sudo /root/bin/decbrightness.sh"



































