Sun 01 June, 2008

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

- 说明
- Merb框架 是一个正在崛起的类似于Rails的Ruby网络框架。以今天形势看,在未来,就Ruby网络框架领域而言,只有该框架可以与Rails抗衡。在这个网站上还有该框架的大量基础教材。
- 参考资料
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
亲爱的宝贝 如果你能活着 请你一定要记住我爱你!
妈妈:
孩子,快抓住我的手
孩子,快
快抓紧妈妈的手
去天堂的路 太黑了
妈妈怕你 碰了头
快 抓紧妈妈的手 让妈妈陪你走
孩子:
妈妈 我怕
天堂的路 太黑
我看不见你的手
自从倒塌的墙 把阳光夺走
我再也看不见 你柔情的眸
妈妈:
孩子 你走吧
前面的路 再也没有忧愁
没有读不完的课本 再也没有爸爸的拳头
你要记住 我和爸爸的模样
来生还要一起走
孩子:
妈妈 别担忧
天堂的路有些挤
有很多同学和朋友
我们说 不哭不哭
哪一个人的妈妈都是我们的妈妈
哪一个孩子都是妈妈的孩子
没有我的日子
你把爱给活着的孩子吧
妈妈
你别哭
泪光照亮不了
我们的路
让我们自己
慢慢的走
妈妈
我会记住你和爸爸的模样
记住我们的约定 来生还要一起走
add to del.icio.us. look up in del.icio.us.
add to furl
“ I urge you to please notice when you are happy, and exclaim or murmur or think at some point, “If this isn’t nice, I don’t know what is.” ”
Kurt Vonnegut
add to del.icio.us. look up in del.icio.us.
add to furl
Kernel#probably & Kernel#rarely
module Kernel def probably yield if (0...8).include? Kernel.rand(10) end def rarely yield if (0...2).include? Kernel.rand(10) end end 1_000_000.times do probably do good end rarely do evil end end # Good done 799,086 of 1,000,000 # Evil done 199,662 of 1,000,000
add to del.icio.us. look up in del.icio.us.
add to furl

- 说明
- iPhone是一款划时代的 智能手机 ,该手机的市场占有率将会越来越大!与之相关的软件业将是一个不可低估巨大而又惊人的潜力市场。未来的三、五年与之能够竞争的巨头将会出现,它将会是使用 Google Android系统 的智能手机。
- 发布时间:2008.06.09
- 发布会议:WWDC (Worldwide Developers Conference)
- iPhone 2价格: US$ 299 或者 $349 (目前价格 US$ 399)
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 furlFri 30 May, 2008

add to del.icio.us. look up in del.icio.us.
add to furl
Yesterday I received a packet in the mail from Disney's Pirates of the Caribbean Online game. I am a charter member or something like that since I joined up really soon after it launched and I might have paid for some length of time. Anyway, so this packet comes with some neat maps and such, but also some glaring spelling errors in the first paragraph.
I was shocked at those. Disney usually has much better quality control, so I'm really surprised this slipped out the door. For those of you scratching your heads about what's wrong with the circled words, let me 'splain. "You're" is a contraction of "you" and "are". The word they really wanted was "your." And "adieu" is French for "goodbye." The word they wanted was "ado," as in "Much Ado About Nothing."Come on Disney people, you can do better than that.
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
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 furlThu 29 May, 2008

目录
(一)系统环境:
- Ruby 语言 1.8.6版本, 点击这里Ruby1.8.4。要想安装多个Ruby语言运行环境请看这里。
- Rails 框架 2.0.2版本,安装方法请看这里,最简单方法是第一种方法即可。
- Windows XP 或者 Windows 2000操作系统 或者 Linux Ubuntu操作系统
- 需要一个浏览器,如FireFox1.5.0.1以上版本。
- 开发编辑工具 Notepad2 ,安装方法请单击这里,复制一个notepad2.exe,并且更名为vi.exe。
- 在Windows XP上安装Linux核心命令,点击这里。
- 如何在Windows Console下使用命令svn(下载软件),点击这里。
- 在Windows上安装版本控制系统Git作为客户端使用,点击这里。
- 安装数据库系统SQLite3,点击这里。
(二)前提条件:
- 在本机Winodw操作系统上,我们的工作目录为d:\works_rails2008。
- 你的电脑必须在线。
- 安装Rails框架插件thin:
gem install thin --no-ri --no-rdoc
(三)目的:
- 我们想要在一个已有Rails项目(版本为2.0.2)上安装和使用Rails框架最新版本2.1 RC1,注意不改变系统上的Rails框架版本。
(四)解决方案:
- 创建一个Rails项目:
rails test_project && cd test_project - 查看系统Rails框架版本,应该还是版本2.0.2。
rails -v - 查看该Rails项目的版本信息
输出结果:ruby script/aboutAbout your application's environment
Ruby version 1.8.6 (i386-mswin32)
RubyGems version 1.1.1
Rails version 2.0.2
Active Record version 2.0.2
Action Pack version 2.0.2
Active Resource version 2.0.2
Action Mailer version 2.0.2
Active Support version 2.0.2
Application root E:/coding/work_rails2008/test_project
Environment development
Database adapter sqlite3 - 安装Rails框架2.1 RC1到该Rails项目上
git clone git://github.com/rails/rails.git vendor/rails - 再一次查看该Rails项目的版本信息
输出结果:ruby script/aboutAbout your application's environment
Ruby version 1.8.6 (i386-mswin32)
RubyGems version 1.1.1
Rails version 2.0.991
Active Record version 2.0.991
Action Pack version 2.0.991
Active Resource version 2.0.991
Action Mailer version 2.0.991
Active Support version 2.0.991
Edge Rails revision 4d248543429918bc5a63e109e6f2327ffab9848b
Application root E:/coding/work_rails2008/test_project
Environment development
Database adapter sqlite3
Database schema version 0 - 查看该Rails项目目录script文件
输出结果:ls scriptabout console destroy generate performance plugin process runner server - 更新该Rails项目相关到Rails2.1 RC1内容
rake rails:update - 查看该Rails项目目录script文件,发现多了一个文件dbconsole
输出结果:ls scriptabout dbconsole generate plugin runner console destroy performance process server - 为了使用上面这个新文件dbconsole,可以使用如下命令。该命令简化和统一了打开数据库方法。
ruby script/dbconsole
>>.exit - 再次,查看系统Rails框架版本,应该还是版本2.0.2。
rails -v - 修改该Rails的相关配置文件environment.rb
vi config/environment.rb
【代码开始】
。。。
RAILS_GEM_VERSION = '2.0.991'
。。。
【代码结束】 - 创建该Rails的相关配置文件new_defaults.rb
vi config/initializers/new_defaults.rb
【代码开始】
# These settins change the behavior of Rails 2 apps and will be defaults
# for Rails 3. You can remove this initializer when Rails 3 is released.
# Only save the attributes that have changed since the record was loaded.
ActiveRecord::Base.partial_updates = true
# Include ActiveRecord class name as root for JSON serialized output.
ActiveRecord::Base.include_root_in_json = true
# Use ISO 8601 format for JSON serialized times and dates
ActiveSupport.use_standard_json_time_format = true
# Don't escape HTML entities in JSON, leave that for the #json_escape helper
# if you're including raw json in an HTML page.
ActiveSupport.escape_html_entities_in_json = false
【代码结束】 - 启动网络服务器thin,或者使用Mongrel。
thin start
(五)视听教学:
(六)必须注意的问题:
- 可能出现的问题之一:
http://ar-code.lighthouseapp.com/projects/34/tickets/166-cannot-bootstrap-undefined-method-register_template_handler-for-actionview-base-class
实例代码:
源代码 ActionView::Base::register_template_handler :liquid, LiquidView 修改为: ActionView::Template::register_template_handler :liquid, LiquidView
(七)参考资料:
(八)命令清单:
rails test_project && cd test_project
rails -v
ruby script/about
git clone git://github.com/rails/rails.git vendor/rails
ruby script/about
ls script
rake rails:update
ls script
ruby script/dbconsole
.exit
rails -v
vi config/environment.rb
【代码开始】
。。。
RAILS_GEM_VERSION = '2.0.991'
。。。
【代码结束】
vi config/initializers/new_defaults.rb
【代码开始】
# These settins change the behavior of Rails 2 apps and will be defaults
# for Rails 3. You can remove this initializer when Rails 3 is released.
# Only save the attributes that have changed since the record was loaded.
ActiveRecord::Base.partial_updates = true
# Include ActiveRecord class name as root for JSON serialized output.
ActiveRecord::Base.include_root_in_json = true
# Use ISO 8601 format for JSON serialized times and dates
ActiveSupport.use_standard_json_time_format = true
# Don't escape HTML entities in JSON, leave that for the #json_escape helper
# if you're including raw json in an HTML page.
ActiveSupport.escape_html_entities_in_json = false
【代码结束】
thin start
(九)下载文件pdf:
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


- 重要参考文献
- 参考文献
- Upgrade to Rails 2.1.0_RC1
- http://zargony.com/2008/04/02/my-favorite-features-in-upcoming-rails-2-1
- http://www.caboo.se/articles/2008/3/30/exciting-times-in-rails-land
- http://weblog.rubyonrails.org/2008/4/1/a-taste-of-what-s-coming-in-rails-2-1
- http://frozenplague.net/2008/04/03/rails-21-migration-timestamping/
add to del.icio.us. look up in del.icio.us.
add to furlWed 28 May, 2008

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
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 furlTue 27 May, 2008

add to del.icio.us. look up in del.icio.us.
add to furl
“ Perhaps it’s only a trampled package in the street—this life I pick up—and maybe my writing is its furtive unwrapping. ”
William Kohler in The Tunnel
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 furlMon 26 May, 2008

这里说的职业,并不是说他们写出的程序本身有多么神奇,恰恰相反,他们写出来的程序和我们写出来的程序,看上去并没有多大的差别。之所以,他们给我留下更职业的感觉,主要是日常工作的一些细节。
刚开始进入项目的时候,我们几个中国同事对项目完全是一头雾水,甚至Rails开发都很少,所以,在和他们一起工作的过程之中,就需要他们为我们做大量的解释,而这种时候,他们总是表现得非常耐心。有时候,语言上的障碍让我们不能一下子抓住他们说的重点,他们就会不厌其烦的一遍遍解释着,直到我们表示自己真正的理解了。
刚刚入门的人难免会问一些愚蠢的问题,他们并不会嘲笑,反而会认真的给你讲解,这会给人以极大的信心,不会因为问题的愚蠢而被打击了积极性。回顾自己之前在工作中的表现,在这一点上,我做得总是很不够,我愿意给人解释一些问题,但对于简单的问题,我有时会表现得不屑一顾。实际上,谁没有从笨笨的初学阶段走过来呢!对于初学者,鼓励的作用更大一些。最近一段时间,我会和几个新近加入项目的同事一起工作,自己刻意在这个方面注意了一下。
前些天,有一些来自产品环境的任务,要对产品数据做一些修改。这些外国同事对这种问题的想法是,写个脚本解决它,即便数量不是很大。所以,那几天几乎每天都是在写脚本。其实,对于数据量不大的一些修改,手工修改可能来更快,但是,每次都用脚本解决问题,一来可以锻炼一个用脚本解决问题的好习惯,二来可以避免做一些让自己头疼手工操作,将其转化为编程问题,解决起来更有乐趣,再有,以后遇到类似的问题,有之前的脚本可以参考。这里不得不说一下用Ruby写脚本还是很方便的,Rails项目的开发和维护都用Ruby,很大程度将二者统一起来。
项目进行性能测试,一个外国同事将测试结果放到了一个电子表格中,做成了动画效果,很高兴的给秀给我们看。因为在他看来,那是一件有乐趣的事,尤其是一群人乐呵呵的围绕在他身边看他的工作成果。
我们的开发平台是Mac,基本上就是一个Unix平台。所以,我们的外国同事经常会给我们展现他们良好的运用Unix命令的能力。他们经常将一些Unix命令组合起来,完成一些辅助开发的工作,很大程度的提高了工作效率。
在我们项目的Mingle里面,有一个Dev Standup的页面。在日常的开发中,一些解决起来会有些困难部分或者影响会比较大的部分,就会记录在这个页面里面。一方面,分布在中国和美国的同事都有机会知道对方做了些什么影响比较大的部分,另一方面,双方也可以协作解决一些对方觉得头疼的问题。
在ThoughtWorks做程序员,幽默感是不可缺少的一环。所以,经常会出现这样画面:“你能帮我一下吗?”,“不”,然后,一个人过去问什么事;“一个问题”,“一个答案”;两个人正在讨论,有一个人过来说“我觉得有道理”,另一个过来说“我不这样认为”……
add to del.icio.us. look up in del.icio.us.
add to furl
《JRuby语言实战技术》预计2008年6月出版
- 封面

- 样章
样章已经在Google cnRails论坛上(需要注册)可以下载了。
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 furlSun 25 May, 2008

- 说明
- 插件class_inputs的作用在于增加标记input的属性class,以便更好地显示页面。这里介绍这个插件的目的是让大家把它作为学习Rails插件的实例。
- 安装方法
ruby script/plugin install http://svn.jcoglan.com/classyinputs/trunk/classy_inputs
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
“ A design problem is not an optimization problem. ”
Christopher Alexander
add to del.icio.us. look up in del.icio.us.
add to furl



