Sat 07 June, 2008

add to del.icio.us. look up in del.icio.us.
add to furl

- 说明
- Ruby语言库gchartrb是一件穿着Ruby语言的外套,其核心是基于Google API Chart 。
- bd7lx说:“不需要(自身)server端的图形处理库,计算(大权)交给强大的google(集群服务器)。给出(源自于数据库的)数据,返回漂亮的图形。”
- 中文总是问题。上面的图形是通过Rails软件所生成的。
- 参考资料
- http://www.infoq.com/articles/bass-google-charts-gchartrb
- http://blog.runrails.de/2008/05/21/charts-und-diagramme-mit-der-google-api-in-rails-erzeugen/
- http://blog.codefront.net/2007/12/12/gchartrb-ruby-google-chart-api/
- http://railsontherun.com/2007/12/10/google-chart-gem
- http://chinaonrails.com/topic/view/1063.html
add to del.icio.us. look up in del.icio.us.
add to furlFri 06 June, 2008

add to del.icio.us. look up in del.icio.us.
add to furl
http://code.google.com/p/pyftpdlib/
文档都不错,还有例子,我就照搬了,然后把windows service的套上去:
import win32serviceutil
import win32service
import win32event
from pyftpdlib import ftpserver
FTP_USER = 'nps_card'
FTP_PASS = 'nps_card'
HOME_DIR='d:\nps_data\'
class MyFtpd(object):
def __init__(self):
self.ftpd = None
def main(self):
# Instantiate a dummy authorizer for managing 'virtual' users
authorizer = ftpserver.DummyAuthorizer()
# Define a new user having full r/w permissions and a read-only
# anonymous user
authorizer.add_user(FTP_USER, FTP_PASS, HOME_DIR, perm='elradfmw')
authorizer.add_anonymous(HOME_DIR)
# Instantiate FTP handler class
ftp_handler = ftpserver.FTPHandler
ftp_handler.authorizer = authorizer
# Define a customized banner (string returned when client connects)
ftp_handler.banner = "pyftpdlib %s based ftpd ready." %ftpserver.__ver__
# Instantiate FTP server class and listen to 0.0.0.0:21
address = ('', 21)
self.ftpd = ftpserver.FTPServer(address, ftp_handler)
# set a limit for connections
self.ftpd.max_cons = 256
self.ftpd.max_cons_per_ip = 5
def start(self):
# start ftp server
self.ftpd.serve_forever()
def stop(self):
self.ftpd.close_all()
class MyService(win32serviceutil.ServiceFramework):
"""NT Service."""
_svc_name_ = "PyFtpService"
_svc_display_name_ = "Py Ftp Service"
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
# create an event that SvcDoRun can wait on and SvcStop
# can set.
self.stop_event = win32event.CreateEvent(None, 0, 0, None)
self.myftpd = MyFtpd()
def SvcDoRun(self):
self.myftpd.main()
self.myftpd.start()
# now, block until our event is set...
win32event.WaitForSingleObject(self.stop_event, win32event.INFINITE)
def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
self.myftpd.stop()
win32event.SetEvent(self.stop_event)
if __name__ == '__main__':
win32serviceutil.HandleCommandLine(MyService)
然后用另外一个ftp client的库,ftputil,
http://ftputil.sschwarzer.net/trac
随后,做好server,放到实际环境下实验,结果发现还是存在问题,估计就是外网和内网之间的互联互通上的防火墙的问题,也会造成没有响应,后来发现去掉service,server端看日志,发现server并没有退出,但是不响应,看看例子上的代码,有个地方我删除了,有可能就是nat的问题,加上:
ftp_handler.masquerade_address = '10.146.x.188'
passive_ports的范围,似乎nat也做了限制,我不规定范围了。
代码改好之后,好像还是有点问题,还是有点晕,谁了解这些,可以和我说说么?期待有人和我说说。。。...
add to del.icio.us. look up in del.icio.us.
add to furl
Enumerable#pick
module Enumerable def pick(percentage) select do |element| percentage.chance.happens? end end def some pick 50.percent end def few pick 20.percent end def many pick 80.percent end end
add to del.icio.us. look up in del.icio.us.
add to furl
YouTube now allows you to add hotspots and notes to your videos.
I did a quick experiment with a Monkeybars screencast and the ability to add additional information is sweet. I can see this as particularly handy for instructional vids where you don’t want to belabor something in the main content, but still want to offer details or linkis to more information.
The video quality is still not quite all that spiffy, but readable. Overall, this is quite nice (but note some of the comments in the above link).
add to del.icio.us. look up in del.icio.us.
add to furl
Big thanks to Sean Tierney of JumpBox for organizing yesterday’s Tempe Nerds lunch.
Great turn-out. Check out some photos.
The next one is noon, June 19, at The Tavern on Mill (404 S. Mill, Tempe; map)
add to del.icio.us. look up in del.icio.us.
add to furl
I posted some links to the Refactor Phoenix sub-topic on Reddit:
http://reddit.com/r/refactorphoenix/
There are also some links on the Refactor home page.
add to del.icio.us. look up in del.icio.us.
add to furl
Since Ruby 1.8.7 is out I went and updated the API docs on Ruby-doc.org .
It’s bothered me (and others) that running rdoc over the source using the default settings grabs yaml.rb and friends and ends up sticking additonal methods on core classes that would only be there were one to require yaml.
People have also asked me why so many files appear in both the core and stdlib sections. Ideally there would be just one place to look for docs, but for now rdoc gives cleaner results when files under lib/ and ext/ are processed apart from the core files.
So, for the 1.8.7 docs, I edited the .document files to restrict what appears in the core section. What’s missing from core should appear in stdlib.
add to del.icio.us. look up in del.icio.us.
add to furl
Hot on the heels of the 0.6 Monkeybars releases comes spiffy new tutorials.
Here’s what’s rockin’:
- Installing: Part 1 – Getting Monkeybars, creating a new project
- Installing: Part 2 – The contents of a generated Monkeybars project
- Installing: Part 3 – Using the Monkeybars generator
- Configuring Netbeans
- Overview of Monkeybars
Catch Monkey Fever and start building kick-ass cross-platform GUI applications in Ruby!
add to del.icio.us. look up in del.icio.us.
add to furl
There was a Script Bowl contest at JavaOne , pitting Groovy, JRuby, Jython and Scala against each other in a set of application challenges.
Long story short: JRuby ruled .
The client application entry was a Monkeybars Twitter app. It won, of course
Note: edited to correct for idiotic use of SunOne instead of JavaOne.
add to del.icio.us. look up in del.icio.us.
add to furl
David was on a panel at the recent JavaOne, and eWeek has a few quotes from him in an interesting article on the continued rise of the Ruby language.
add to del.icio.us. look up in del.icio.us.
add to furl
Last night’s Refactor meeting was great. A big thanks to Austin for his detailed Git talk, and to David for demoing some git repo sharing.
Austin has posted his slides on his website:
http://uberhip.com/projects/presentations.html
And you can clone it from the repo with: git clone http://uberhip.com/git/gitintro.git
Earlier in the day David and I were poking around with git-daemon, getting the parameters Just So and experimenting with basic repo sharing. It crossed my mind that the process for selecting the git-daemon arguments and kicking off the process should be automated with a script; David, though, was way ahead of me and quickly had a working version running.
We now have a nice little Ruby script that makes sharing a git repo snake simple. David posted the code to the Refactor mailing list.
You just drop the script in your bin dir, and when you want to share a git repo you cd to the root of the working directory and run share_git_repo (or whatever you’ve named it).
It will figure out the correct base path and display the URL needed by the client.
add to del.icio.us. look up in del.icio.us.
add to furl
The topic for the next Refactor Phoenix meeting, Wednesday May 28 is git.
Git is a distributed version control system (DVCS) with increasing popularity.
Along with Mercurial, Darcs, and Bazaar, DVCS’s are increasingly winning the hearts and minds of hackers everywhere. Austin Godber of JumpBox will give a presentation on the basics of git installation, local repository setup and basic usage. You’ll also learn how to publicly share, read only, a repo over HTTP to offer public, read-only access.
David and I will relate our experience with gitorious.org and its use for managing open-source projects.
Some worthwhile places to start learning about git and distributed version control systems:
- Distributed Version Control Systems: A Not-So-Quick Guide Through
- Intro to Distributed Version Control
- Git
- Mercurial
- Bazaar
- Darcs
Refactor Phoenix meets on the 4th Wednesday of each month, at Boulders on Broadway in Tempe. See the Web site for more details.
add to del.icio.us. look up in del.icio.us.
add to furl
May 31 is Desert Code Camp
It’s held at UAT in Tempe:
University of Advancing Technology
2625 W. Baseline Road
Tempe, Arizona 85283
Well worth checking out, though there seems to be a heavier slant towards Microsoft tech than in than past.
Also, a word on the Ruby presentations: David will not be available that day because of prior commitments; his Ruby talks might be canceled, though Logan will probably be covering at least one of them.
I will likely be attending, but prefer to play spectator this time.
add to del.icio.us. look up in del.icio.us.
add to furl
Don’t forget: Desert Code Camp tomorrow, Saturday May 31.
Logan will be leading several Ruby talks, with topics covering basic Ruby, JRuby, and building kick-ass GUI apps with Monkeybars.
I’ll be there, too, lending a hand and grooving to the geek vibe.
If you’re in or around Phoenix, don’t miss this.
add to del.icio.us. look up in del.icio.us.
add to furl

Happy Camper Studio’s own David Koontz will be part of an impressive Ruby panel at the upcoming Java CommunityOne
David will be joined by JRuby luminary Thomas Enebo (Sun Microsystems, Inc.), Rich Manalang (Oracle), Mark Driver (Gartner), and others.
All of us fellow Campers are damned proud of David’s pioneering work with Monkeybars, and if you’re at all interested in super-sweet cross-platform GUI application development you have to check it out.
David will be attending both CommunityOne and JavaOne, and if you’re also going be sure to catch the Ruby panel and then track him down to learn more about the future of Ruby desktop development
add to del.icio.us. look up in del.icio.us.
add to furl
On this date in 1976, The Ramones released their self-titled debut album. 14 songs in less than 28 minutes. It contained the singles, “Blitzkrieg Bop” and “I Wanna Be Your Boyfriend”. The singles didn’t chart and the best the album could muster was a peak at the #111 spot on the U.S. albums chart. Nonetheless, legend was born. The legendary punk band from Queens, NY turned in their leather jackets for good in 1996.
From The Post Punk Progressive Pop Party
See also Bands That Changed Everything: The Ramones
add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furl
Like Chad, I think MagLev’s initial performance numbers will hold up. It’s possible that as it matures it will get slower, but it could get a lot slower than it is now and still easily be the fastest Ruby VM around.
And I agree with Chad that it might even get faster. I’ve also spent some time investigating how to make Ruby run on a Smalltalk VM, and it’s a really close fit. During the presentation at RailsConf, either Avi or the Gemstone guys revealed that they had modified their Smalltalk VM by adding two new bytecodes aimed at Ruby. I’ll go so far as to speculate: it’s likely that those two bytecodes deal with variadic methods and creation/lookup of dynamic instance variables. It sounds as though the core Ruby language is nearly complete on top of that base, so it’s easy to imagine that the early, hurried implementation of those two new bytecodes could be optimized further. And some of the Ruby features that have hurt JRuby’s performance will be no problem on a Smalltalk VM—ObjectSpace, for example, can work using the same facilities that Smalltalk’s development tools use today.
The persistence story is amazing. Avi and the team at Gemstone plan to implement an interface that is similar to ActiveRecord, but cleaner, since the object/relational impedance mismatch no longer applies.
Finally, there’s the question of licensing. I’ll be shocked if MagLev is open-source, but I think there’s room for a proprietary Ruby implementation. The team has committed to complying with RubySpec, which means I’m not very worried about compatibility. Most Ruby projects won’t need MagLev, but the ones that do will gladly pay for a top-notch, supercharged implementation with great scalability and persistence stories.
I’m definitely looking forward to hearing more about MagLev over the next few months.
add to del.icio.us. look up in del.icio.us.
add to furl
Class#initialize_with
class Class def initialize_with(*params, &block) attr_reader *params define_method(:initialize) do |*args| params.zip(args).each do |param, arg| instance_variable_set("@#{param}", arg) end instance_eval(&block) if block_given? end end end class Account initialize_with :username, :password do p "Initializing..." # Initialization code end end Account.new 'joe', 'secret' "Initializing..." # => #<Account @password="secret", @username="joe">
add to del.icio.us. look up in del.icio.us.
add to furlThu 05 June, 2008

“ You have to know how to accept rejection and reject acceptance. ”
Ray Bradbury
add to del.icio.us. look up in del.icio.us.
add to furl
Herman Düne – I Wish That I Could See You Soon
add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furl
”>- Rails 2.1最重要的改进功能
- 模型方法named_scope
- 软件包gem的配置方法
- 测试数据fixtures文件
- Rails 2.1其它改进功能
- 参考资料
add to del.icio.us. look up in del.icio.us.
add to furl
拜IE6所赐,我们的系统刚刚上线,便有一个bug浮出水面。经过验证,这是IE6处理直接打开附件(如PDF、PPT等)的错误。不过,好在这是一个广泛遇到的问题,使得这个bug连午饭时间都没有坚持到,便被消灭了。
按照对客户的承诺,我和另外一个同事要在办公室支持到晚上10点。上午的时候,我们的QA和客户努力了三个小时,并没有发现其它问题,于是,我们想当然的认为我们可以按“点”下班。就在我们俩准备收拾东西回家睡觉之前,从睡梦中醒来的客户终于发现了bug。于是,我们只好在深夜来临之际,开始了bug征服之旅。
有bug不是什么坏事,发现总是比不发现好。
在客户和PM压力之下修改代码并不是什么愉快的经历,好在bug们都是一些友好的家伙,很容易就定位到。不过,因为客户在线,所以,必须强迫自己把事情做得尽可能按部就班:本机测试、提交到主干、提交到分支、部署到测试环境……
感谢之前大家辛勤努力编写的测试,让我们很容易就知道自己的修改在系统内会造成怎样的影响。通过所有测试的那一刻,心头如释重负。在这个原本很是紧张的时候,多了一份自信。我喜欢这种感觉,虽然忙碌,但依然从容,一切尽在掌握之中。
这个无眠的夜里,身边还有自己的Pair,有专程赶来帮助我们进行验证的项目组的老大哥,当然,还有一直都很辛苦的PM,一个敬业的团队。
add to del.icio.us. look up in del.icio.us.
add to furlWed 04 June, 2008

add to del.icio.us. look up in del.icio.us.
add to furlTue 03 June, 2008

印象中,这应该是一个手忙脚乱的阶段,一大群人奔前跑后,忙着处理各种各样的问题,尤其是bug。许多人回忆自己经历的时候,往往会很有成就感的说,在某某程序发布之前,忙了一整夜,终于在程序发布之后,回到家里,一觉睡了N个小时,俨然一副历经沧桑的样子。自己经过的,既有有过连续十几天工作十几个小时,为了赶上发布日的经历,也有连续几个熬到后半夜改bug的痛苦。虽然这些都是不错的日后谈资,但当时,那是透支的感觉。
现在,我在等待发布。
是的,等待!
Story的开发工作早就已经完成,bug修改也到了尾声。代码已经冻结,Mingle上可供开发的卡已无踪影,有一种闲暇无聊的感觉。
这已经不是第一次体验发布前的闲暇了。记忆中,最近做过的几个项目,到了最后的几天,都会出现无卡可做的情况。最极端的是有一次,在PM的陪伴之下,打了多半天的游戏。
对比之前的经历,这样的经历显得很特别。原本在我的印象中,越是临近发布,应该越是忙碌,而这种一下子闲下来的感觉,真的是让人有些不适应。
这个时候,PM就成了给大家找事的人。比如,他会组织大家进行一些讨论,看看之前那些做得好,做得不好,以便在后续的工作中进行改进。比如,他会把一些属于下一个阶段的任务拿过来,让大家分析一下,提前热热身,有些手快的家伙,甚至会顺便把一些任务做完。
这样难得的清闲,多半要归功于合理的计划和控制。其实,想想之前的经历,最终期限并不是合理规划出来的。事实上,大多数情况下,对于要做什么,以及这些工作的工作量究竟有多大,并没有很好的估计,所以,往往就是指定一个发布的日期,剩下的就是靠人了,其结果就是为了赶上发布日期,拼命的加班加点,那种透支需要很长一段时间才能恢复过来。
而现在做项目,所要做的一切都是经过大家一起估计出来,包括客户和开发团队,大家对于软件开发的实质认识得比较清楚,所以,不会做一些杀鸡取卵的事情,于是,所有的一切,都会按照预期一步步进行:开发团队也不会为了追赶进度,而损失了软件的内在质量;客户会重新认识他需求的价值所在,做好优先级排序,而不会不明就里的要求全部完成。这是一个合理的开发过程,一种软件开发应有的状态。
准备发布了!
add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furl
还真有人作了一个包,我试了试,感觉还挺简单,也就是那几个动作,作一次就会。它的地址是:
http://www.nongnu.org/fab/index.html
我在archlinux下安装,碰到了一些问题,需要修改几个地方:
1)os.getlogin(),在gnome界面下使用,会报错,用pwd.getpwid(os.getuid())[0]来代替
2)fab的程序中,exit(1)之类的,要改成sys.exit(1)
保证程序不错后,还要保证paramiko这个包先安装,这个包是ssh用的,然后python setup.py install安装。
使用fabric,就是简单的写fabfile文件,文件就是py文件,内容就是几个简单的函数和变量:
1)变量
set(
fab_hosts = ['172.16.7.13'],
fab_user = 'hzg'
)
fab_hosts是远端服务器ip,fab_user是ssh的用户
2)函数
def deploy():
"Build the project and deploy it to a specified environment."
local("tar zcvf fx_analysis.tar.gz fx_analysis --exclude='*.XLS'")
put("fx_analysis.tar.gz", "/home/hzg/work/fx_analysis.tar.gz")
run("cd /home/hzg/work/; tar zxvf fx_analysis.tar.gz")
deploy函数,由fab来调用,其中它又调用了几个:
local()=>本地机器运行
put()=>上传文件到远端服务器
run()=>在远端服务器运行
还有一些:
send(), download, sudo()等之类,都很简单明了
3)使用方法
很简单,就一个fab,运行fab,自动会去找fabfile,deploy会显示出来。
要运行deploy的步骤,也很简单,fab deploy就可以了
(mypy)[hzg@myhost work]$ fab
Fabric v. 0.0.5, Copyright (C) 2008 Christian Vest Hansen.
Fabric comes with ABSOLUTELY NO WARRANTY; for details type `fab warranty'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `fab license' for details.
No commands given.
Available commands are:
deploy : Build the project and deploy it to a specified environment.
help : Display Fabric usage help, or help for a given command.
license : Display the Fabric distribution license text.
list : Display a list of commands with descriptions.
set : Set a Fabric variable.
shell : Start an interactive shell connection to the specified hosts.
warranty : Display warranty information for the Fabric software.
Done.
(mypy)[hzg@myhost work]$ fab deploy
这样就能自动远程部署了,当然可能功能上没有capistrano多,不过已经足够了。
...
add to del.icio.us. look up in del.icio.us.
add to furl
Conference Summary Video
Wow, what a great conference! There was a lot of energy flowing at RailsConf this year. Overall I’d rate this year as head and shoulders above last year. I’m not going cover much here, but will direct you attention to a Rails Envy VideoCase that Greg Pollack put together. The video is a series of very short interviews with a number of presenters giving summaries of their own talks. The only downside with the video is that I wish it was available before the conference. I see there were a number of interesting talks that I missed.
Followup on the “Modelling Dialogue”
Joe O’Brien, Chris Nelson and myself did a dialogue style presentation on the difference between object modelling and data modelling. The most common question I got after the talk was requests for book titles to learn more about object oriented modelling. Here are the books that Joe, Chris and I have recommended:
- Domain Driven Design—Eric Evans
- AgileSoftware Development, Principles, Patterns, and Practices—Bob Martin
- Refactoring: Improving the Design of Existing Code—Martin Fowler
add to del.icio.us. look up in del.icio.us.
add to furl
RubyEnRails 2008 is a Dutch Rails conference happening on June 10th. They still have a few tickets left, so if you’re able to go, there’s still the option. Lots of good speakers there including Charlie from JRuby, Obie, and the Phusion Passenger guys. I’ll be doing a iChat Q&A session as well.
add to del.icio.us. look up in del.icio.us.
add to furl
Gregg Pollack has made a great video with interviews of speakers and attendants at RailsConf as a way of giving people who weren’t there a taste of what it was like. The result is 36 minutes of video and really worth watching. Check it out.
add to del.icio.us. look up in del.icio.us.
add to furlMon 02 June, 2008

add to del.icio.us. look up in del.icio.us.
add to furl
The Musician’s Birds of a Feather gathering at RailsConf was great. We had a room full people, two guitars, a ukulele, a flute, several harmonicas and an improvised drum set. Unfortunately, one of the guitars was an electric travel guitar which had a dead battery, therefore no way to really hear it.
However, the other guitar was a nice Epiphone accoustic which was passed from player to player. It became the quickly became the basis for most of the music performed that night.
I want to thank Artichoke Community Music for supplying the guitar. Travelling with a guitar by plane is a big pain, so I arrived with nothing to bring to the music BOF. I called several local music stores looking for a guitar that I could rent for an evening. Artichoke music said they had a “not-for-profit” guitar that they would let me borrow for a day. Not many stores would do that for an out-of-town stranger.
So, if you’re in Portland looking for a good guitar store, check out the great people at Artichoke Community Music.
add to del.icio.us. look up in del.icio.us.
add to furlSun 01 June, 2008

add to del.icio.us. look up in del.icio.us.
add to furl
Rails 2.1 is now available for general consumption with all the features and fixes we’ve been putting in over the last six months since 2.0. This has been a huge effort by a very wide range of contributors helping to make it happen.
Over the past six months, we’ve had 1,400 contributors creating patches and vetting them. This has resulted in 1,600+ patches. A truly staggering number. And lots of that has made it into this release.
New features
The new major features are:
- Time zones (by Geoff Buesing): Tutorial | Introdction | Railscast
- Dirty tracking: Introduction (partial updates) | Railscast
- Gem Dependencies: Introduction | Railscast
- Named scope (by Nick Kallen): Introduction | Railscast
- UTC-based migrations: Introduction | Railscast
- Better caching: Introduction
Thanks to Ryan Daigle for the feature introductions and Ryan Bates for the Railscasts. It makes writing the release notes so much easier :).
As always, you can install with:
gem install rails
...or you can use the Git tag for 2.1.0.
Enjoy!
add to del.icio.us. look up in del.icio.us.
add to furl

- 说明
- 该插件更好地改进和解决如何从数据库一次性调出数据记录的方法。随着数据库数据记录的不断增加,这个问题是所有Rails软件都会面临的问题。
- 重要参考资料
- 参考资料
add to del.icio.us. look up in del.icio.us.
add to furl
Kernel#maybe etc with Percentage::Chance
class Percentage def chance Chance.new(self) end class Chance attr_reader :odds, :happens alias :happens? :happens def initialize(percent) @odds = percent.amount @happens = @odds > Kernel.rand(100) end def of(&block) yield if happens? end end end module Kernel def maybe(percent = 50.percent, &block) if block_given? percent.chance.of &block else percent.chance.happens? end end def probably(&block) 80.percent.chance.of &block end def rarely(&block) 20.percent.chance.of &block end end
add to del.icio.us. look up in del.icio.us.
add to furlSat 31 May, 2008

add to del.icio.us. look up in del.icio.us.
add to furl



