Liu 的个人资料唯有仰望是真实的照片日志列表更多 ![]() | 帮助 |
|
2006/8/28 blog spam in my eyesIt's been a while since i write something here, in case you worried(like that ever happens:), i was tighted up by the new job i got. Trying hard to make the work right and interesting as well and live up to my own dreams.
I didn't really begin to write this blog until June, and after the first few post, i find someone i didn't know post his sites on the comment. I didn't have a clue what's going on back then, thought it was just some people maybe have same interest in web dev show off.
After i post a hell lot of stuff here, and i start to find some trackback from some weird site, I didn't know what that two, just find their sites with nothing but ads from google or other. And the live space lauched, now i can see the stat. I find out a lot of the traffic here is brought from the search engine mainly google and baidu. There's even about 30-40 visit per day.
You may wonder what the heck all this to do with blog spam, hehe, you are feeling what i'm feeling when i first understand this. The first pic below show how they work.
Quote from the presentation of the Charaterizing the SPlogoshere by Tim Finin etc. from UMBC, the second pic to the fifth pic showes how hot the blogoshpere is, spams in the blogosphere, where are they from and why are the a problem.
And the motivation needs no pic to say, to host ads, to index affiliates, and to promote pagerank.
reference about this, and is highly recommend readings if you're interested are
and reference and papers on their page.
2006/8/21 Digg.com:投票的动力因素分析(zz)学子论文:Digg.com:投票的动力因素分析――一个公共选择的视角中国人民大学 新闻学院 易正林摘要:一般而言,在公共事务领域,人们都存在“搭便车”的习惯心态,而对投票采取冷漠和理性的“无知”态度。但digg.com这个网站似乎打破了这样的特性,总有大量的用户进行投票。本文从唐斯的投票“收益-成本”模型入手,分析digg网站用户投票活动的背后驱动因素。认为它在总体范围内降低了成本,而由于投票效果的可叠加性和diggspy的直观性,投票的收益预期大大提高,而获利概率也得到了提升,由此,用户获得了投票的动力。当然,文章也从用户的团体策略方面分析了负向的制约因素。 关键词:digg.com 公共选择理论 唐斯投票模型 说到digg.com这个网站,很多人都会惊叹它的成长速度。2004年10月,digg开始设计、开发,创始人Kevin Rose。2004年10月,发布第一个测试版本。2004年的11月5日,正式发布。而11月17日,有关它的新闻就登上了老牌技术类新闻社区slashdot的主页。2006年4月,Alexa数据显示Digg的流量已逼近并超过了同类网站Slashdot (详见文末图表),甚至有人就此预言slashdot将会逐渐走向没落。 一个网站为什么能够这么迅速地窜红呢?作为新兴起的网站,Digg有一些自己鲜明的特点,我们先从它的特点进行分析。它的个性特征主要表现在以下几个方面: 1、会员发布主题,由其它会员进行投票,得票多的可以进入主页,否则只能在队列中等待直至最后被淹没,但文章不会被删除。在Digg网站中,主页会显示部分文章,这些文章是获得了较多支持(对一主题的支持方式是为其投票,即“Digg”某个主题,网站把投票称为“Digg”,相反的过程时“bury story”,即埋葬主题)才能到主页的,而其他文章则在“队列”中,如果有足够多的支持,它的位置就会向前,否则也只能在大量的文章中被淹没。当然,以给文章即使被淹没了也不会被删除,它依旧可以被搜索到。 一般认为digg的做法是一个用户驱动(user driven)的模式,而老牌的科技类新闻社区slashdot则被认为是管理员(moderator driven)驱动[1]。 2、基于账户的管理。在digg中,投票并不完全是随意的,只有注册后的会员才可以投票,当然,这种注册并不完全是没有作用的,注册后,所有用户digg的内容都会出现在自己的账户中,也就是说,digg过程也是一个收藏的过程。在整理收藏内容的过程中,可以结合社会书签进行分类,也可以便于他人进行检索。 3、blog,rss,bookmarking三者结合。 投票来决定首页内容并不是digg的创新(如大众点评网和imdb),但最彻底的投票决定选题的是digg,同时结合了社会书签、blog等功能的也是它。 在digg中,用户完全可以通过一个主题找到所有digg或者dugg了这一主题的所有人,dugg是一个和digg相反的过程,即在digg一个主题后,如果觉得该主题没有意思或者没有作用,可以用dugg将其从自己的收藏中删除。同时,也可以找到所有把这一主题放到自己博客的所用用户。而从一个用户出发,也可以知道他digg或者dugg过的所有的主题。当然,任何用户也可以把某一个主题放到自己的博客或者发邮件给朋友。这样,就形成了主体和用户为中心的横纵社交网络,并且通过RSS互链,可以预社区外的博客以及其它网络形式形成更大范围的互链互通。 从上面分析可以看出来,digg最大的特点在于它的投票机制。即使是他的社会书签、RSS等也是和投票紧密相关的,所以本文的目的就是分析为什么digg通过这样一种投票机制能吸引到那么多的访问者。先来看看digg投票的基本情况: 首先,只有注册后的会员才享有投票资格,在投票方式上实行直接投票制,每个人所投的票都是等值的。因此,是一种多数同意规则:digg者越多,文章越有可能出现在网站首页,否则会停留在队列(queue)中。 其次,在同一时间内,同一用户可以就多个主题进行投票,每一个主题都进行digg或者bury story的判断。 第三,投票结果是被记录的,会直接形成个人收藏页面,并且这种收藏是开放的,其他网民可以随时通过用户名检索到他收藏(投票)的所有内容。 第四,Diggspy实时直观地显示投票结果,在这个页面,用户可以动态地看到每一个主题在被别人投票时暂时蹦到最前面时的场景。 最后,Digg某一主题后可以有一个相反的dugg过程,即如果认为该主题没有意义,可以用这个方式删掉它。 公共选择理论[2]有这样的假设:“人都是自利的、理性的效用最大化者;……政治领域中,个人也同样扮演者经济人的角色,个人的行为和决策同样是在理性地进行成本分析和收益分析后,才作出的选择或决定,同样也是在追求某种最大化效应。[3]”既然个人是自利的,那么,个人投票行为也应该是在成本和效益分析后,自利和理性的投票者做出的决策。 Digg网站是一个科技类新闻社区,因此,公共性非常强,而就公共性主题进行投票的时候,根据公共选择理论,积极性是不高的。有人称之为投票过程中的“无知”和“冷漠”现象[4]。在公共领域,任何一件物品和每个个体都相关,但相关并不明显,相关度也不同,因为多数决定原则下,一个人的投票是不会对自己有实质性的和即刻性的效果的,故投票积极性不高。而在公共物品的选择过程中,个人投票对于结果也可能没有明显的可以预期的后果,因此,投票者会采取冷漠的态度。由于成本付出后可能弄不清楚该选择哪个结果,也可能投票后得不到符合意愿的投票结果,从而,理性的投票者可能采取理性的“无知”策略,根本不去了解或者装作不了解而逃避责任。 问题是,为什么digg的用户们没有采取“冷漠”和“无知”的策略呢?在成本和收益之间,是什么收益吸引了他们? 在投票的成本和收益分析方面,美国学者唐斯提供了一个投票行为的函数模型[5]――R=BP-C+D 。在这个公式中,理性投票者的投票行为可以通过其投票预期收益和选民投票时的个人偏好两个方面来说明。其中: R=投票者行动(投票、搜集信息)R=0则表示投票者将弃权;如果R>0,则表示投票者将参与投票。而且对于候选人来说,谁出的R大,也即谁许诺的收益更大,并能为选民接受,一般选票就会流向他这一方。 B=投票者行动的潜在收益 P=投票者进行该项行动时这些收益产生的概率 C=投票者行动的成本 D=作为投票者行动补充的私人收益(投票获收集信息活动产生的额外收益,如与人接触、沟通的愉悦或其他心理上的收益等) 一般而言,由于投票结果是公共物品,就会有人想尽可能不参与投票而享受收益,这种“搭便车”行为的结果是B与P处于反向变化之中,BP的乘积可能很小,这意味着投票参与带来的享受价值D和成本C支配着投票行为[6]。但在digg中的收益和成本分析结果会如何呢?即唐斯公式中的B、P、D、C各项如何呢? 1)投票成本。digg的投票成本组成如下:注册/登陆成本;信息成本(了解网站和了解具体文章);机会成本;页面等待造成的时间成本等等。可以发现,这些成本在日常的网页浏览中都是很难避免的,也就是说,在成本上,digg的成本并没有特别高也没有特别地低。但它在成本的支付和计算上有一些很鲜明的特征: 在首次使用上,digg的成本偏高,因为digg是一种全新的社区类型,很多人在初次接触是很难理解其运行原理和机制,因此需要一定的时间进行熟悉和了解。但是,如果熟悉了之后,和其他注册网站比,并没有更多的成本需要付出,尤其在采用了firefox插件以及熟练程度提高后,投票成本递减,可以说,成本和收益的比值随着参与程度的深化而缩小。 收藏功能结合web2.0的标签功能,使得到投票后得到收藏的主题有更好的组织,整体上降低了成本。参与投票的过程其实就是一个自己选择自己喜欢内容进行收藏和分类的过程,因此,从总体上来说,成本在更大范围内被冲淡了,而收益则增加了,因为收藏网页和投票的活动二而一了。可以说,digg的经营过程中,已经突破了投票这一活动,而是把投票和其他网络活动连接起来 在digg中,投票成本和正常的博客浏览等行为已经实现了无缝对接,除了上面所说的和收藏主题结合外,对积极分子而言,社交网络的留言功能和RSS等功能都让用户在更大的范围内支付成本,可以把主题链接到自己的博客,减轻自己博客写作成本,也通过digg最新的资讯增强博客的可看性,如国内比较出名的博客如“keso(洪波)的博客”、“幻灭的麦克风”[7]中有大量文章直接来自或受启发于digg,digg直到现在还是他们重要的信息来源;此外,同时可以通过主题寻找其他和自己兴趣相投的用户,比如可以寻找和自己digg内容相近的人作为好友等等。 总之,成本的支付通过与其它网络活动的无缝连接而在更大范围内进行支付,针对digg的成本支付自然就小多了,比如,用户本来要收藏一个网页也需要成本,而digg本身就是收藏的过程,这样,两个成本就合一了,成本支付感自然也就变弱了。 2)个人收益分析。Digg首先具备了普通媒体的效用,例如监测环境、提供娱乐等等;其次提供了一个社交环境,可以找到和自己去为相投的好友,好友可以根据主题的选择进行组合,而也可以通过好友对主题进行组合;第三,在digg过程中,通过投票和发布自己的主题,可以让自我品味与价值观经受大众的检验;第四,可以通过收藏存档材料;最后,对于网站、博客而言,可以通过它进行宣传,让很多的人在短期内了解到自己的网站并带来相当可观的流量[8]。等等。但digg中投票活动的收益获取有自己的一些鲜明特点。 digg的投票过程中自我体验更强些,和同类网站slashdot也有很大区别。slashdot往往把社区讨论作为自身特点,而digg则尽管也具备社区性特征,而且社区功能也很强大,但更多是个人中心的,而不是公共论坛性质的社区,无论是交友的连接方式还是文章发布以及digg行为,都充分地体现了个人利益的选择,因此,个人收益占的比重比较大,从而也对公共事务投票行为的冷漠态度起了一定的制约作用。个人收益和公共的潜在收益重合后,促进了投票行为的发生机率。 3)潜在收益*收益产生概率分析。潜在收益和个人收益最大区别在于潜在收益是一种公共收益,不具有排他性。它主要体现在作为信息发布公共平台这一功能上,能提供最新、最前沿的资讯。例如一个很有意义的主题被digg到了主页,投票者的贡献是不容置疑的,但其他所有人也能够同时看到。正因为公共产品的非排他性,参与这就有了“搭便车”的想法,同时由于多数决定的原则,潜在收益和收益发生概率的乘积往往很小,以致在很多人的分析过程中是忽略不记的[9]。但在digg中,潜在收益和收益发生概率的乘积似乎也不小: 首先,单个投票者可以在短时期内就大量主题进行投票,由此个人收益可以进行叠加和放大。一般认为,在多数决定的投票行为中,投票者倾向于认定自己的投票对结果是没有明显效果的,从而对投票采取冷漠的态度。而在digg投票中,尽管但次投票都只是一个是否“digg”的判断,但由于可以多次投票,投票的挫败感会更微弱些,总有部分投票可以反映自己的偏好,因此,投票的获利概率在多次投票中得到了叠加,获利的预期也更大。 其次,由于多次投票可以让个人偏好得到最大程度的实现,投票时面临的交错压力更小[10],所以,无形中也更容易提升对预期获利的期待。 此外,由于diggspy的作用:直接、实时显示投票结果,可以同时增大投票者对收益发生概率的认识,同时,如前文所述,直观的、跳动的投票结果本身就显示了投票的暂时效用,尽管个人的投票未必能决定最终的走向。 最后,digg.com作为信息发布平台,其潜在收益就是一般媒体的消息发布等功能,因此,潜在收益和个人收益之间重叠度较高,如传统媒体监测环境、传播知识的功能等等,其实也是个人的收益。二者重合后,冲淡了参与者搭便车的心理。同时,多次投票也可以冲淡潜在收益的遥远感或距离感。 总之,通过一些技术手段,digg.com实现了成本和预期收益比值的最小化。从而吸引了大量的投票者。此外,结合了主题收藏功能、会员制、web2.0的社会书签等功能,digg.com在更大范围内降低了投票成本,也提高了用户对网站的粘着力。 当然,digg先行的投票机制也不是总是存在着正面的动力,负向的动力也是存在的,它们制约着用户的投票热情。 负向动力主要体现在以下几个方面: 1)团体策略:在digg的用户群中形成更小的团体,进行不正常的群体投票。如:4月19日,Forevergeek.com 的 Jacob Gower 发现,Digg 上两条新闻的最初投票人16人完全相同,也就是说,同一帮人对刚刚出现的两条新闻都投了票,这显然不是巧合。更奇怪的是,网站创始人Kevin Rose 也出现在其中。Jacob Gower 在他的博客中记录了这个发现,当有人把这个链接提交到 digg 时,总遭到拒收。Jacob Gower 本人在 Digg 上的帐号随即被封。这件事情在4月27日的 Guardian Unlimited 上得到了报道。这一事件出现后,一些用户就在这个帖子后面跟帖表示要退出digg [11]。 2)选票交换:选票交换也属于团体策略之一。交换在有的时候对总体福利有增益,但本质上会腐败投票过程。因为交换过程可能为利益集团所控制,而且,即使是对总体有利,它对合作外的其它个体还是有损害的 [12]。 3)作弊式的digg行为:从slashdot时代开始,只要一篇文章在主页上出现,文章所在网站的流量都能够在短期内飙升,前面已经提到过,往往可能因为一篇文章上了首页可能带来导致服务器瘫痪的流量。因此,处于推广网站的目的,作弊投票在所难免,而这也是digg的技术人员需要进行解决的问题。 通过以上的分析,我们可以看出digg.com的成功在于以下投票方面的因素:投票成本的降低(实际的和感觉上的);大量投票对个人偏好的照顾;diggspy的实录式投票结果展示。当然,面临的反作弊、反垃圾、控制小团体行为等方面还有多困难。 附录: digg在2006年赶超slashdot的材料,包括页面访问量、流量、访问人数三个项目。数据来自Alexa 。[13] ![]() ![]() 注释: [1]Ithink’s blog就持这样的看法:“slashdot采用的是管理员驱动的机制:用户提交新闻,管理员审阅后决定这些提交的新闻是否出现在slashdot的主页上;而digg采取的是用户驱动的机制,它设置了一个新闻源的缓冲,用户提交的新闻首先进入这个缓冲,如果认同这一新闻的读者足够,就会从缓冲中脱颖而出,出现在digg页面上,否则就逐渐被挤出新闻源缓冲。说的直观一点, slashdot由管理员控制,而digg则将权力下放给用户。”详见http://yackol.com/blog/2005/11/digg.html [2]布坎南认为“公共选择是政治上的观点,它从经济学家的工具和方法大量运用于集体或非市场决策而产生”(详见陈光金中译《同意的计算――立宪民主的逻辑基础》中国社会科学出版社,1999年 P16)。一般认为,公共选择包含两层含义:一是集体性。单个人自己的决策不在考虑范围之内,但凡是有人群的地方集体决策就不可避免,因而公共选择成为必需的;二是规则性。决策就是指定规则,在人与人之间存在偏好差异的情况下,必须决定规则以使人们的行为协调起来,因此,人们必须进行决策以选择那些能够反映和满足一般人偏好的规则。 [3]杨先保《选民投票的政治心理分析》,《武汉理工大学学报》2006年第4期 [4]高建富《公共选择中投票者“无知”和“冷漠”现象及其克服》,《三明高等专科学校学报》2001年第12期 [5]丹尼斯?缪勒著,杨春学译《公共选择理论》,中国社会科学出版社1999年 P425 [6]对于这一点,即“搭便车”的心态和行为,奥尔森“集体行动理论”有过非常经典的解释。详见赵鼎新《集体行动、搭便车理论与形式社会学方法》,《社会学研究》2006年第1期 [7] 网站地址分别为http://blog.donews.com/keso和http://www.kenwong.cn/ [8] 这一点在slashdot上也存在,曾有因文章出现在slashdot而服务器崩溃的情况,digg在11月17日上了slashdot就被视为成功的转折点之一。比较而言,digg可自行将文章作为主题粘贴,不需要管理员审核,但也能带来巨大的访问量。有人统计,有网站曾在一天内接受到digg带来的38450 位独立访问者, 295388次页面查看和100万左右的点击。见http://www.portableplaylist.com/blog/2006/04/surviving-digg-effect.html [9] 如林清伏、王伊景在《人大代表投票行为的制度经济学分析》一文中就指出二者可能朝相反方向发展,从而二者的乘积会非常小。见http://www.npcnews.com.cn/gb/paper8/7/class000800001/hwz182283.htm。而这“意味着投票参与带来的享受价值D和成本C支配着投票行为。” [10] “交错压力”为人所熟知是从拉扎斯菲尔德的《人民的选择》开始的。指这样一种状况:“(1)选民具有众多角色,这些角色可能在一些问题上彼此互相冲突,(2)选民具有众多偏好,这些偏好通常不能通过仅仅选择可选择的方案之一而得到满足”,也被用来解释“为什么一些投票团体选举参与率较低”。详见拉斯?斯沃桑《关于影响和投票的交错压力架设》,载斯坦因?U?拉尔森主编 任晓中译《社会科学理论与方法》,上海人民出版社,2002年,P263-264 [11]记录地址http://forevergeek.com/news/digg_corrupted_editors_playground_not_userdriven_website.php [12] 帕特里克·敦利威著 张庆东中译《民主、官僚制与公共选择――政治科学中的经济学阐释》,中国青年出版社,2004年,P42-50 [13] Alexa 排名是目前常引用的用来评价某一网站访问量的一个指标。事实上,Alexa 排名是根据对用户下载并安装了 Alexa Tools Bar 嵌入到 IE 等浏览器,从而监控其访问的网站数据进行统计的,因此,其排名数据并不具有绝对的权威性。但由于其提供了包括综合排名、到访量排名、页面访问量排名等多个 评价指标信息,且目前尚没有而且也很难有更科学、合理的评价参考,大多数人还是把它当作当前较为权威的网站访问量评价指标。 2006/8/18 interesting ruby on rails jobSoftware Developer at Nature Publishing GroupLocation: New York, NY Description To apply
Ruby on Rails developer at A leading Investment BankLocation: New York Description To apply Python in Google Code Jam太high了,乐坏我了...
All Things Pythonic
Python in Google Code Jam by Guido van Rossum August 14, 2006 Summary
For a number of years, Google has run a yearly coding contest named Code Jam. The smartest (young) programmers in the world compete against each other for prizes and fame. There are 3 online rounds (September 5-6, September 14 and September 19). The top 100 will be invited for the final coding showdown at Google New York on October 27, 2006. All travel and accommodation expenses will be covered by Google and there will be over $165,000 in cash and prizes. What's most exciting for me is that this year, for the first time, Python is one of the supported languages. (The others are C++, Java, C# and VB.NET.) I'm hoping that at least some of the finalists will get that far by exploiting Python's superior coding speed! (Googlers, others involved in setting up the competition, and their families, etc., etc., are not allowed to participate, as is customary in such things.) 2006/8/13 King and The Clown今天看了King and The Clown, 感觉字幕的翻译很差劲,可自己听不懂韩语,所以只能如此了。说说感受吧,以前看到的一些同性恋题材的东西总是觉得很压抑,都是千篇一律的不受社会认可,然后他们/她们自私的,无情的对待别人,然后是很多的直接的sex场面或是隐场面。可能这很符合西方人的文化或是他们的社会接受,但相对东方人来说,我觉得King and The Clown在艺术性和思想性上远远超出了,因为我看的时候很感动,能够骗到观众眼泪的艺术作品是伟大的艺术作品我相信。因为在那样的背景下,他们的反抗是与统治阶级的斗争融合的,他们的感情流露是那么的含蓄和自然,那一段布娃娃的戏可能是最好的表现。也许李安是很明白这个的,所以他的bbm是西方人的故事给西方人看,骗西方人的眼泪和小金人。
还有就是我不知道韩文的标题是什么意思,但我觉得英文的这个比中文的要好很多,因为至少不与整个思想有矛盾。 yet another cool python jobToday i add the planet python and www.planetpython.org to my google reader feeds, pretty cool. Google reader is a nice way to keep track of all the feeds, but it's not perfect, i will write one when i cann't stand that. If you read the post before, you will notice that i post a job ads of DreamWorks from jobs@python, today i saw that Disney Animation also posts their ads there, copy to here just for fun.
Disney Animation (Burbank, CA, USA)Posted 11-Aug-2006 Job Description: Disney Animation combines the very best in artistry and storytelling with cutting-edge technology to bring wonderful new characters to the big screen for audiences around the world. Constantly challenged to create innovative new technologies for animated features, theme park productions and special projects for the Walt Disney Studios, Disney Animation is home to some of the most talented artists working in the film industry today. Our team is currently hard at work on MEET THE ROBINSONS, which comes to theaters on March 30, 2007. We have an exciting opportunity for a Linux Software Development Engineer to join the team at our Burbank, CA studio. We are seeking a Software Development Engineer with experience in systems level programming and interfacing software applications with UNIX systems. Experience with Linux operating systems, compilers, libraries, and troubleshooting kernel issues are required. The individual will be highly analytical, solving development and integration problems among many internal and 3rd party software products. Candidate will be responsible for maintaining internal build system. The successful candidate will also be able to contribute to software application development and support using Perl, C++, C, UNIX shell scripting, Python and Java. Experience with databases (maintaining and programming) and knowledge of web, systems and network architectures are highly desirable. Qualifications
Strongly Desired
Desired
We look forward to an opportunity to work with you! Disney Animation is part of the magic of The Walt Disney Company. Short descriptions of position, requirements, company - break into sections if desired. 周末小事记周五上午就办完手续回家了,着实享受了一下大礼拜的感觉。拉小亚去吃川渝情,一年前在那吃了一次,那天小井同学回来本来打算在那的,结果由于时间问题换地方了,不过昨天吃的满不错的,比较好吃,就是酒水偏贵的说,估计害的小亚一定吃的比较郁闷。
胖的不行了,被好多人b4了,以前从来没有胖过的人,现在整天吃了就坐那,肚子上的肉啊堆得不行了。于是今天跑到54去锻炼身体,跑了一圈然后和别人打了会篮球,喘的那个,玩了没多久就不行了,然后赶骑车回来,身上都被汗打透了,洗了澡坐那还流了好久的汗。这样可不行,以后要坚持锻炼了,过年回来舅妈就谆谆的对我说要锻炼啊要锻炼,没认真对待...有想法找个合适的地方办张卡,每天逼着自己去运动运动,还是能改善心情的。
想洗了澡拉小井和段伟去吃饭,结果一个在家一个出去high了,真失败,就自己又跑到门口老家肉饼吃的那个还不错的凉面。
吃完饭心想出去转转,就骑车到财智那,然后到盈都,再从盈都回到第三极,看看路况和时间。发现财智那里的健身地方不错,列入考虑对象。盈都还是有些远,骑回来到第三极花了22分钟,是到财智的一倍距离。看来要办张卡了,不知道那个卡能不能用一代身份证办,不能的话还比较麻烦。
到第三极去蹭书和冷气,呵呵,还到地下餐厅办了张卡,东西还是稍有些贵,尤其是饮料,抢钱的说。不过饭菜满多样式的,可以去那吃晚饭了。跑到7层去看书,人都很少,所以可以在那个晃晃椅上看书,high极了。找了几本游戏设计开发的书看,下面来说说。
首先看那个游戏中的物理学(Physics for game developers), 台湾人译的,有些单位和说法不太一样,基本上讲的都是力学,看起来很亲切,想到两个事,一就是要是我们的课程能和书中这样应用结合的这么好的话,一是sunzx说我的,只要是老师教的都不好好学:P
一个是Ultimate Game Design: Building Game Worlds, 这本书太赞了,翻译的一般,但书的内容太吸引人了,作者对游戏开发领域的方方面面非常清楚,能有这样的人来介绍一个领域真是一件幸福的事,里面每张后都会采访相关内容的大家,听他们来谈游戏设计与开发的看法,非常的有帮助。想对game industry有个big picture的话,这本书非常的适合,帮助我形象化了这一切。
还有就是Hacking exposed: Network Security Secrets 5th Edition,中文不知道是不是和以前翻译的是同一帮人,Notice the patterns, 我又在看一本翻译的书,好像第三极这些好书影印的都很少,了解我的朋友都知道,能找到原版的我很少会看翻译的,因为原版的看的快。这个第五版相对于我读的第二版有了一定内容的修改,添加了近几年的几个漏洞和病毒的论述,对出现的一些新技术和趋势进行的讲述,比如搜索引擎的利用,比如专门讲的mac os x的安全问题等等。btw: 感谢当年sunzx的那本第二版,使我对这个领域有了丁点的了解和很大的热情。
还扫了几本认为有些意思的书,时间不够,就没能仔细看了,下次去吧。
和上次去的时候一样,他们那个查询系统还是搓的没法用,考虑和他们商量,我帮他们改善查询系统,他们给我vip权限,可以借书看和影响进书选择的,能够对他们的数据做分析来提供商业策略的资询,哈哈,yy中... 2006/8/12 PDX.pm's OSCON Roundup(zz)for all the geeks out there
PDX.pm
Fellow Portland Perl hacker Chris Dawson has just uploaded the OSCON Roundup podcast to the PDX.pm podcasts archive. On Wednesday night, 09 August, the Portland Perl Mongers shared their new knowledge and experiences attending, volunteering, and organizing OSCON 2006. There are several good nuggets of information there. Make Your .vimrc Trivial to Update(zz)Sweet tip
In a recent post on the Perl QA mailing list, David Golden showed off two lovely Vim bindings to load Vim’s configuration file in a buffer for editing, then to reload that file in the current Vim process.
I had to modify this to replace It’s much easier to experiment with writing new bindings in Vim itself, rather than through the This tip has already made me much more productive. Thanks, David! Post OSCON I: The darker side of speaking(zz)I used to speak at our own lcp(Linux Club of Peking University) for some time and attend a lot of presentations of our lcp, also some other speaks and lectures, presentations a lot on a broad topics. From the post before this one, I said that Jobs is one hell of speaker, and through out his keynote, you can find some of the aspects which can be made textbook. I thought i have a good sense of what's a great speech/lecture/presentation, but this article sure broaden my mind.
Three years ago I remember sitting in a session, one of many, and thinking how cool it would be to be a speaker at OSCON. I mean seriously, OSCON is the best software conference in the world, who wouldn’t want to be a speaker? As speaker, you join an elite group of software enthusiasts and it looks great on your resume (not to mention the great parties…). I’ve been fortunate to realize my dream for two years in a row now. This year was a dream come true as I was able to provide not only a session, but a tutorial as well. I’ve really appreciated the opportunity, and thank everyone who attended my talks. More importantly, I thank my co-presenter Joseph Hill. Without his contributions and technical expertise, my dream would have never materialized. So while I’ve been able to realize my dream, I see myself in many other convention attendees. I see them thinking to themselves about speaking at OSCON at a future date. So let me share something I’ve come to appreciate these last two years. Speaking at a convention like OSCON is not without its sacrifices. Perhaps the biggest sacrifice of all is missing out on the convention itself. Sure, there is a lot of work preparing slides and whittling your message down to its most simple and concise form, but for most speakers, speaking during the convention means you’ll miss most of the convention. My experience has perhaps been more extreme than most. So far, in all of my OSCON talks I’ve collaborated with Jospeh Hill, founder of Mono Live. While we always try to prepare as much as possible before arriving, he lives in Texas and I live in Puerto Rico. So the only time we have to practice is when we arrive in Portland. Most of our conventions have been consumed with practicing our talk, perfecting our demonstrations, and synchronizing our interaction. This year we spent all of Monday, Tuesday morning, and most of Wednesday working on our talks. From interacting with other presenters in the speaker lounge, I would confess that our final preparations are extreme, but not uncommon. Even Damian Conway in his “Presentation Aikido” recommends extreme practicing prior to a talk. You might be thinking, well if I had the opportunity, I would arrive prepared. Yeah right! Larry Wall of Perl fame has long confessed that the reason he wrote Perl was because of being lazy. Let’s face it, if you are going to speak at a conference, it is most likely an extra workload on top of your day job, and probably on top of your evening pursuits. From what I’ve seen from other speakers, it is very common to arrive in Portland, ahhh, let’s just say not quite ready for your presentation. Of course, I take speaking very serious. Once again, to borrow from Damian, speaking is a honor. When people attend your talk, they are giving time from their precious lives, so don’t suck away their lives for nothing. I try not to, and I hope the results show that extra effort. That extra effort meant this year that I missed all of OSCamp, I missed almost all of the keynotes, and only attended one session before my session talk. I would not have wanted to miss the opportunity of speaking, but just know that if you enjoy attending OSCON, you might want to consider what you might have to sacrifice to make your dream happen. I can’t say what my future holds, but I think that next year, I’ll take a rest and just enjoy the show; because what a great show it is! A little adviceIf you are going to take the plunge, then I’d like to share from my experience some tips. All the way from proposing talks to your final delivery, here is what I’ve learned these last two years.
看完了wwdc06的keynote其它的不说, Jobs同学的演讲水平确实很不错, 那几个vp上来的也说的很不错, 尤其是b4 vista的那个人, 超强
apple作为一个软件公司, 我认为它了不起的地方在于它很懂用户的需求, 他很在乎用户的体验, 很有创新的精神, 酷酷的感觉, 这正是我喜欢apple的原因;-) Untwisting Python Network Programming(zz)Update: Kendrew had post the bug report on twistedmatrix, http://twistedmatrix.com/trac/ticket/1988
This is a fairly basic introduction to the python network programming, the author managed to give a nice big picture based on the three protocols . The part interests me the most is that he had to use a recursive callback to do_retrieve_msg, which is pretty hackie and i don't really get why it's not work for collecting the Deferreds of multiple calls to retrieve of POP3Client in a DeferredList, this needs some experiments.
Published on ONLamp.com (http://www.onlamp.com/) http://www.onlamp.com/pub/a/python/2006/08/10/untwisting-python-network-programming.html See this if you're having trouble printing code examples Untwisting Python Network Programmingby Kendrew Lau08/10/2006 Networking is an essential task in software applications nowadays. Many programming languages have support for network programming to various extents. While the core libraries of most languages allow low-level socket programming, other libraries and third-party extensions often facilitate higher-level Internet protocols. For example, Java has a standard API to access sockets and send emails (via the Python is an exception--it has very good built-in support for both socket and various Internet protocols, including POP3, SMTP, FTP, Telnet, and Gopher. The Python core distribution contains many networking modules, such as This article introduces basic client-side networking using both core Python modules and the Twisted framework. For its example, I will show how to send, receive, and delete emails, and conduct Telnet sessions. I have written two functionally equivalent examples, one using the core modules (mail-core.py) and another using Twisted (mail-twisted.py), with both start, stop, and interact with a server to process emails. These programs work with any standard-compliant SMTP and POP3 servers in sending and retrieving of emails. The starting and stopping of server are specific to the Apache James mail server, which I choose as a local testing server due to its ease of installation and its shutdown procedure in a Telnet session. Sending Mails with smtplibThe core module
The This testing server accepts and relays emails from anyone, and this is the default configuration of the Apache James server. Although it is fine for a local testing server, most, if not all, SMTP servers in the Internet mandate certain security measures to fight spam. To use a Retrieving Emails with poplibRetrieving emails is inherently more complex than sending: it involves identification of the user, getting the number of messages, and retrieving or deleting the messages. The
Like the SMTP class, you can create a To get the number of messages in the server, you may use either the
Here the second value is a list of strings, each stating the number and size of a message in the mailbox. The number of messages is the size of this list of strings. Retrieve a message wholly with the method
Typically, the second value in the results is the most interesting: it is a list of the lines of the message. The example program needs only to retrieve the header information, so it gets string containing all header plus one line of body text with To delete a message in the mailbox, use the method Conducting Telnet with telnetlibThe Apache James mail server comes with a batch file to start it. As a convenient option, the example program can invoke the batch file via a call to
Shutting down the server, on the other hand, requires a Telnet session. Manually, you can do it through a Telnet client program connected to port 4555 of the server. Enter the user name as To establish a Telnet session, create a The Twisted FrameworkBeyond the core Python modules, Twisted is a networking framework in a different style. As demonstrated in the previous example, Python's core networking modules use a procedural approach. To perform a task, your code must invoke a method that holds the thread of execution until the task either completes successfully or fails. Such a method is straightforward to use since it is synchronous and communicates any results of execution to its caller by means of some return value. The code to perform a sequence of tasks simply invokes the appropriate methods one by one, possibly with some structural constructs and checking of return values. On the other hand, the Twisted framework adopts a different approach of asynchronous invocation. A method call will schedule a task to do in the framework's execution thread, returning control to its caller immediately and before the completion of the task. An event-driven mechanism communicates the results of the execution. The object returned by the asynchronous method call can register success and failure callbacks that will be invoked when the scheduled task completes successfully and fails, respectively. Performing a sequence of tasks is relatively more complex, since you must typically define each task in a method registered as the success callback to the object returned by the previous task's method. In Twisted, get used to receiving a Sending Mails the Twisted WayThe
To send more than one mails with Retrieving Mails with TwistedProgramming a POP3 client to retrieve mails in the Twisted framework is more complex and takes more code. The logic to retrieve mails is all in a class that subclasses
In the class Similarly, the
If there is no message in the mailbox, the code calls Because the logic of mail retrieval is similar to deletion, both features are in the same class,
To delete a mail, call the
With the implementation of the desired mail handling in class Invoking Doing Telnet with TwistedTwisted can power a Telnet client in a way similar to, but simpler than, the POP3 client. the Telnet conversation logic goes in a subclass of
The class When to Be Twisted?The two functionally equivalent programs, one using Python core modules and the other using the Twisted framework, significantly differ from each other in terms of programming style and the amount of code. Then when should you use either of the two options? For basic programs such as the command-line client of this example, the Python core networking modules are more desirable due to the simplicity and performance advantages. However, most real-world networking programs are very complex, and Twisted's asynchronous programming model is more effective. For example, BitTorrent, the popular peer-to-peer file sharing client that performs massive parallel downloading of data chunks from different sources, uses Twisted. Twisted also works well in programs with graphical user interface (GUI), because its asynchronous nature fits more seamlessly with the event-driven programming models of modern GUI frameworks. In fact, Twisted has integration with popular GUI frameworks including PyGTK, Qt, Tkinter, WxPython, and Win32. The other area where Twisted shines is in server programming. A typical network server uses multithreading so that it can handle multiple clients concurrently. The asynchronous mechanism of Twisted alleviates the creation and handling of threads by server programs. In addition, Twisted provides several protocols on which to build new networking services, enabling rapid development of complex servers. One such project is Quotient, which adopts Twisted to build a multiprotocol messaging server that supports a variety of protocols and services including SMTP, POP3, IMAP, webmail, and SIP. Kendrew Lau is a consultant in Hong Kong, with focus on Java, Linux, and other OSS technologies. Return to the Python DevCenter. Copyright © 2006 O'Reilly Media, Inc. love like you've never been hurt(zz)Work like you don't need the money; 美文(zz)转贴未名的趣文一篇和感人贴一篇: 发信人: yting (贝贝壳), 信区: Beauty
在一张纸上写下你的名字,然后在第一个字上面写下M,在左边写下E,在下面写下W, 在最后一个字下面写上W,在右边写下Q,然后 用弧线把字母连起来,然后你会发现……我给你惊喜哟
家——不是讲理的地方 萍儿: 萍儿,我们只是天底下最平凡的父母,我们的孩子也只是天底下最平凡的女儿,我们不奢求太多,只是希望我的孩子踏上婚姻之路,走向人生之旅後,能满怀感恩,一路平安在这里,给你一个我们的生活体会. 先要告诉你:家不是一个讲理的地方.这句话听起来,很没有道理,但千真万确,这句话是真理,是至理,是多少夫妇,多少家庭(包括我们家)用多少岁月,多少辛酸,多少爱恨,多少是非,多少对错,在纠缠不清难解难分的混乱中,梳理出来的一个最後结论. 当夫妇之间开始据理力争时,家里便开始布上阴影.两人都会不自觉地各抱一堆面目全非的歪理,敌视对方,伤害对方,最後只能两败俱伤,难以收拾.多少夫妻,为了表面的一个〔理〕,落得负心无情.他们不知道,家不是讲理的地方,不是算帐的地方. 那么,何为(家),家是什么地方?萍儿,我们年轻的时候,也回答不了这个问题;也像许多夫妻那样,为一点小事争闹不休.那一年为了你小叔的调动问题,我和你妈大吵了一场,甚至闹到要离婚的地步.只是在那个时代我们还缺乏勇气. 直到有一天,一位老战友在他孩子的婚礼上说:希望你白头偕老,相爱永远时,爱这简短的字,像春雷响在我心里.是的,家不是讲理的地方,家该是讲爱的地方.爱一时很容易,爱一生一世却不容易,这里面有许多妙处需要我们去总结和体会. 空盒子最先该放的应该是(思念),思念是一种使我们刻骨铭心的东西.它是两个人有了肯定,有了情感,然後进而关怀,进而疼爱的一种情绪.(思念)是疲惫时通向家里的一条小路,是寒冷冬夜里的一股暖意,是匆忙推开家门後扑面而来家饭香.... 空盒子里还要放进(艺术),婚姻生活中的艺术.在婚姻生活中,需要讲艺术的地方无处不在,生气有艺术,吵架有艺术.有一对夫妇含辛茹苦养育了五个孩子,其中之艰难,只有他们自己能体会.一天,夫妻为了孩子的一件小事吵起来,越吵越厉害,眼看不可收拾了,妻子突然说:等一下,我要去生孩子了.这句话,就是吵架的艺术. 婚姻的盒子里,除了放(思念)和(艺术)外,还有许多东西,都可以放进去,这有待於你们自己去填补.写到这里想到一位作家说过的一句话:你们生养他,教育他,你们的责任已尽,而你们给他最好的礼物,是一对翅膀. 萍儿,这封信,就是爸妈送给你的结婚礼物,我们希望你带著我们的祝福,快乐的飞翔!
爱一个人 是支持,而不是支配;是慰问,而不是质问; prototype cheetsheetPrototype is a must read if you are interested in ajax on rails, heck, even rails is not necessary, it's a nice way to map the ruby thinking to javascript, which boils down to make js sucks less;-) Just like MochiKit do it in the python way and i guess there are other ways too.
Quick guide to somewhat advanced JavaScript(zz)This article is fairly simple compare to the title, because the json part, the functions as first class citizens, closures, Arrys, items and object members, also about the prototype thing, really stright forward since i have some knowledge of ruby and python and some about functional programming. The only part that is not that obvious to me is the function bind on "this" object, just as when i'm reading the code of prototype, that's the part i have to think careful.
Quick guide to somewhat advanced JavaScripttour of some OO featureslast update: February 21st 2006
Hey, I didn't know you could do thatIf you are a web developer and come from the same place I do, you have probably used quite a bit of Javascript in your web pages, mostly as UI glue. Until recently, I knew that Javascript had more OO capabilities than I was employing, but I did not feel like I needed to use it. As the browsers started to support a more standardized featureset of Javascript and the DOM, it became viable to write more complex and functional code to run on the client. That helped giving birth to the AJAX phenomena. As we all start to learn what it takes to write our cool, AJAXy applications, we begin to notice that the Javascript we used to know was really just the tip of the iceberg. We now see Javascript being used beyond simple UI chores like input validation and frivolous tasks. The client code now is far more advanced and layered, much like a real desktop application or a client-server thick client. We see class libraries, object models, hierarchies, patterns, and many other things we got used to seeing only in our server side code. In many ways we can say that suddenly the bar was put much higher than before. It takes a heck lot more proficiency to write applications for the new Web and we need to improve our Javascript skills to get there. If you try to use many of the existing javascript libraries out there, like Prototype.js, Scriptaculous, moo.fx, Behaviour, YUI, etc you'll eventually find yourself reading the JS code. Maybe because you want to learn how they do it, or because you're curious, or more often because that's the only way to figure out how to use it, since documentation does not seem to be highly regarded with most of these libraries. Whatever the case may be, you'll face some kung-fu techniques that will be foreign and scary if you haven't seen anything like that before. The purpose of this article is precisely explaining the types of constructs that many of us are not familiar with yet. Related articlePrototype.js documentation JSONJavaScript Object Notation (JSON,) is one of the new buzzwords popping up around the AJAX theme. JSON, simply put, is a way of declaring an object in javascript. Let's see an example right away and note how simple it is. var myPet = { color: 'black', leg_count: 4, communicate: function(repeatCount){
for(i=0;i<repeatCount;i++) alert('Woof!');} };
Let's just add little bit of formatting so it looks more like how we usually find out there: var myPet = {
color: 'black',
legCount: 4,
communicate: function(repeatCount){
for(i=0;i<repeatCount;i++)
alert('Woof!');
}
};
Here we created a reference to an object with two properties (color and legCount) and a method (communicate.) It's not hard to figure out that the object's properties and methods are defined as a comma delimited list. Each of the members is introduced by name, followed by a colon and then the definition. In the case of the properties it is easy, just the value of the property. The methods are created by assigning an anonymous function, which we will explain better down the line. After the object is created and assigned to the variable myPet, we can use it like this: alert('my pet is ' + myPet.color);
alert('my pet has ' + myPet.legCount + ' legs');
//if you are a dog, bark three times:
myPet.communicate(3);
You'll see JSON used pretty much everywhere in JS these days, as arguments to functions, as return values, as server responses (in strings,) etc. What do you mean? A function is an object too?This might be unusual to developers that never thought about that, but in JS a function is also an object. You can pass a function around as an argument to another function just like you can pass a string, for example. This is extensively used and very handy. Take a look at this example. We will pass functions to another function that will use them. var myDog = {
bark: function(){
alert('Woof!');
}
};
var myCat = {
meow: function(){
alert('I am a lazy cat. I will not meow for you.');
}
};
function annoyThePet(petFunction){
//let's see what the pet can do
petFunction();
}
//annoy the dog:
annoyThePet(myDog.bark);
//annoy the cat:
annoyThePet(myCat.meow);
Note that we pass myDog.bark and myCat.meow without appending parenthesis "()" to them. If we did that we would not be passing the function, rather we would be calling the method and passing the return value, undefined in both cases here. If you want to make my lazy cat start barking, you can easily do this: myCat.meow = myDog.bark; myCat.meow(); //alerts 'Woof!' Arrays, items, and object membersThe following two lines in JS do the same thing. var a = new Array(); var b = []; As I'm sure you already know, you can access individual items in an array by using the square brackets: var a = ['first', 'second', 'third']; var v1 = a[0]; var v2 = a[1]; var v3 = a[2]; But you are not limited to numeric indices. You can access any member of a JS object by using its name, in a string. The following example creates an empty object, and adds some members by name. var obj = {}; //new, empty object
obj['member_1'] = 'this is the member value';
obj['flag_2'] = false;
obj['some_function'] = function(){ /* do something */};
The above code has identical effect as the following: var obj = {
member_1:'this is the member value',
flag_2: false,
some_function: function(){ /* do something */}
};
In many ways, the idea of objects and associative arrays (hashes) in JS are not distinguishable. The following two lines do the same thing too. obj.some_function(); obj['some_function'](); Enough about objects, may I have a class now?The great power of object oriented programming languages derive from the use of classes. I don't think I would have guessed how classes are defined in JS using only my previous experience with other languages. Judge for yourself. //defining a new class called Pet
var Pet = function(petName, age){
this.name = petName;
this.age = age;
};
//let's create an object of the Pet class
var famousDog = new Pet('Santa\'s Little Helper', 15);
alert('This pet is called ' + famousDog.name);
Let's see how we add a method to our Pet class. We will be using the prototype property that all classes have. The prototype property is an object that contains all the members that any object of the class will have. Even the default JS classes, like String, Number, and Date have a prototype object that we can add methods and properties to and make any object of that class automatically gain this new member. Pet.prototype.communicate = function(){
alert('I do not know what I should say, but my name is ' + this.name);
};
That's when a library like prototype.js comes in handy. If we are using prototype.js, we can make our code look cleaner (at least in my opinion.) var Pet = Class.create();
Pet.prototype = {
//our 'constructor'
initialize: function(petName, age){
this.name = petName;
this.age = age;
},
communicate: function(){
alert('I do not know what I should say, but my name is ' + this.name);
}
};
Functions as arguments, an interesting patternIf you have never worked with languages that support closures, like Ruby or C#2.0, you may find the following idiom too funky. var myArray = ['first', 'second', 'third'];
myArray.each( function(item, index){
alert('The item in the position #' + index + ' is:' + item);
});
Whoa! Let's explain what is going on here before you decide I've gone too far and navigate to a better article than this one. First of all, in the above example we are using the prototype.js library, which adds the each function to the Array class. The each function accepts one argument that is a function object. This function, in turn, will be called once for each item in the array, passing two arguments when called, the item and the index for the current item. Let's call this function our iterator function. We could have also written the code like this. function myIterator(item, index){
alert('The item in the position #' + index + ' is:' + item);
}
var myArray = ['first', 'second', 'third'];
myArray.each( myIterator );
But then we would not be doing like all the cool kids in school, right? More seriously, though, this last format is simpler to understand but causes us to jump around in the code looking for the myIterator function. It's nice to have the logic of the iterator function right there in the same place it's called. Also, in this case, we will not need the iterator function anywhere else in our code, so we can transform it into an anonymous function without penalty. Let's look at the original example again with some highlighting to hopefully make things clearer.
var myArray = ['first', 'second', 'third'];
myArray.each( function(item, index){
alert('The item in the position #' + index + ' is:' + item);
} );
This is this but sometimes this is also thatOne of the most common troubles we have with JS when we start writing our code is the use of the this keyword. It could be a real tripwire. As we mentioned before, a function is also an object in JS, and sometimes we do not notice that we are passing a function around. Take this code snippet as an example. function buttonClicked(){
alert('button ' + this.id + ' was clicked');
}
var myButton = document.getElementById('someButtonID');
var myButton2 = document.getElementById('someOtherButtonID');
myButton.onclick = buttonClicked;
myButton2.onclick = buttonClicked;
Because the buttonClicked function is defined outside any object we may tend to think the this keyword will contain a reference to the window or document object (assuming this code is in the middle of an HTML page viewed in a browser.) But when we run this code we see that it works as intended and displays the id of the clicked button. What happened here is that we made the onclick method of each button contain the buttonClicked object reference, replacing whatever was there before. Now whenever the button is clicked, the browser will execute something similar to the following line. myButton.onclick(); That isn't so confusing afterall, is it? But see what happens you start having other objects to deal with and you want to act on these object upon events like the button's click. var myHelper = {
formFields: [ ],
emptyAllFields: function(){
for(i=0; i<this.formFields.length; i++){
var elementID = this.formFields[i];
var field = document.getElementById(elementID);
field.value = '';
}
}
};
//tell which form fields we want to work with
myHelper.formFields.push('txtName');
myHelper.formFields.push('txtEmail');
myHelper.formFields.push('txtAddress');
//clearing the text boxes:
myHelper.emptyAllFields();
var clearButton = document.getElementById('btnClear');
clearButton.onclick = myHelper.emptyAllFields;
So you think, nice, now I can click the Clear button on my page and those three text boxes will be emptied. Then you try clicking the button only to get a runtime error. The error will be related to (guess what?) the this keyword. The problem is that this.formFields is not defined if this contains a reference to the button, which is precisely what's happening. One quick solution would be to rewrite our last line of code. clearButton.onclick = function(){ myHelper.emptyAllFields(); };
That way we create a brand new function that calls our helper method within the helper object's context. Books I've read and recommendSome books are just too good not to pass the word forward. I haven't read a whole lot of Javascript books, but the following books were very helpful to me. They are very well written and didn't cause me to lose interest before reading half of it. I'm comfortable recommending them if you're on the market for a new book. This article is not finished yet. If you find broken examples, incorrect information, broken links, etc., please let me know and I'll try to fix it as soon as possible. baidu mp3试听的歌词同步功能今天去找个东西听,突然发现多了新的功能,前几天还看他们招ajax的程序员呢,看来baidu这方面还是花些力气的. 很好奇是怎么实现的, 看了看那个js文件,发现没什么神秘的,就是歌词里面每行前加时间信息,然后同步就好了.代码看起来挺直观的,可读性不差,就是换我写肯定写不出来, ft啊,又一门能看但写的少的语言:P 2006/8/7 脑筋急转弯(zz)从段伟那看到的,大家可以试试,一会在comments里说我做的结果:) 问题1:Sergey Brin、Jerry Yang和Bill Gates同时爱上了一个姑娘,为了决定他们谁能娶这个姑娘,他们决定用手枪进一次决斗。 Gates的命中率是30%,Yang比他好些,命中率是50%,最出色的枪手是年轻的Brin,从不失误,他的命中率是100%。由于这个显而易见的事实,为公平起见,他们决定按这样的顺序:Gates先开枪,Yang第二,Brin最后一个。然后这样循环,直到他们只剩下一个人。问题是: (1) 首先,猜猜Sergey Brin、Jerry Yang和Bill Gates都是谁? (2) 显然Brin、Yang和Gates都是绝顶聪明的人,那么这三个人中谁活下来的机会最大呢? (3) 前两枪他们都应该采取什么样的策略? 2006/8/4 ez_where plugin for railsAs I was checking out the blog i mentioned on the last post, I find this plugin for rails, i always not good at writing that complex sql statements, hard to get it right with the syntax which i'm not familiar with. When i saw this post, my eyes enlarge instantly like seeing an really pretty girl after a boring day;-)
New release of ez_where pluginPosted by ezmobius 17 days ago Fabien Franzen and I have created a new release of the ez-where plugin with many new features and a much nicer API. Some things have changed including module and class names so if you are using an old verion and want to update you will have to make a few small search and replace changes. Change Caboose::EZ::Condition to EZ::Where::Condition. Other then that your old code should work fine.But the new API is much nicer to use. And we have added support for multi search easier by excluding nil or empty values from a search. So instead of: cond = EZ::Where::Condition.new :my_table do
title =~ "%#{params[:search]}%" unless params[:search].blank?
user == params[:user] unless params[:user].blank?
end
You can do: cond = EZ::Where::Condition.new :my_table do
title =~ "%#{params[:search]}%"
user == params[:user]
end
And if any of the right hand side values are blank? that whole line will be excluded from the query. There are way too many new features to list here so I will show some of the highlights. The huge test cases are currently the best place to look to see all the things this plugin can do. I will wrtie up a few more tutorials soon on some even more advanced features like compositions. So without further ado, here are some cool things you can do with the new version: # find all posts where with body LIKE '%rails%'
@posts = Post.find_where(:all) { |p| p.body =~ "%rails%" }
=> ["posts.body LIKE ?", "%rails%"]
# find all posts where with title, body or extended LIKE '%rails%'
@posts = Post.find_where :all do |post|
post.any_of(:title, :body, :extened) =~ '%rails%'
end
=> ["(posts.title LIKE ? OR posts.body LIKE ?
OR posts.extended LIKE ?)", "%rails%", "%rails%", "%rails%"]
# find all articles with title, body or extended LIKE "%#{params[:search]}%"
# AND (author.name = params[:author] OR comment.body LIKE "%#{params[:search]}%")
@articles = Article.find_where(:all, :include => [:author, { :comments => :users }]) do
|article, author, comment|
article.any_of(:title, :body, :extended) =~ "%#{params[:search]}%"
any {
author.name == params[:author]
comment.body =~ "%#{params[:search]}%"
}
end
=>["(articles.title LIKE ? OR articles.body LIKE ?
OR articles.extended LIKE ?) AND ((authors.name = ?)
OR (comments.body LIKE ?))", "%foo%", "%foo%", "%foo%", "Ezra", "%foo%"]
One of the coolest new features is the c method. This promotes conditions
into first class objects. It works like this:
c{ title =~ '%foo%' }.to_sql
=> ["title LIKE ?", "%foo%"]
With a naked block like this it just converts whats inside the block
into a condition.
c(:posts) { title =~ '%foo%' }.to_sql
=> ["posts.title LIKE ?", "%foo%"]
When you give it a plural table name as an arguments it scopes the condition to that
table.
You can also use the c object directly in a find like so:
Post.find :all, :conditions => c{ body =~ '%rails%' }
Now that you can have conditions as objects you can do some really interesting
and complex queries with them. You can use operators to define how
the conditions get strung together. So:
+ == AND
| == OR
- == AND NOT
For example:
cond1 = c(:posts) { body =~ '%rails%'}
cond2 = c(:comments) { username == 'ezmobius'}
cond3 = c(:posts) { author_id === (1..4) }
(cond1 + cond2 | cond3).to_sql
=> ["((posts.body LIKE ?) AND (comments.username = ?))
OR (posts.author_id IN (?))", "%rails%", "ezmobius", [1, 2, 3, 4]]
Now you can pass these into a find like this and .to_sql will
automatically be called on the compound condition:
Post.find :all, :conditions => (cond1 + cond2 | cond3)
You can also build up one compound condition use +=, -= or |=
cond = c{ title =~ '%ruby%' }
cond += c{ description =~ '%ez-where%' }
cond |= c{ user_id === (1..5) }
cond -= c{ pub_date > Time.now.to_s(:db) }
Post.find :all, :conditions => cond
=> ["((title LIKE ?) AND (description LIKE ?))
OR ((user_id IN (?)) AND NOT (pub_date > ?))",
"%ruby%", "%ez-where%", [1, 2, 3, 4, 5], "2006-06-21 01:17:47"]
Get it here:$ script/plugin install svn://rubyforge.org//var/svn/ez-where I moved the project to rubyforge so there is now a mailing list where you can ask questions or contribute ideas. http://rubyforge.org/mailman/listinfo/ez-where-devel Enjoy! ;) |
|
|