12/27/2010

Realtime Encoding

Transloadit 介紹一篇新的服務即時轉檔服務,也就是在上傳過程同時進行轉換,讓轉檔過程速度加快150倍以上。

從技術面思考如何做?

  • 上傳的時候如何將檔案切成 {chunk1, chunk2,...}
  • Transloadit使用node.js同時自行針對上傳過程進行拆解(file upload parser)

  • chunk 丟進ffmpeg server再組合成轉檔目的檔
  • Transloadit使用ffmpeg自行建立server用來處理四面八方的chunk資料,真正麻煩的地方 !

最近思考了一堆轉檔想法,RealTime轉法滿值得學習。

12/26/2010

空中樓閣理論

凱因斯曾說:

投資人不該把精力浪費在估算股票的真實價值,而該用於分析投資大眾未來的動向,以及在樂觀時期,他們會如何把希望建築為空中樓閣.

原文

The Castle-in-the-Air Theory, one of the Investment Theories, is rather opposite in its postulations compared to the Firm Foundation Theory. The Firm Foundation Theory believes and tries to understand the intrinsic value of any stock or other asset. The castle-in-the-air theory delves deep into another aspect of investing behaviour - it tries to unravel and understand the psychic values and behaviour of the group of investors. This theory was made popular in 1936 by John Maynard Keynes, a famous economist (as also an investor) and the theory postulates that the investors try to build a sort of castles in the air and think of the probable price rise in the future than estimating the intrinsic values of stocks. Once the investor has estimated this, he/she tries to beat the crowd by building positions in the preferred stocks before the crowds (read other investors) start buying those stocks and the price surges ahead.

關鍵的操作道理!

12/23/2010

Apache Tapestry 5.2.4 : Code Less, Deliver More

Apache Tapestry 5.2.4 發佈

從2009/4發佈5.1.0.5版本經過18月時間,發佈新版5.2.4,Tapestry創始人Howard Lewis Ship針對新版本主要的改進:

Removal of Page Pooling

一些大型專案會有大量記體消耗問題;因為Tapesry Page採取Pooling機制,有一個請求進來必須綁定Page Instance,當Page結構 (Page裡面一堆元件)是夠大,Page Pooling又同時多工請求下易造成記憶體不夠使用。

新機制每一個請求都是面對相同single page tree透過額外轉換(extra transformation step)將Page與Componet所產生短暫實例放入Per-thread Map中。透過新機制不需要額外要求Page Instance同時也不需要建構多個Page Instance,將能有效防止大量記憶體消耗。

Live Service Reloading

Service在實作的過程可在大部份環境直接看到執行結果,在開發過程中減少不斷重新佈署(省時間)

ClassTransformation API Improvements

重新設計ClassTransformation API可Java環境中進行好玩ClassTransformation,而不再被限於Javassist API

Query Parameter Support

QueryParameter機制方便Page存取從Request URL帶來資料

Testing

加強整合Selenium更容易可測試Tapestry Page。

JSR-303 Support

支援Bean Validation於 Client-Side與Server-Side

Documentation

明年應該會有Tapestry 5 In Action !

這一次最大改變應該在Tapestry 內部機制強化,如果您還在選擇Java Web Framework或許可考慮Tapestry的高生產力、高執行效率之開發架構 。

參考 Announcing Tapestry 5.2

Rack URLMap

Rack提供簡易routing 功能,能夠不同URL (PATH_INFO, SCRIPT_NAME) 執行不同的middleware。

[code lang="ruby"] app = Rack::Builder.new do use Rack::CommonLogger use Rack::ShowExceptions map '/env' do run Proc.new {|env| [200, {"Content-Type" => "text/html"}, env.inspect]} end map '/' do run lambda {|env| [200, { 'Content-Type' => 'text/plain' }, ["Hello World!"] ] } end map "/lobster" do use Rack::ShowExceptions run Rack::Lobster.new end end Rack::Handler::WEBrick.run app, : Port => 9292 [/code]

或者利用 Rack::URLMap 組出 url path 對映 app之關系

[code lang="ruby"] hello_app = lambda {|env| [200, { 'Content-Type' => 'text/plain' }, ["Hello World!"] ] } env_app = Proc.new {|env| [200, {"Content-Type" => "text/html"}, env.inspect]} lobster_app = Rack::Lobster.new app = Rack::Builder.new do use Rack::CommonLogger use Rack::ShowExceptions run Rack::URLMap.new '/' => hello_app, '/env' => env_app, '/lobster' => lobster_app end Rack::Handler::WEBrick.run app, : Port => 9292 [/code]

Rack 提供urlmap算是簡易的routing功能, 通常都是Framework自行撰寫routing機制,內建Rack Routing僅限單純應用。

12/17/2010

Rack Middleware Stack

Rack middleware針對Http要求與Http回覆進行過濾(filter)。換言之,Rack機制可撰寫自己filter用來控制或加強由Rack app所產生內容。Rack內部實作利用 pipeline design pattern,separation of concerns 觀念,因此可任易組合filter針對需求或你自行開發架構。

Rack內建許多處理Http相關的Filter,分成Authentication, Authorisation , Caching, Decoration, Monitor,...,所以基本上應該想得到都存在。

如何利用Rack::Builder建構middleware stack?

12/15/2010

Virtual Users in vsftpd

Virtual Users? 基本上就是不想在系統中開帳號,針對ftp需要開啟所需要帳號既可。

Ubuntu環境中先安裝下例套件,其中當然有很多PAM 認證方式,我選擇最容易方法使用libpam-pwdfile

[code lang="shell"] apt-get install vsftpd apt-get install libpam-pwdfile 新增virtual user touch /etc/vsftpd/passwd htpasswd -c /etc/vsftpd/passwd partner1 htpasswd /etc/vsftpd/passwd partner2 [/code]

修改vsftpd認證方式,將/etc/pam.d/vsftpd全部注解(除非還要使用不同的PAM認證),加入pam_pwdfile認證方式

[code lang="shell"] sudo vim /etc/pam.d/vsftpd auth required pam_pwdfile.so pwdfile /etc/vsftpd/passwd debug account required pam_permit.so debug [/code]

微調/etc/vsftpd.conf,關掉不必要anonymous 登入

[code lang="bash"] listen=YES anonymous_enable=NO local_enable=YES write_enable=YES local_umask=022 dirmessage_enable=YES xferlog_enable=YES connect_from_port_20=YES #chroot 所指定的目錄 chroot_local_user=YES secure_chroot_dir=/var/run/vsftpd pam_service_name=vsftpd rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key user_config_dir=/etc/vsftpd/user #比較重要設定將guest_enable開啟,否則會出現500 OOPS: cannot locate user entry:partner1錯誤 guest_enable=YES #vsftpd需要一個system account去替代virtual users,否則會找不到目錄( cannot locate user entry),剛好ftp account是安裝時預設建立直接使用預設就可以。 guest_username=ftp write_enable=YES anon_world_readable_only=NO anon_upload_enable=YES anon_mkdir_write_enable=YES anon_other_write_enable=YES local_root=/home/partner [/code]

分別調整partner1與partner2 權限

[code lang="bash"] vim /etc/vsftpd/user/partner1 vim /etc/vsftpd/user/partner2 [/code]

12/14/2010

這一季書單

"Business Model Generation: A Handbook for Visionaries, Game Changers, and Challengers" Alexander Osterwalder; Paperback; $23.07

"Just Enough Software Architecture: A Risk-Driven Approach" George H. Fairbanks; Hardcover; $69.75

"Hackers: Heroes of the Computer Revolution - 25th Anniversary Edition" Steven Levy; Paperback; $14.04

原文書真貴!

12/10/2010

Conque Shell

Conque Shell 不錯小工具,簡易terminal emulator 可以將畫面顯示於vim buffer中,最好都不要跳出vim 編輯畫面!

 vim + mysql

下載安裝 git://github.com/chrismetcalf/vim-conque.git

使用方式

[code] :ConqueTermVSplit bash --login :ConqueTermSplit :ConqueTermVSplit :ConqueTermTab [/code] 參考 Conque Shell

12/08/2010

Rack Concept

Rack提供Ruby世界中Web Servers與Web Frameworks之間的橋樑。重要位置如同J2EE中Servlet,所有Java Web Application都透過相同介面與底層溝通。

如同Christian Neukirchen所言:

I noticed that there is a lot of code duplication among frameworks since they essentially all do the same things. And still, every Ruby web framework developer is writing his own handlers for every webserver he wants to use ...
However, in essence, dealing with HTTP is rather easy. In the end , you get a request and return a response.

因此Rack就被創造出來了 ! 也解救了大家,雖然在Java World是不可能看到這種事情發生 Orz。

從架構角度來思考Rack所佔位置:

From: Rack in Rails 3  Presentation

Rack官方定義:

Rack provides a minimal, modular and adaptable interface for developing web applications in Ruby. By wrapping HTTP requests and responses in the simplest way possible, it unifies and distills the API for web servers, web frameworks, and software in between (the so-called middleware) into a single method call.

那麼怎麼樣才是一個Rack程式所需要符合條件? Rack SPEC說到:

A Rack application is an Ruby object (not a class) that responds to call. It takes exactly one argument, the environment and returns an Array of exactly three values: status, the headers, and the body.

因此,只要有call function並且接收一個environment參數,且回傳一個Array由Http Status、Http Headers、Http Body所組成成員。

根據此需求撰寫一個最簡易Rack應用程式且透過Rack::Handler跑你喜歡Web Server!

[code lang="ruby"] ?> rack_app = lambda {|env| [200, {}, ["hello rack"]]} # >> Rack::Handler::WEBrick.run rack_app [2010-12-08 00:25:55] INFO WEBrick 1.3.1 [2010-12-08 00:25:55] INFO ruby 1.9.2 (2010-08-18) [x86_64-darwin10.5.0] [2010-12-08 00:25:55] INFO WEBrick::HTTPServer#start: pid=3996 port=3000 [/code]

Rack 趨勢所造成結果,統一中間層、介面,才有學習使用價值。

參考

f

12/01/2010

Java Swing 外觀

Java Swing Look and Feel,似乎愈做愈漂亮,雖然已經超久沒有寫Swing-Based Application。如果有寫Swing可以考慮幾個不錯外觀(皮)。

  • Substance Java look & feel
  • The goal of this project is to provide a rock solid, fast and extensible library for creating visually appealing and consistent Swing applications.
    From: substance.dev.java.net

    Berkeley Software Distribution (BSD) License