COC风味的 Flash Builder 代码自动生产功能

Flash Builder 留给我一个大遗憾就是到了4.0还没有提供code template功能,所以要大量编码的时候,还是不得不回到FDT,因为里面积累了许多代码自动完成的模板。昨天不经意间GOOGLE到一个很有意思的东西叫做EclipseMonkey 这个工具可以以脚本的方式玩弄Eclipse的DOM,爽!于是我借用了些Ruby的 convention over configuration 腔调,写了一个自动生产属性和方法的EM脚本

下面是这个东东具体效用的slide,有图有真相,废话不多讲。

优化fLEX程序性能的各种方法

写了很多时间的Flex程序,感觉Flex/AS在内存和性能方面的设计有一定的局限。我把对这两方面的一些经验记录在此,希望能抛砖引玉。

  1. 及时移除无效的事件监听器(event listeners),以避免造成内存泄漏。
  2. 及时卸载Loaders
    当你使用Loader加载对象时,当该对象无用之后,及时调用unloadAndStop()卸载该对象,然后使用垃圾回收器(gc)回收Loader。AS3中的GC可能需要重复调用两次才能生效。特别针对静态图像文件使用这个技术可以有效地避免内存膨胀。
  3. 在你自建的类中,设立dispose()方法  –> 参见 DOJO toolkit 的 widget 组建的模板方法。
  4. 调用集合对象的disableAutoUpdate()/enableAutoUpdate() 方法,以避免在批量修改集合中对象时,造成大量无用的冗余事件。
  5. 在自建组件时,通过重载createChildren()方法来延迟子对象创建,而不要把所有的子对象的创建全部放在自建组件的构造方法中。
  6. 对象的创建是一个高资源消耗操作,因此尽量使用 ObjectPool 来复用对象。
  7. 在 invalidate/destroy/re-validate 你的组件之前,做一个lazy checking,以避免无谓的运算开销
  8. 善用常数,常数的访问速度快。常数都设成静态属性。
  9. 将工具方法以及其他各种无状态的方法写成静态方法。静态方法附属于类,因此无需对象初始化就可以使用,减少内存占用。
  10. 对于应用程序级别的事件,可以采用GlobalObject 或者 静态EventDispatcher 来做事件中转。这样设计的代价是增加了程序和这个程序级对象之间的紧偶尔,但是好处是大大降低了事件处理所需要的计算机资源。
  11. 使用green-threads来减缓大运算量逻辑对播放头的帧计算的压力。

参考阅读

The Longest Way

The Longest Way 1.0 - one year walk/beard grow time lapse from Christoph Rehage on Vimeo.

自动翻译Rails的locales YAML 文件 | Automatically translate your Rails locale YAML into other languages

刚做了个小工具,自动把Rails 的locals YAML文件翻译成各种语言。

>> 点击使用 <<

代码放在Github上:http://github.com/yi/rails-localisation-yaml-auto-translator/tree/master

I’ve been using Google translate for a while.  It’s quality of translation is excellent.  I now start working on a project need i18n support. To be more DRYer, I quickly put up a html page. It automatically translates your YAML into a wild range of other languages.

>> Click here to use <<

Ubuntu, 好用!

之前用了一段时间MacOS,感觉还成。虽然键盘布局让人感觉胳地慌,虽然在笔记本上按鼠标右键必须得用两个手,虽然。。。但开发效率的确被Windows下高许多。何况Mac长地那么酷。

可能因为太酷了,所以没过半年Mba就被偷了。于是觉得不折腾,回到Windows。之后一直看到Lifehacker中报道Ubuntu的消息,心中痒痒。最近有暇,在Windows下用Wubi装了一个Ubuntu,一用便爱不释手!第二天便将boot.ini中的默认启动改为Ubuntu。

几番折腾之后,我的Ubuntu变的让人见了心情就愉悦。在这里厚这脸皮拿出来晒晒。


其中

Google Linux Software Repositories

http://www.google.cn/linuxrepositories/index.html

Google 的 Linux 软件库极大得方便用户下载和更新 Google 开发的 Linux 平台软件,省去 Linux 初级用户望而却步的软件编译过程。Google Linux 软件库支持的 Linux 发行版包括Ubuntu, Debian, Red Hat, Fedora, openSUSE, SUSE, Mandriva等常见的 Linux 发行版……

Rails 2.1 中文书!

刚从 Rails 中文博客看到已经有 Rails 2.1 的中文书了!

Libin Pan 已经完成了这本书的中文翻译。中文书的PDF文件地址是:

http://blog.libinpan.com/download/libin-rubyonrails21-cn.pdf

Support foreign domain (CNAME forwarding) in your Rails application

Let’s say you have a blog application, which is built on Ruby on Rails. In the application, each registered user will have his personal blog page at the URL: yourblogapp.com/blogs/blogid

Perhaps, the user has his own website, say, someone.com. It will be nicer to let the user have a custom domain in your blog application (in this example: blog.someone.com).

After some digging, I found the implementation in Rails is quite simple and straightforward.

Requirements

  1. Your application must running on a dedicated IP. Or at least, if running on a virtual hosting without a  dedicated IP, it must be set to the default vhost site, in order to allow all requests from foreign domains be routed to your application.
  2. In your blog table add a field to record custom domain set by the user. Something like:
    add_column(:blogs, :custom_domain, :string, :limit=>200)
    And provide an web interface to let the user custom it.

Implementation in Rails

Rails has a built-in URL rewriting module, which redirects incoming requests to controllers and actions. This router makes things a lot easier. But the packaged Routing module only understand request from native domain, and so all we need to do is to extend it to parse requests from foreign domain.

The Routing module provides two extendible methods to define the condition for request parsing. Dan Webb’s Request Routing plugin (alternative link) has already taken care of them and give extra conditions for defining map rules.

So, install the plugin:

ruby script/plugin install http://svn.danwebb.net/external/rails/plugins/request_routing/trunk/

Then create a new map rule in routes.rb

# route all requrest from foriegn domain to boards controller
map.connect(
‘:action/:id’,
:controller => ‘blogs’,
:conditions => {
:domain => /\A(?!(yourblogapp\.com))/i
}
)

This map rule says all requests which are not coming from “yourblogapp.com” will be redirect to the blogs controller.

Then in blogs_controller, you will probably have something like:

def retrieve_blog

@blog = Blog.find_by_id(params['id'])

…..

end

Change this retrieving method to:

def retrieve_blog

@blog = (request.domain != ‘yourblogapp.com’)  ?
Blog.find_by_id params['id']  :
Blog.find_by_custom_domian request.host.downcase

…..

end

Job done.

What the user needs to do

To custom a domain for his blog, the user need to do following two setup:

  1. Create a CNAME record for this domain: blog.someone.com, the destination of which is the domain of your application: yourblogapp.com
  2. Log in your application, and add “blog.someone.com” to his preference settings.