mysql,Linux,HighPerformance,ruby on Rails

2009年11月28日星期六

attention! Ruby Core Bug #405 can be resolved. get your way.

hi,rubist,
      Today i encouner this error:
   ssl.rb:31: [BUG] Bus Error
this is annoying thing. i have try install any version ruby.but no avail.
let me think.this is macos special bug.no ruby anything.
so latest way, you can use port install any thing. this way can resolve this bug.

sudo port -v selfupdate

sudo port install ruby

sudo port install rb-rubygems

sudo gem update --system
..
go along with this way.when finished install,this rails is come back.wow!

ref:
http://redmine.ruby-lang.org/issues/show/405
http://www.jotlab.com/2009/11/08/installing-ruby-on-rails-mysql-imagemagick-nginx-passenger-with-macports/

--
tommy xiao
E-mail: xiaods(AT)gmail.com

2009年11月19日星期四

ruby编译中的二三事--你不了解的部分

如果你像我一样,对编译ruby经历过的话,肯定会遇到一些挫折,但通过google又能找到一些通用的tutorial,这些tutorial中总会给你一条"万能的指令"如:


 ./configure --enable-shared --enable-pthread CFLAGS=-D_XOPEN_SOURCE=1
但你理解这后面的flag的意思吗?我相信不一定有人能理解,我记下来,总让有心人能有所收获.

RubyCocoa compatibility and --enable-shared

In order to use RubyCocoa, the Ruby interpreter must be compiled with --enable-shared. By default, Ruby Enterprise Edition's interpreter is not compiled with --enable-shared. You can compile the Ruby Enterprise Edition interpreter with this flag by passing -c --enable-shared to its installer, like this:

./ruby-enterprise-X.X.X/installer -c --enable-shared

Please note that enabling --enable-shared will make the Ruby interpreter about 20% slower. It is for this reason that we don't recommend enabling --enable-shared on server environments, although it's fine for desktop environments.


Tcl/Tk compatibility and --enable-pthread

In order to use Tcl/Tk with threading support, the Ruby interpreter must be compiled with --enable-pthread. By default, Ruby Enterprise Edition's interpreter is not compiled with --enable-pthread. You can compile the Ruby Enterprise Edition interpreter with this flag by passing -c --enable-pthread to its installer, like this:

./ruby-enterprise-X.X.X/installer -c --enable-pthread

Please note that enabling --enable-pthread will make the Ruby interpreter about 50% slower. It is for this reason that we don't recommend enabling --enable-shared on server environments, although it's fine for desktop environments.

-D_XOPEN_SOURCE=1
这个最难理解,其实它是Clib库的一个宏,说白了就是为了支持更多的函数配置的开关
Glibc 所实现全部或部分规范下的功能有:
1.ISO C: C语言国际标准.
2.POSIX: 操作系统的 ISO/IEC 9945 (aka IEEE 1003) 标准.
3.Berkeley Unix: BSD 和 SunOS.
4.SVID: V 系统接口描述.
5.XPG: The X/Open Portability Guide.
为了实现扩展函数,可以设置D_XOPEN_SOURCE
Macro: _XOPEN_SOURCE
If you define this macro, functionality described in the X/Open Portability Guide is included. This is a superset of the POSIX.1 and POSIX.2 functionality and in fact _POSIX_SOURCE and _POSIX_C_SOURCE are automatically defined.
As the unification of all Unices, functionality only available in BSD and SVID is also included.
If the macro _XOPEN_SOURCE_EXTENDED is also defined, even more functionality is available. The exa functions will make all functions available which are necessary for the X/Open Unix brand.


That's all!

参考:
http://www.rubyenterpriseedition.com/documentation.html#_how_ree_installs_itself_into_the_system
http://hivelogic.com/articles/ruby-rails-leopard

2009年11月16日星期一

javascript语言精粹--笔记1


1.每个函数创建时都附带有一个prototype属性,它的值是一个拥有consctructor属性且值即为该函数的对象,这和隐藏连接到Funtiocn.prototype完全不同
2.通过函数字面量创建的函数对象包含一个连接上下文的连接。这被称为闭包
3.在javascript中调用函数有四种模式:
方法调用模式,函数调用模式,构造器调用模式和apply调用模式

构造器函数不为推荐,有更好的解决方法

2009年11月14日星期六

BeijingonRails,我们社区还很小,但我们很真诚!


P1010140
Originally uploaded by Robin Lu
今天去参加了beijing rails的周末聚会,来的人不多,也就三四十号人。keynote讲的也很简单,但这就是beijingonrails的开始。希望能继续这样的社区,当然壮大起来就更好了。这次聚会,看到有人在试探rails,想学又有很多疑问。提的问题我感觉还是很“外行”,不能切入重点。但这些都不是重点,其实大家最重要的是分享,rails让我感觉到的是开源的亲和力,不管你是什么时候进入,都会在很短的时候里建立自已的成就,这就是程序员的文化所在。

2009年11月13日星期五

parse querystring use oneline.ruby tips

base envirenment:
parse a HTTP query string in the shortest possible way.
q = "query1=apa&query2=apa2"
Hash[q.split("&").collect{|a| a.split("=")}.flatten]
=> {"query1"=>"apa", "query2"=>"apa2"}
absolutely shottest way:
Hash[*q.split(/=|&/)]

reference url:
http://refactormycode.com/codes/1058-parse-a-querystring

2009年11月11日星期三

在搞清楚&block的用法时看到的bechmack方法

来源:http://blog.sidu.in/2007/11/ruby-blocks-gotchas.html
以后在测试性能时可能会用到.记在此.
Benchmark.bmbm(10) do |rpt|
rpt.report("foo") do
n.times {foo('Sidu', 'Ponnappa'){|name| "Hello #{name}"}}
end

rpt.report("bar") do
n.times {bar('Sidu', 'Ponnappa'){|name| "Hello #{name}"}}
end

rpt.report("ooga") do
n.times {
the_block = lambda {|name| "Hello #{name}"}
ooga('Sidu', 'Ponnappa', the_block)
}
end
end

显示结果:
Starting benchmark

Rehearsal ---------------------------------------------
foo 0.781000 0.000000 0.781000 ( 0.782000)
bar 1.406000 0.000000 1.406000 ( 1.406000)
ooga 1.438000 0.016000 1.454000 ( 1.453000)
------------------------------------ total: 3.641000sec

user system total real
foo 0.782000 0.000000 0.782000 ( 0.781000)
bar 1.375000 0.015000 1.390000 ( 1.406000)
ooga 1.453000 0.032000 1.485000 ( 1.485000)





2009年11月3日星期二

accepts_nested_attributes_for引起的实践

如果你读了ihower的rails best practices那个ppt,一定对39页的实践看过,我跟着实现了一下,但没有成功,对于这种失败细节,很难一下子讲清楚,如果有一个demo就好了.终于来了一份:http://github.com/anathematic/has_one_problem,clone下来后,跑起来一切ok.好了,如果你这样收手,就没有注意了,在PPT中显示的form如:<% form_for :product do |f| %>....
<% end %>
这里的是:product,但我实际中,这样是跑不了的.需要指定action.<% form_for :user, :url => {:action => 'create'} do |f| %>另外,还需要注意里面的变化: <% f.fields_for :contact_attributes do |c| %>
<%= c.label :phone,'电话' %>
<%= c.text_field :phone %>
<% end -%>
注意需要加上_attributes

参考demo:http://www.box.net/shared/vm76if7zdd


另外,增加这点tips
从Doctor Nic那里扒来的To find, clone, and fork any rubygem that is hosted on github:

$ sudo gem install drnic-github
$ gh clone --search rails
$ gh fork
To personalise the gem and share it on gemcutter:

> edit the project.gemspec to have a unique name, e.g. yourname-project
$ gem build project.gemspec
$ sudo gem install gemcutter
$ gem push yourname-project-1.0.0.gem

2009年11月2日星期一

will_paginate的ajax实现

之前一直没有实现成功过ajax版的分页,心中总有心节.网上也搜索了很多教程,但总是实作不了.心有不甘.
今天静下心来,按will_paginate的wiki中介绍的方法实现出来,打包放在这里,给大家直接参考.

blogspot不能上传附件,所以放在这里:
http://www.box.net/shared/rufuee2ldm

environment:
rails 2.3.4
ruby 1.8
--
tommy xiao
E-mail: xiaods(AT)gmail.com

需要升级rubygems的注意一下这两条指令

sudo gem install rubygems-update
sudo update_rubygems

就这些。当然你的环境需要是*nix环境,win我就不保证了。

--
tommy xiao
E-mail: xiaods(AT)gmail.com