tag:blogger.com,1999:blog-337919602024-03-13T18:53:51.261+08:00白菜请使用firefox浏览!黄毅http://www.blogger.com/profile/01060629900676151700noreply@blogger.comBlogger86125tag:blogger.com,1999:blog-33791960.post-30126111086756368302010-04-10T15:30:00.003+08:002010-04-10T16:17:54.930+08:00博客搬新家鉴于blogger常年在墙外,严重影响了发贴的心情。终于搭建了自己的博客。
http://www.yi-programmer.com/blog/
博客的成功运转跟下面这些光辉的名字是分不开,向创造这些东西的大牛们表示致敬,谢谢git,谢谢make,谢谢python,谢谢docutils,谢谢mako,谢谢pygments,谢谢latex。黄毅http://www.blogger.com/profile/01060629900676151700noreply@blogger.com0tag:blogger.com,1999:blog-33791960.post-60137720318138191742009-04-23T13:32:00.001+08:002009-04-23T13:32:33.985+08:00hello黄毅http://www.blogger.com/profile/01060629900676151700noreply@blogger.com0tag:blogger.com,1999:blog-33791960.post-39225518421113603952009-04-20T18:23:00.001+08:002009-04-20T18:24:31.820+08:00学习Haskell<div style="text-align: center;"><div style="text-align: center;"><h1>学习Haskell</h1></div></div>发现自己学习一门新语言的时候总是去尝试找到一个能完全表达这门语言的最小子集,然后其他的都是语法糖。比如c语言这个子集基本就是汇编语言所提供的那些东西:分支跳转指针等,python的这个子集大概是些对象、类型、属性、duck typing之类的东西。这样可以帮助记忆。haskell的这个子集里都会有些什么呢?lambda、type、typeclass,这样考虑起来 haskell 语言的核心概念还是挺少的,就是有些理论还需要学习,函数式的风格需要转换过来。<br>黄毅http://www.blogger.com/profile/01060629900676151700noreply@blogger.com0tag:blogger.com,1999:blog-33791960.post-41563768751705577922009-04-20T14:19:00.002+08:002009-04-20T14:21:26.257+08:00monad与状态<h1 style="text-align: center;">monad与状态</h1>
<div style="text-align: left;">最近重新捡起haskell来看了看,似乎对monad和程序状态的关系有点小小的明白了。强烈希望明白人指点一下。</div>
<div style="text-align: left;"> </div>
<div style="text-align: left;">话说用命令式语言写程序的时候,有明白人就强烈要求不要用全局变量不要用全局变量,其实要取消所有的全局变量也容易,不过就是增加几个参数而已,比如这样的程序:</div>
<div style="text-align: left;"> </div>
<div style="text-align: left;">int 全局变量=0;</div>
<div style="text-align: left;">void inc(){全局变量+=1;}</div>
<div style="text-align: left;">void dec(){全局变量-=1;}</div>
<div style="text-align: left;">void main(){inc(); dec();}</div>
<div style="text-align: left;"> </div>
<div style="text-align: left;">改成这样就成了:</div>
<div style="text-align: left;">
<div style="text-align: left;"> </div>
<div style="text-align: left;">void inc(int *变量){*变量+=1;}</div>
<div style="text-align: left;">void dec(int *变量){*变量-=1;}</div>
<div style="text-align: left;">void main(){int 全局变量=0; inc(&全局变量); dec(&全局变量);}</div>
<div style="text-align: left;"> </div>
<div style="text-align: left;">其实说起来,搞个全局变量也就是为了让函数少写几个参数而已。参数实在太多了,大不了就搞个 struct stat 把公用的参数给包装成一个。</div>
<div style="text-align: left;">函数式编程号称不准修改状态,那大不了就每次改都创建一份新的,然后返回了,这样程序就变成这样了:</div>
<div style="text-align: left;">
<div style="text-align: left;">void inc(状态,...){...; return 结果和新状态;}</div>
<div style="text-align: left;">void dec(状态,...){...; return 结果和新状态}</div>
<div style="text-align: left;">void main(){</div>
<div style="text-align: left;"> 初始状态;</div>
<div style="text-align: left;"> 新状态, 返回值 = inc(初始状态,...);</div>
<div style="text-align: left;"> 新状态2, 返回值 = dec(新状态,...);</div>
<div style="text-align: left;">}</div>
<div style="text-align: left;"> </div>
<div style="text-align: left;">这样所有函数都要多加一个状态参数,要多返回一个新状态。麻是麻烦点,不过据说都要玩并行计算了嘛,忍了。</div>
<div style="text-align: left;"> </div>
<div style="text-align: left;">那么可以把状态这个东西本身抽象了一下,我们用python来模拟一下吧,假设原来的程序是这样的:<br><br>global_stat = []<br>def inc1(stat, input):<br> return stat+['inc1'], input+1<br><br>def inc2(stat, input):<br> ...<br> return stat+['inc2'], input+2<br><br>a = 1<br>new_stat, a1 = inc1(global_stat, a)<br>new_stat, a2 = inc2(new_stat, a1)<br></div></div></div><br>为了简化这个问题,我们引入一个 bind 函数来进行抽象:<br><br>def bind(func1, func2):<br> def lazy_bind(stat, value):<br> new_stat, return_value = func1(stat, value)<br> func2(new_stat, return_value)<br> return lazy_bind<br><br># 然后就可以这样来调用 inc1,inc2...<br><br>bind(inc1,<br>bind(inc2,<br>bind(xxx,<br>...<br>))...) (init_stat, defaut_value)<br><br>就我们这个例子来说,后面这种方式除了让程序更加诡异以外看不出来有什么特别的好处。<br>但是对于 Haskell 来说,很多基本的东西(IO)都是构建与这种类型的抽象之上,并且提供一些语法糖让代码变得更好看,这样一种抽象方式也就成为理解haskell程序很重要的一个东西了。<br>而haskell之所以说能够通过这种抽象方式来隔离纯代码和有副作用的代码(比如说具体的IO操作)就我个人理解就是因为可以把有副作用的代码放到bind里面执行,从而保证 inc1、inc2 这种函数的纯粹性。<br><br>黄毅http://www.blogger.com/profile/01060629900676151700noreply@blogger.com0tag:blogger.com,1999:blog-33791960.post-37150583426212575222009-01-20T15:20:00.000+08:002009-01-20T15:21:31.865+08:00所谓日久生情不要怀疑,这个日就是你心里想的那个日,而且是被。
意思是说,再郁闷的东西,被郁闷久了,也总能从中发掘出一些稍微好玩一点的东西出来。
<a href="http://huangyilib.googlecode.com/svn/trunk/doc/js_best_practice.html">http://huangyilib.googlecode.com/svn/trunk/doc/js_best_practice.html</a>
当然,玩python的兄弟就不要点了,主要是用来忽悠没玩过动态语言的朋友的。黄毅http://www.blogger.com/profile/01060629900676151700noreply@blogger.com3tag:blogger.com,1999:blog-33791960.post-84988706824670324042008-12-26T17:46:00.001+08:002008-12-26T17:48:19.884+08:00无题想起来也很久没有用python,尤其没有用来做web了,没想到还记得很清楚,不容易不容易。黄毅http://www.blogger.com/profile/01060629900676151700noreply@blogger.com0tag:blogger.com,1999:blog-33791960.post-61893527208103016242008-11-12T00:31:00.002+08:002008-11-12T01:07:43.164+08:00linux下的半透明窗口为了做一个显示歌词的小玩意,学习了一把x window,我希望歌词窗口能背景透明但文字清晰显示。理论基础就是 composite window manager(比如compiz)支持窗口使用 alpha channel。那么应用程序只要整好rgba的图像交给x服务器即可。
发现使用 gtk+cairo+pango 大大简化了工作。
代码:http://code.google.com/p/huangyilib/source/browse/trunk/py_transparent_window.py
<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_jpcT9HwSFrU/SRm7tda0QrI/AAAAAAAAAak/-3faHlg_t6A/s1600-h/Screenshot-py_transparent_window.py.png"><img style="cursor: pointer; width: 200px; height: 64px;" src="http://1.bp.blogspot.com/_jpcT9HwSFrU/SRm7tda0QrI/AAAAAAAAAak/-3faHlg_t6A/s200/Screenshot-py_transparent_window.py.png" alt="" id="BLOGGER_PHOTO_ID_5267447628852118194" border="0" /></a>黄毅http://www.blogger.com/profile/01060629900676151700noreply@blogger.com1tag:blogger.com,1999:blog-33791960.post-62905244010972393322008-11-11T23:39:00.002+08:002008-11-11T23:49:03.291+08:00关于设计模式又看到关于设计模式的文章,突然联想到vim的作者说过一句大概是这样的话:学习vim的方法就是使用它,然后在使用过程中注意发现那些经常重复的行为,然后简化之。
写程序的模式又何尝不是如此呢?只不过程序的事情更复杂罢了,那些重复的模式往往需要灵感来发现,简化的方法也总是不那么明显,甚至需要思维方式的彻底改变。黄毅http://www.blogger.com/profile/01060629900676151700noreply@blogger.com0tag:blogger.com,1999:blog-33791960.post-7828868859658966962008-11-08T17:20:00.003+08:002008-11-08T18:40:31.127+08:00inkscape还是很好用的<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_jpcT9HwSFrU/SRVsRd_pvbI/AAAAAAAAAac/Ran0fgy0chg/s1600-h/libevent_quene.png"><img style="cursor: pointer;" src="http://2.bp.blogspot.com/_jpcT9HwSFrU/SRVsRd_pvbI/AAAAAAAAAac/Ran0fgy0chg/s200/libevent_quene.png" alt="" id="BLOGGER_PHOTO_ID_5266234386644843954" border="0" /></a>
<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_jpcT9HwSFrU/SRVsRLLI8LI/AAAAAAAAAaU/zS4Y-IWNE_c/s1600-h/libevent_buffer.png"><img style="cursor: pointer;" src="http://4.bp.blogspot.com/_jpcT9HwSFrU/SRVsRLLI8LI/AAAAAAAAAaU/zS4Y-IWNE_c/s200/libevent_buffer.png" alt="" id="BLOGGER_PHOTO_ID_5266234381592752306" border="0" /></a>
<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_jpcT9HwSFrU/SRVsQ_Ha69I/AAAAAAAAAaM/e0wfacESReQ/s1600-h/libevent_basic.png"><img style="cursor: pointer;" src="http://1.bp.blogspot.com/_jpcT9HwSFrU/SRVsQ_Ha69I/AAAAAAAAAaM/e0wfacESReQ/s200/libevent_basic.png" alt="" id="BLOGGER_PHOTO_ID_5266234378355928018" border="0" /></a>黄毅http://www.blogger.com/profile/01060629900676151700noreply@blogger.com0tag:blogger.com,1999:blog-33791960.post-27679288330298076062008-10-28T20:54:00.000+08:002008-10-28T20:55:12.199+08:00北京好远啊唉黄毅http://www.blogger.com/profile/01060629900676151700noreply@blogger.com5tag:blogger.com,1999:blog-33791960.post-30837003025825966562007-12-18T21:53:00.000+08:002007-12-18T22:04:35.039+08:00工作后转眼来到腾讯有5个月了,博客也就长个5个月的草了。
china-pub 又给我送了几本书来,自然也就又有一百多块离开了我的身边。
拿到书的时候心情自然是不用说,不过想起床上躺着上个月的科幻世界没看完时,却也着实让人发愁。
有时间的时候没钱,有钱的时候没时间,人生啊!!!
还有可爱的python也是许久没有贡献新东西了,真是惭愧,唉~~~黄毅http://www.blogger.com/profile/01060629900676151700noreply@blogger.com6tag:blogger.com,1999:blog-33791960.post-83766644477071043542007-09-26T20:46:00.000+08:002007-09-26T20:48:51.726+08:00爆强的翻译第一次见到翻译得这么好的编程之道了:<a href="http://livecn.huasing.org/tao_of_programming.htm">http://livecn.huasing.org/tao_of_programming.htm</a>
Prince Wang's programmer was coding software. His fingers danced upon the keyboard. The program compiled without an error message, and the program ran like a gentle wind.
Excellent!" the Prince exclaimed, "Your technique is faultless!"
"Technique?" said the programmer, turning from his terminal, "What I follow is the Tao -- beyond all technique. When I first began to program I would see before me the whole program in one mass. After three years I no longer saw this mass. Instead, I used subroutines. But now I see nothing. My whole being exists in a formless void. My senses are idle. My spirit, free to work without a plan, follows its own instinct. In short, my program writes itself. True, sometimes there are difficult problems. I see them coming, I slow down, I watch silently. Then I change a single line of code and the difficulties vanish like puffs of idle smoke. I then compile the program. I sit still and let the joy of the work fill my being. I close my eyes for a moment and then log off."
Price Wang said, "Would that all of my programmers were as wise!"
程序员为公子王写软件,指飞键舞,不差丝毫,行之如风。
公子王曰:『嘻,善哉!技盖至此乎?』
程序员释键对曰:『臣之所好者道也,进乎技矣。始臣之编程之时,所见无非程序者;三年之后,未尝见程序也,见其子程序也;方今之时,臣以神遇而不以目视,官知止而神欲行,因其固然,程序自写之。诚然,尝至于难者,吾见其难为,怵然为戒,视为止,行为迟,改其一字,謋然已解,如烟随风。使之编译,释键而坐,为之踌躇满志,闭目而log off之。』
公子王曰:『吾之程序员皆如此,则其善焉!』黄毅http://www.blogger.com/profile/01060629900676151700noreply@blogger.com1tag:blogger.com,1999:blog-33791960.post-45218951955991502007-06-26T01:02:00.000+08:002007-06-26T01:22:14.382+08:00实现一个 django 的 url dispatcher心血来潮,实现了一个 django 的 url dispatcher,比想象中简单多了。
<a href="http://djangodispatcher.googlecode.com/svn/trunk/mapper.py">http://djangodispatcher.googlecode.com/svn/trunk/mapper.py</a>
<a href="http://djangodispatcher.googlecode.com/svn/trunk/test.py">http://djangodispatcher.googlecode.com/svn/trunk/test.py</a>
实际实现功能的代码才2、30行,功能基本完整,包括分层次的url配置,和发生异常时帮助调试用的一些信息。
PS:发现最近爱上了 Test Driven.黄毅http://www.blogger.com/profile/01060629900676151700noreply@blogger.com0tag:blogger.com,1999:blog-33791960.post-23271563989653249352007-06-22T17:07:00.000+08:002007-06-22T17:12:30.744+08:00如何在醉酒的情况下编写正确的程序答案很简单:Test Driven。
哈哈,这个(<a href="http://code.google.com/p/pylifegame/">http://code.google.com/p/pylifegame/</a>)就是好例子!
醉了,不多说了,自己看去,我要睡觉去了,嗯 ...黄毅http://www.blogger.com/profile/01060629900676151700noreply@blogger.com0tag:blogger.com,1999:blog-33791960.post-40288842389633218382007-06-20T12:17:00.000+08:002007-06-20T12:18:48.711+08:00Faint! 和我同名的编辑器<p align="center"><a href="http://www.haskell.org/yi/Yi.html"><strong><span style="font-size:130%;">Yi</span></strong></a></p>
Yi is a text editor written and extensible in Haskell. The goal of Yi is to provide a flexible, powerful and correct editor core dynamically scriptable in Haskell.黄毅http://www.blogger.com/profile/01060629900676151700noreply@blogger.com0tag:blogger.com,1999:blog-33791960.post-2480441444349924702007-06-20T11:28:00.000+08:002007-06-20T11:31:23.150+08:00原来 pickle 这么有意思<a href="http://peadrop.com/blog/2007/06/18/pickle-an-interesting-stack-language/">Pickle: An interesting stack language</a>
原来 pickle 本身就是就是一个微型的基于栈的语言,呵呵,有点意思。
研究一下 pickle.py 和 pickletools.py ,可以看到更细节的东西。黄毅http://www.blogger.com/profile/01060629900676151700noreply@blogger.com0tag:blogger.com,1999:blog-33791960.post-55127615203562977072007-06-20T11:26:00.000+08:002007-06-20T11:27:51.872+08:00翻译了这篇文章<a class="toc-backref" id="python-3000" href="http://wiki.woodpecker.org.cn/moin/Py3000StatusUpdate#id17" name="python-3000">Python 3000 进度报告</a>
也可以从 guido 的中文 blog 看到:<a href="http://blog.csdn.net/gvanrossum/archive/2007/06/20/1658829.aspx">http://blog.csdn.net/gvanrossum/archive/2007/06/20/1658829.aspx</a>黄毅http://www.blogger.com/profile/01060629900676151700noreply@blogger.com0tag:blogger.com,1999:blog-33791960.post-27864005042091566682007-06-19T16:39:00.000+08:002007-06-19T16:41:52.638+08:00Python 3000 Status Update (Long!)<a href="http://www.artima.com/weblogs/viewpost.jsp?thread=208549">Python 3000 Status Update (Long!)</a> by Guido van Rossum """
<strong>Summary</strong>
Here's a long-awaited update on where the Python 3000 project stands. We're looking at a modest two months of schedule slip, and many exciting new features. I'll be presenting this in person several times over the next two months.
"""黄毅http://www.blogger.com/profile/01060629900676151700noreply@blogger.com0tag:blogger.com,1999:blog-33791960.post-72681989815294985792007-06-08T23:47:00.000+08:002007-06-09T00:32:13.755+08:00老子毕业了<a href="http://picasaweb.google.com/yi.codeplayer/070608">http://picasaweb.google.com/yi.codeplayer/070608</a>
<img src="http://lh6.google.com/image/yi.codeplayer/Rmlv-LQQLXI/AAAAAAAAAEU/423ul6UtTDo/%E5%AD%A6%E5%A3%AB%E6%9C%8D070608%20005.jpg?imgmax=512" />
<img src="http://lh5.google.com/image/yi.codeplayer/Rmlzc7QQLhI/AAAAAAAAAFo/PBd5rwh1KOM/%E5%AD%A6%E5%A3%AB%E6%9C%8D070608%20015.jpg?imgmax=288" />
<img src="http://lh5.google.com/image/yi.codeplayer/Rmlys7QQLgI/AAAAAAAAAFc/LJtHUc00iHg/%E5%AD%A6%E5%A3%AB%E6%9C%8D070608%20014.jpg?imgmax=288" />
<img src="http://lh6.google.com/image/yi.codeplayer/RmlzuLQQLiI/AAAAAAAAAFw/F2E--aoUcA4/%E5%AD%A6%E5%A3%AB%E6%9C%8D070608%20016.jpg?imgmax=288" />
<img src="http://lh5.google.com/image/yi.codeplayer/RmlyQ7QQLfI/AAAAAAAAAFU/9oWUzy0bfVc/%E5%AD%A6%E5%A3%AB%E6%9C%8D070608%20013.jpg?imgmax=288" />
<img src="http://lh4.google.com/image/yi.codeplayer/Rml5YrQQLnI/AAAAAAAAAGw/JziZHS0IDeg/%E5%AD%A6%E5%A3%AB%E6%9C%8D070608%20021.jpg?imgmax=288" />
<img src="http://lh4.google.com/image/yi.codeplayer/Rml-brQQMOI/AAAAAAAAALo/8u55Fz0TjUs/%E5%AD%A6%E5%A3%AB%E6%9C%8D070608%20060.jpg?imgmax=288" />
<img src="http://lh6.google.com/image/yi.codeplayer/Rml-nLQQMQI/AAAAAAAAAL4/5g0YrKSybM8/%E5%AD%A6%E5%A3%AB%E6%9C%8D070608%20062.jpg?imgmax=288" />
<img src="http://lh3.google.com/image/yi.codeplayer/Rml8ibQQL9I/AAAAAAAAAJg/i1Xoy4znGPk/%E5%AD%A6%E5%A3%AB%E6%9C%8D070608%20043.jpg?imgmax=288" />
<img src="http://lh5.google.com/image/yi.codeplayer/Rml_c7QQMaI/AAAAAAAAANI/dc_1YSpT1Bw/%E5%AD%A6%E5%A3%AB%E6%9C%8D070608%20073.jpg?imgmax=288" />
<img src="http://lh4.google.com/image/yi.codeplayer/RmmCNrQQM2I/AAAAAAAAAQo/ICgcSN1lOMw/%E5%AD%A6%E5%A3%AB%E6%9C%8D070608%20101.jpg?imgmax=288" />黄毅http://www.blogger.com/profile/01060629900676151700noreply@blogger.com0tag:blogger.com,1999:blog-33791960.post-18702679123312680882007-06-03T02:22:00.000+08:002007-06-03T02:47:51.927+08:00SQLAlchemy Examples看 SQLAlchemy 自带的 zblog 的例子,可以看到 SQLAlchemy 一些非常有用的特性。
<p><strong>文章相关评论数统计</strong></p><p>比如显示文章列表的同时我们希望获得相关文章的评论数,如果是用 django 那就只能放弃 ORM 的好处自己去执行 sql 语句了,否则就只会导致 n+1 条 SQL 语句的执行。
在 SQLAlchemy 中你可以把任意的 select 语句映射到一个 class ,这样就可以用一条 SQL 语句搞定,还能获得 ORM 的好处,下面是原封不动拷过来的代码(只调整了下格式):</p><pre> # Post mapper, these are posts within a blog.
# since we want the count of comments for each post,
# create a select that will get the posts
# and count the comments in one query.
posts_with_ccount = select(
[c for c in tables.posts.c if c.key != 'body'] + [
func.count(tables.comments.c.comment_id).label('comment_count')
],
from_obj = [
outerjoin(tables.posts, tables.comments)
],
group_by=[
c for c in tables.posts.c if c.key != 'body'
]
) .alias('postswcount')
# then create a Post mapper on that query.
# we have the body as "deferred" so that it loads only when needed,
# the user as a Lazy load, since the lazy load will run only once per user and
# its usually only one user's posts is needed per page,
# the owning blog is a lazy load since its also probably loaded into the identity map
# already, and topics is an eager load since that query has to be done per post in any
# case.
mapper(Post, posts_with_ccount, properties={
'id':posts_with_ccount.c.post_id,
'body':deferred(tables.posts.c.body),
'user':relation(user.User, lazy=True,
backref=backref('posts', cascade="all, delete-orphan")),
'blog':relation(Blog, lazy=True,
backref=backref('posts', cascade="all, delete-orphan")),
'topics':relation(TopicAssociation, lazy=False, private=True,
association=Topic, backref='post')
}, order_by=[desc(posts_with_ccount.c.datetime)])</pre>
<strong>树形评论</strong>
映射如下:
<pre> # comment mapper. This mapper is handling a hierarchical relationship on itself,
# and contains
# a lazy reference both to its parent comment and its list of child comments.
mapper(Comment, tables.comments, properties={
'id':tables.comments.c.comment_id,
'post':relation(Post, lazy=True,
backref=backref('comments', cascade="all, delete-orphan")),
'user':relation(user.User, lazy=False,
backref=backref('comments', cascade="all, delete-orphan")),
'parent':relation(Comment,
primaryjoin=tables.comments.c.parent_comment_id==tables.comments.c.comment_id,
foreignkey=tables.comments.c.comment_id, lazy=True, uselist=False),
'replies':relation(Comment,
primaryjoin=tables.comments.c.parent_comment_id==tables.comments.c.comment_id,
lazy=True, uselist=True, cascade="all"),
})
</pre>
很多时候我们需要一次性获取对应一个文章的所有评论,可以用一条 select 先把数据取出,然后手动建立树形结构:
<pre># we define one special find-by for the comments of a post, which is going to make its own
# "noload" mapper and organize the comments into their correct hierarchy in one pass. hierarchical
# data normally needs to be loaded by separate queries for each set of children, unless you
# use a proprietary extension like CONNECT BY.
def find_by_post(post):
"""returns a hierarchical collection of comments based on a given criterion.
uses a mapper that does not lazy load replies or parents, and instead
organizes comments into a hierarchical tree when the result is produced.
"""
q = session().query(Comment).options(noload('replies'), noload('parent'))
comments = q.select_by(post_id=post.id)
result = []
d = {}
for c in comments:
d[c.id] = c
if c.parent_comment_id is None:
result.append(c)
c.parent=None
else:
parent = d[c.parent_comment_id]
parent.replies.append(c)
c.parent = parent
return result
Comment.find_by_post = staticmethod(find_by_post)
</pre>黄毅http://www.blogger.com/profile/01060629900676151700noreply@blogger.com0tag:blogger.com,1999:blog-33791960.post-17527921026472398702007-05-30T12:29:00.000+08:002007-05-30T12:40:10.306+08:00multitask and Hive<a href="http://o2s.csail.mit.edu/o2s-wiki/multitask"><strong>multitask</strong></a>
multitask allows Python programs to use generators (aka coroutines) to perform cooperative multitasking and asynchronous I/O. Applications written using multitask consist of a set of cooperating tasks that yield to a shared task manager whenever they perform a (potentially) blocking operation, such as I/O on a socket or getting data from a queue. The task manager temporarily suspends the task (allowing other tasks to run in the meantime) and then restarts it when the blocking operation is complete. Such an approach is suitable for applications that would otherwise have to use select() and/or multiple threads to achieve concurrency.
<a href="http://www.oluyede.org/blog/2007/05/29/producerconsumer-with-multitask-library/">Producer/Consumer with multitask library </a>
<a href="http://cheeseshop.python.org/pypi/Hive"><strong>Hive</strong></a>
This is a basic concurrency module that uses only dependencies available in the Python 2.5 standard library. It allows the creation of a jobfile for uses to queue work that any number of worker processes with access to the jobfile can pull from the queue and run.
看到这两个库很快就联想到曾经写过的<a href="http://codeplayer.blogspot.com/2006/09/python25-yield-stacklesspython.html">那段代码</a>,python2.5 增强的 yield 表达式所蕴涵的 continuation 的能力似乎终于有人拿它来发挥点实际作用了。黄毅http://www.blogger.com/profile/01060629900676151700noreply@blogger.com0tag:blogger.com,1999:blog-33791960.post-38878611225178362402007-05-30T12:16:00.000+08:002007-05-30T12:28:47.910+08:00Polymorphic Associations in Rails<a title="Permanent Link to Polymorphic Associations with SQLAlchemy" href="http://techspot.zzzeek.org/?p=13" rel="bookmark">Polymorphic Associations with SQLAlchemy</a>
<a href="http://techspot.zzzeek.org/">SQLAlchemy 老大</a>展示怎么用 <a href="http://www.sqlalchemy.org">sqlalchemy </a>实现 rails 的 <a href="http://wiki.rubyonrails.com/rails/pages/UnderstandingPolymorphicAssociations">Polymorphic Associations </a>
顺便看了下 Rails 所谓<a href="http://wiki.rubyonrails.com/rails/pages/UnderstandingPolymorphicAssociations">Polymorphic Associations </a>的介绍,才发现其实就是我很早就<a href="http://codeplayer.blogspot.com/2006/09/django-contribs-contenttype.html">介绍过</a>的 django 的 content-type app 所干的事情,app 就是插件的意思。黄毅http://www.blogger.com/profile/01060629900676151700noreply@blogger.com0tag:blogger.com,1999:blog-33791960.post-61045660485308258142007-05-26T16:23:00.000+08:002007-05-26T16:29:34.893+08:00Python and vim: Two great tastes that go great together<a href="http://www.tummy.com/Community/Presentations/vimpython-20070225/vim.html">Python and vim: Two great tastes that go great together</a>
用 python 扩展 vim ,想法倒是不新,不过第一次看到 tutotial 。
记得 tocer 说过要用 python 写个 vim 库的,不知道有没有进展哈,呵呵。黄毅http://www.blogger.com/profile/01060629900676151700noreply@blogger.com8tag:blogger.com,1999:blog-33791960.post-22661175055513838612007-05-26T15:47:00.000+08:002007-05-26T15:51:31.860+08:00Evolution of a Python programmer<a href="http://dis.4chan.org/read/prog/1180084983/">http://dis.4chan.org/read/prog/1180084983/</a>
哈哈,有点意思,再加一个:
Python 2.5 programmer:
<pre>def fact(x):
return x * fact(x - 1) if x > 1 else 1
print fact(6)
</pre>黄毅http://www.blogger.com/profile/01060629900676151700noreply@blogger.com1tag:blogger.com,1999:blog-33791960.post-10383696017019919272007-05-22T02:47:00.000+08:002007-05-22T02:57:31.400+08:00Elixir Examples有的时候在 blog 里写 wiki,有的时候在 wiki 里写 blog,有的时候在 blog 里发在 wiki 里写的 blog ;-)黄毅http://www.blogger.com/profile/01060629900676151700noreply@blogger.com0