Jan'uary » 2008年 » 2月
Ruby 1.9 with Symbol#to_proc and (soon) curried Procs
Jan 发表于 2008-02-27 15:04:22
收藏:
QQ书签
del.icio.us
订阅:
Google
抓虾
Tech Talk: Linus Torvalds on git
Jan 发表于 2008-02-27 14:48:32
Watch the video here. You'll find a good summary here.
Git vs SVN/CVS/etc. is not only a comparison on tool, it's a comparison on development model/philosophy.
Git vs SVN/CVS/etc. is not only a comparison on tool, it's a comparison on development model/philosophy.
收藏:
QQ书签
del.icio.us
订阅:
Google
抓虾
Load fixtures into db by hand
Jan 发表于 2008-02-25 23:02:30
Sometimes you have some fixutres want to load them into some db by hand, maybe as useful data. You can do this by rails console:
$ script/console
>> table = YAML.load_file("#{table_name}.yml")
>> ActiveRecord::Base.transaction do
>> table.each do |fixture_name, fixture|
>> ActiveRecord::Base.connection.execute "INSERT INTO #{table_name} (#{fixture.keys.join(",")}) VALUES (#{fixture.values.collect {|value| ActiveRecord::Base.connection.quote(value) }.join(",")})", "Fixture Insert"
>> end
>> end
$ script/console
>> table = YAML.load_file("#{table_name}.yml")
>> ActiveRecord::Base.transaction do
>> table.each do |fixture_name, fixture|
>> ActiveRecord::Base.connection.execute "INSERT INTO #{table_name} (#{fixture.keys.join(",")}) VALUES (#{fixture.values.collect {|value| ActiveRecord::Base.connection.quote(value) }.join(",")})", "Fixture Insert"
>> end
>> end
收藏:
QQ书签
del.icio.us
订阅:
Google
抓虾
[zz] Ruby's Thread#raise, Thread#kill, timeout.rb, and net/protocol.rb libraries are broken
Jan 发表于 2008-02-25 15:25:03
via
- Although you don't have to take my word for it, eventually you're going to have to accept the truth. Thread#kill, Thread#raise, timeout.rb, net/protocol.rb all suffer from these problems. net/protocol.rb could be fixed to use nonblocking IO (select), as could I suspect most of the other libraries, but there is no safe way to use Thread#kill or Thread#raise. Let me repeat that: there is no safe way to use Thread#kill or Thread#raise.
- Start lobbying the various Ruby implementations to eliminate Thread#kill and Thread#raise (and while you're at it, eliminate Thread#critical= as well, since it's probably the single largest thing preventing Ruby from being both concurrently-threaded and high-performance).
- Start lobbying the library and application maintainers using Thread#kill, Thread#raise, and timeout.rb to stop.
- Stop using them yourself.
- If you want to be able to kill a thread, write its code such that it periodically checks whether it should terminate. That allows the thread to safely clean up resources and prepare to "die itself".
- If you need to time out an operation, you're going to have to find a different way to do it. With IO, it's pretty easy. Just look up IO#select and learn to love it. With arbitrary code and libraries, you may be able successfully lobby the authors to add timeout options, or you may be able to hook into them yourself. If you can't do either of those...we'll, you're SOL. Welcome to threads. I hope others will post suggestions in the comments.
- If you think you can ignore this, think again. Eventually you're going to get bitten in the ass, be it from a long-running transaction that gets corrupted due to a timeout error or a filesystem operation that wipes out some critical file. You're not going to escape this one, so we should start trying to fix it now.
收藏:
QQ书签
del.icio.us
订阅:
Google
抓虾











