123
 123

Sun 08 February, 2009

Click here to bookmark this link.Channel Image14:11 Hello,V8» 梦想风暴

V8是一个开源的JavaScript引擎,它和Chrome一起来到世人面前,凭借着优异的性能表现让几大浏览器掀起了新一轮JavaScript引擎竞争。

构建V8

了解V8的第一步自然是获取V8的代码,SVN上的代码基本上可以体现出V8的最新的进展。

  svn checkout http://v8.googlecode.com/svn/trunk/ v8

V8是用C++编写的,按照通常的思路,完成获取的过程后,就该打开对应的目录,准备make。对不起,这里没有Makefile,V8是用SCons管理其构建过程的。所以,除了基础的开发工具之外,我们需要额外安装SCons。因为SCons是用Python编写的,所以,Python也是不可获取的。如果你和我一样用的是Ubuntu,安装变得很简单:

  sudo apt-get install scons

万事俱备,开始构建:

  scons

运气够好的话,就会顺利生成一个库:libv8.a。

这里介绍的只是最简单的构建过程,如果有兴趣了解更多的话,可以参考V8的文档《Download and Build》。

和V8打招呼

下面这段代码来自V8起步文档

#include <v8.h>

using namespace v8;

int main(int argc, char* argv[]) {
    HandleScope handle_scope;
    Persistent<Context> context = Context::New();
    Context::Scope context_scope(context);

    Handle<String> source = String::New("'Hello' + ', V8!'");
    Handle<Script> script = Script::Compile(source);
    Handle<Value> result = script->Run();

    context.Dispose();

    String::AsciiValue ascii(result);
    printf("%s\n", *ascii);
    return 0;
}

正如前面提到的,V8是一个JavaScript引擎,我们所需要做的就是为它提供一段JavaScript,source起到的就是这个作用。对于程序语言实现而言,拿到输入的源码之后,就是对其进行编译(Script::Compile)编译之后的结果自然就是运行了(script->Run()),这就是这段代码的主要内容。

当然这里还牵扯到一些其它内容,按照起步文档中的说法:
* handle表示一个对象指针,所有V8对象的访问都依赖于handle,按照V8垃圾收集器的运作机制,这是必需的。
* scope可以看作一个容纳任意数目handle的集合。当你用完了自己的handle,你只要删除scope,而无需一个个地删除handle。
* context是一个执行环境,它让一个单独的V8实例可以运行独立、无关的JavaScript代码。必须显式指定JavaScript运行所需的context。

我们看到了前面V8构建的结果是生成了一个库,那我们只要在自己程序中使用这个库就好了。按照通常编写C/C++程序的习惯,我们把include里面的v8.h放到我们工程的include目录下,把libv8.a放到lib目录下,通过-I指定include的目录,-L指定库目录。

  g++ -Iinclude -Llib -oHelloV8 src/HelloV8.cpp -lv8 -lpthread

好了,是时侯,让V8和我们打招呼了。

  ./HelloV8

我们会看到

  Hello, V8!






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

Sat 07 February, 2009

Click here to bookmark this link.Channel Image19:26 Rails世界:CnRails成员超过500人» 天天红玉世界

Fri 06 February, 2009

Click here to bookmark this link.Channel Image23:48 This Week in Edge Rails» Riding Rails - home

January 31, 2009 – February 6, 2009

The big news in edge Rails this week, of course, is the release of Rails 2.3.0 RC1. There’s been a fair amount of activity in the days since that happened, much of it concerned with tidying things up and fixing bugs based on early adopter issues and feedback. Thanks for all the testing, and by all means keep it up!

Nested Form Support in Active Record and Action Pack

This one is big enough that it got a whole blog entry of its own (the version that was committed has minor changes from what you’ll see there). There are two main parts to this commit. First, Active Record can now update the attributes on nested models directly, provided you tell it to do so:


class Book < ActiveRecord::Base
  has_one :author
  has_many :pages

  accepts_nested_attributes_for :author, :pages
end

Turning on nested attributes enables a number of things, including automatic (and atomic) saving of a record together with its associated children, and child-aware validations. But the big visible one is nested form support. Provided the parent model accepts nested attributes for the child objects, you can create nested forms using form_for and field_for. These forms can be nested arbitrarily deep, allowing you to edit complex object hierarchies on a single view without excessive code. For example, given this model:


class Customer < ActiveRecord::Base
  has_many :orders

  accepts_nested_attributes_for :orders, 
    :allow_destroy => true
end

You can write this view in Rails 2.3:


<% form_for @customer do |customer_form| %>
  <div>
    <%= customer_form.label :name, 'Customer Name:' %>
    <%= customer_form.text_field :name %>
  </div>

  <!-- Here we call fields_for on the customer_form builder instance.
   The block is called for each member of the orders collection. -->
  <% customer_form.fields_for :orders do |order_form| %>
    <p>
      <div>
        <%= order_form.label :number, 'Order Number:' %>
        <%= order_form.text_field :number %>
      </div>

  <!-- The allow_destroy option in the model enables deletion of
   child records. -->
      <% unless order_form.object.new_record? %>
        <div>
          <%= order_form.label :_delete, 'Remove:' %>
          <%= order_form.check_box :_delete %>
        </div>
      <% end %>
    </p>
  <% end %>

  <%= customer_form.submit %>
<% end %>

For more information, see Ryan Daigle’s excellent What’s New in Edge Rails: Nested Object Forms.

commit

Rails Guides Rework

The Rails Guides have switched from using AsciiDoc markup to using Textile markup. This has a couple of benefits: first, it makes it easier to contribute to a guide. Second, it means that we can dispense with the compiled HTML versions of the guides in the Rails tree, because we can assume any developer can build from Textile. There’s a spiffy new look for the Guides web site too – check it out at the beta site.

commit

Scaffolding Changes

There were some cleanups to the code produced by script/generate scaffold – nothing too major, but they bring the controller and views more into line with current Rails best practices. Along the same lines, the “Riding the Rails” index.html page generated in new Rails applications now includes a link to the Rails Guides.

commit commit commit


add to del.icio.us add to del.icio.us. look up in del.icio.us.   add to furl.net add to furl
Click here to bookmark this link.Channel Image04:17 This Week in Rails 3.0» Riding Rails - home

Now that Rails 2.3 has hit the release candidate phase, some of the development effort is turning to Rails 3.0. With that activity heating up, it’s time to start keeping you all informed as to happenings on the 3.0 version of the Rails source. I’ll still be posting separate “This Week in Edge Rails” information focused on Rails 2.3, so you can keep straight which changes are ready now and which still lie in the relatively distant future.

The Vision

The Rails 3 vision is based on the announcement that was made in December: we’re bringing in the key ideas from Merb to Rails, including:

  • A more modular Rails core, so you can run applications with less than the full Rails stack
  • Performance optimizations
  • Framework agnosticism with sensible defaults
  • A tested and documented API for extensions

Rails 3 promises to substantially advance the state of the art in Ruby web frameworks, while still providing migration paths from Rails 2.x and Merb 1.x.

The Source Code

The Rails 3.0 branch in the main Rails project on GitHub is the place to be to see what’s going on:


git clone git://github.com/rails/rails.git
git checkout 3-0-unstable

As the branch name might tell you, this is still a fairly experimental place to be: you probably don’t want to roll this out for production applications just yet. But it is tested code (and it’s using continuous integration to stay that way), and it already includes substantial changes from Rails 2.x thanks to the efforts of Yehuda Katz, Joshua Peek, and others. The changes so far are focused on cleaning up and improving Rails internals, rather than on adding new features.

Action Dispatch

Action Dispatch is a new Rails component which lives in Action Pack (along with Action Controller and Action View). Action Dispatch is responsible for all the processing involved with dispatching requests: request and response handling, HTTP status codes, file uploads, URL and parameter parsing, session storage, and so on.

Action View Reorganization

There are substantial changes in the Action View internals. The overall goal was to clean up a bunch of special cases and extra hooks that had built up over the years, and to leave all callers into Action View using a single unified entry point. The code cleanup has been coupled with some rearrangement of the Action View source to make it easier to find bits of functionality. This was a substantial effort; if you’re interested in a detailed look at the refactoring, you can read up on it at Yehuda’s blog

Callback Optimizations

A new method of handling callbacks removes the need for iterating through the callback list at runtime, and provides a substantial speed improvement in this area of the code. Though this is a micro-optimization that may not have much effect by itself, the hope is that by carefully optimizing as many hot spots as possible we can get a visible overall speedup in page creation and delivery – which, after all, is the point of a web framework.

What’s Next?

Obviously, there’s a long distance between where we are today and the Rails 3.0 vision. We’re fortunate to have an excellent team of core programmers devoting substantial time to making that journey. The interim goal is still to have a beta version of Rails 3.0 out in time for RailsConf in May. You can help in the same ways as with earlier versions of Rails: download the source, start testing it with your applications, and submit your own ideas and patches to the Rails Lighthouse. Rails has been a joint effort of thousands of developers over the years, and Rails 3.0 will be no different in that regard.


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

Wed 04 February, 2009

Click here to bookmark this link.Channel Image16:59 If it sounds like writing, ...» Projectionist
If it sounds like writing, I rewrite it.

Elmore Leonard


add to del.icio.us add to del.icio.us. look up in del.icio.us.   add to furl.net add to furl
Click here to bookmark this link.Channel Image15:10 Rails Guides Gets a Facelift» Riding Rails - home

There’s a brand new version of Rails coming, as you already know. What better time for a new version of some of the Rails documentation? So the Rails Guides team is pleased to announce a refresh of the Ruby on Rails Guides site, just in time for the Rails 2.3 release.

The most obvious change you’ll see is a new look, thanks to some awesome design work from Jason Zimdars. But the visual refresh isn’t all that’s going on here. We’ve also been working to update the Guides for Rails 2.3, as well as to add new guides to the list.

And there’s good news if you want to get involved too. Behind the scenes, Tore and Pratik switched our markup engine from AsciiDoc to Textile. This makes the Guides easier to write and edit and easier to build into a Rails project. If you’ve got some spare time to help out, join us in the #docrails room on irc.freenode.net, and help make the Rails Guides into a great resource in time for the 2.3 release.


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

Tue 03 February, 2009

Click here to bookmark this link.Channel Image22:03 Calling All Rails-Savvy Designers» Riding Rails - home

One thing that has been a continuing challenge for many Rails developers is finding a good designer to work with. There are certainly plenty of fantastic designers out there, but it’s often difficult to find one who is comfortable working directly in a Rails project.

In an effort to help ease this challenge, and at the behest of some interested developers and designers, the Rails Activists have set up a group for Ruby Graphics Designers. The idea is to have a place for communication: a spot where designers can ask questions about git or erb, or where developers can try to find a designer to work with.

Of course, a group without participation is nothing to crow about. If you’re a developer – or especially if you’re a designer who works with Rails – we’d love to have your participation. If you’re interested in the visual design and information architecture of Rails applications, c’mon by and say hi! And if you have other ideas about how we can encourage closer collaboration between the Rails community and the design community, we’d love to hear them.


add to del.icio.us add to del.icio.us. look up in del.icio.us.   add to furl.net add to furl
Click here to bookmark this link.Channel Image18:29 Ruby開発合宿» Matzにっき
主要開発者が松江に集合してRuby開発合宿。 matz ko1 yugui akr shyouhei shugo knu うささんは欠席(前日は松江だったのに)。 Redmineのissueをひとつずつ片づける。 だいぶ減った。少なくともアサインされた。 Ruby開発合宿は島根大学の提供でお送りしました。
add to del.icio.us add to del.icio.us. look up in del.icio.us.   add to furl.net add to furl
Click here to bookmark this link.Channel Image18:29 MacBook Pro» Matzにっき
朝、出かける前に荷物が届いたら、MacBook Proだった。 RubyCentralが「もっとOS Xサポートしっかりしてくれ」ということで、 送ってくれたものだ。Mac所有は初めてのことになる。 で、しばらく使ってみた印象は わかりやすい わかりにくい わからない であった。なにを言ってるか分からないかもしれないが、もうちょっと詳しく書いてみる。 わかりやすい ハードウェアもソフトウェアもデザインはすばらしい。 なんとなくマニュアルを読まなくても使えるような気分にさせられるし、 実際にかなりのところまで使える。 タッチパッドは思っ..
add to del.icio.us add to del.icio.us. look up in del.icio.us.   add to furl.net add to furl
Click here to bookmark this link.Channel Image11:31 If you lie to the compiler,...» Projectionist
If you lie to the compiler, it will get its revenge.

Henry Spencer


add to del.icio.us add to del.icio.us. look up in del.icio.us.   add to furl.net add to furl
Click here to bookmark this link.Channel Image11:31 Mr. Novocaine – Don M...» Projectionist

Mr. Novocaine – Don McCloskey


add to del.icio.us add to del.icio.us. look up in del.icio.us.   add to furl.net add to furl
Click here to bookmark this link.Channel Image11:31 ostomy: Surgical constructi...» Projectionist
os•to•my
[os-t uh-mee]noun
Surgical construction of an artificial excretory opening, as a colostomy or ileostomy.

add to del.icio.us add to del.icio.us. look up in del.icio.us.   add to furl.net add to furl
Click here to bookmark this link.Channel Image08:49 O NOES! My iPod Has Gone Tango Uniform!» Joey Gibson's Blog
We went to my mother-in-law’s house this weekend, because my wife was singing at her mom’s church yesterday morning. We had a nice time, and had some great Southern cooking for dinner yesterday. But on the hour-and-a-half drive home, tragedy struck: my iPod started dying. We were happily listening to ABBA’s greatest hits, when suddenly, the [...]
add to del.icio.us add to del.icio.us. look up in del.icio.us.   add to furl.net add to furl

Mon 02 February, 2009

Click here to bookmark this link.Channel Image12:12 パパ» Matzにっき
「パパ」という呼び名は恥ずかしいので、最初の子供が産まれて以来、 「お父さんと呼びなさい」と指導してきた。おかげで「お父さん、お母さん」が 定着していたわけだが、末娘だけは頑固に「パパ、ママ」と呼び続ける。 恥ずかしいからよしなさい。 そういえば、私の兄弟でも下の妹は「パパ」とか呼んでたなあ。
add to del.icio.us add to del.icio.us. look up in del.icio.us.   add to furl.net add to furl
Sources