九月 28, 2010

hoamon's sandbox
hoamon
hoamon's sandbox is about »

tag cloud

» 使用 Google AJAX Libraries API 時,無法離線撰寫網頁程式?

在網頁程式中,我都是使用 Google AJAX Libraries API 來 host jquery 程式庫的,然而這麼作有一個缺點,如果你是在離線作程式設計時,要手動修改樣版,把 Google 來源的 js 檔改成從本機讀取,是有點麻煩,但致少作得到。

但若是將來在系統上線後,使用者上得了你寫的網頁系統,卻無法連至 www.google.com 呢? 那怎麼辦,雖然這個機率會滿低的,但也是有可能會發生在這個網頁系統屬公司內部系統,而對外連線卻被中斷的情況下。

別怕! 很簡單,下面就是一個範例,第 6、7、8 行改成本機 host 的檔即可。



1 <link rel="stylesheet" title="default" type="text/css" media="screen" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/smoothness/jquery-ui.css"> 2 <script type="text/javascript" src="http://www.google.com/jsapi"></script>
3
4 <script type="text/javascript">
5 if (typeof google == 'undefined') {
6 document.write(unescape('%3Cscript src="/localmedia/jquery-1.4.min.js" type="text/javascript"%3E%3C/script%3E'));
7 document.write(unescape('%3Cscript src="/localmedia/jquery-ui-1.7.2.custom.min.js" type="text/javascript"%3E%3C/script%3E'));
8 document.write(unescape('%3Clink type="text/css" href="/localmedia/smoothness/jquery-ui-1.7.2.custom.css" /%3E'));
9 } else {
10 google.load("jquery", "1.4.0");
11 google.load("jqueryui", "1.7.2");
12 }
13 </script>


延伸閱讀: Using CDN Hosted jQuery with a Local Fall-back Copy

七月 14, 2010

hoamon's sandbox
hoamon
hoamon's sandbox is about »

tag cloud

» 3+2 = 5 碼郵遞區號查詢離線網頁程式(已放上 Google Code)

當我開始開發資訊系統時,就一直認為地址處理是一般資訊系統中最基本且常見的功能。不過,目前使用過的資訊系統,了不起就是把 3 碼郵遞區號作完而已,很少看到網頁系統有作到無碼 5 碼的地址處理功能(當然啦,郵局自家的確有提供 5 碼查詢功能,但是不好用)。所以我想郵局苦心推動大家使用 5 碼,除了能讓寄信速度加快外,未來在許多 GIS 應用愈來愈普及下,我相信大家都會利用 5 碼郵遞區號來作加值應用的。

所以為了搔自己的癢,我寫了 http://zipcode.ho600.com/ 網站,除了可作網上查詢 5 碼功能外,也把 HTML5 的 Offline 作進去,讓查詢功能可在無網路的本機端處理。另外也提供其他人嵌入「地址查詢表單」的方法。詳細說明請見「嵌入方法」,本專案我也放到 Google Code 開發,授權條款是 NEW BSD License ,希望能聽到您們的聲音。

這個程式是跑在 GAE 上的,不過可以很容易地移稙到其他框架中,因為這個功能,我主要是用 javascript 開發的。 GAE 不過提供檔案放置的功能。

注意,第一次瀏覽會比較慢,因為要把約 2MB 的郵遞區號資訊下載下來。不過,如果你用的是支援 html5 offline 功能的瀏覽器,像 Firefox3.6+, chrome4+, safari4+ 的話,之後就不用再下載了。

範例:

二月 23, 2010
» 'hello world' ab tests between pylons 0.9.7 and node.js v0.1.30

A rough play, just for fun.

pylons code:

class HelloController(BaseController):

    def index(self):
        return 'Hello World'


Configuration of prod.ini:

debug = false
...
set debug = false

run with:
paster serve prod.ini

node.js code:

var sys = require('sys'),
   http = require('http');

http.createServer(function (req, res) {
    res.writeHeader(200, {'Content-Type': 'text/plain'});
    res.write('Hello World');
    res.close();
}).listen(8000);

sys.puts('Server running at http://0.0.0.0:8000/');

//(filename: serv.js)

run with:
node serv.js
Result of Pylons:

 % ab -kc 10 -t 10 http://192.168.7.77:8000/

Benchmarking 192.168.7.77 (be patient)
Completed 5000 requests
Finished 6325 requests


Server Software:        PasteWSGIServer/0.5
Server Hostname:        192.168.7.77
Server Port:            8000

Document Path:          /
Document Length:        11 bytes

Concurrency Level:      10
Time taken for tests:   10.094 seconds
Complete requests:      6325
Failed requests:        0
Write errors:           0
Keep-Alive requests:    0
Total transferred:      1341099 bytes
HTML transferred:       69575 bytes
Requests per second:    632.49 [#/sec] (mean)
Time per request:       15.810 [ms] (mean)
Time per request:       1.581 [ms] (mean, across all concurrent requests)
Transfer rate:          130.90 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2  84.2      0    2997
Processing:     2   12  22.1     10     644
Waiting:        1   10  22.0      8     640
Total:          2   15  90.4     10    3639

Percentage of the requests served within a certain time (ms)
  50%     10
  66%     12
  75%     12
  80%     13
  90%     15
  95%     17
  98%     22
  99%     47
 100%   3639 (longest request)


Resulf of node.js:

% ab -kc 10 -t 10 http://192.168.7.77:8000/

Benchmarking 192.168.7.77 (be patient)
Completed 5000 requests
Completed 10000 requests
Completed 15000 requests
Completed 20000 requests
Completed 25000 requests
Completed 30000 requests
Completed 35000 requests
Completed 40000 requests
Completed 45000 requests
Finished 50000 requests


Server Software:       
Server Hostname:        192.168.7.77
Server Port:            8000

Document Path:          /
Document Length:        11 bytes

Concurrency Level:      10
Time taken for tests:   6.185093 seconds
Complete requests:      50000
Failed requests:        0
Write errors:           0
Keep-Alive requests:    0
Total transferred:      3750000 bytes
HTML transferred:       550000 bytes
Requests per second:    8083.95 [#/sec] (mean)
Time per request:       1.237 [ms] (mean)
Time per request:       0.124 [ms] (mean, across all concurrent requests)
Transfer rate:          592.07 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:     0    0   3.5      0      81
Waiting:        0    0   3.5      0      80
Total:          0    0   3.5      0      81

Percentage of the requests served within a certain time (ms)
  50%      0
  66%      1
  75%      1
  80%      1
  90%      1
  95%      1
  98%      1
  99%      2
 100%     81 (longest request)

十二月 15, 2009
» 微軟中國模仿噗浪

關鍵字遊戲:微軟,中國,模仿,噗浪。

"Imitation may be the sincerest form of flattery, but blatant theft of code, design, and UI elements is just not cool, especially when the infringing party is the biggest software company in the world." ~ Microsoft China rips off Plurk@amix.dk

我對這段話的翻譯:

「模仿可能是最真誠的奉承形式,然而明目張膽的瓢竊程式碼、設計及使用者介面元素,這一點也不酷,特別是當侵害的一方是世界上最大的軟體公司。」

不禁想到一句:「勢者,因利而制權也。」真好奇他們伺服器端是不是也要來搞 Python + Tokyo Cabinet

其它參考:

  • 微軟中國推出「山寨版」的Plurk噗浪-MSN聚酷
  • Plurk 聲明的中文版
  • MSN聚酷上的服務使用條款連結
    10. 軟體

    如果您在我們的服務過程中收到軟體,則必須在接受使用權條款下才能使用該軟體。若沒有使用權條款或除非本合約另有說明,則只能在您的服務商品所述的一定數量的電腦所授權使用的服務上,使用該軟體。我們保留軟體的其他所有權利。

    我們可以自動檢查您的軟體版本。我們可以將軟體升級自動下載到您的電腦,執行更新、加強功能及進一步開發服務。

    除非我們另行通知,否則軟體的使用權限會在服務結束日期終止,您必須立即解除安裝軟體。在服務結束日期後,我們會停用軟體。

    您不能對服務所包含的任何軟體反組譯、反編譯或反向工程,除非 (也僅限) 法律明確允許此類活動。

    此軟體受美國輸出法令及法規約制。您必須遵守軟體所適用的所有國內和國際輸出法和法規。這些法律包括目的地、終端用戶和最終使用的限制。若需其他資訊,請參閱 http://www.microsoft.com/exporting (英文網頁)。

    若您使用軟體存取受到 Microsoft 數位版權管理 (DRM) 保護的內容,為了讓您能播放此內容,軟體可能會自動在網際網路上向版權伺服器要求媒體使用權,並下載安裝可用的 DRM 更新。如需相關資訊,請參閱 http://go.microsoft.com/fwlink/?LinkId=123883

  • Evil-smelling 的同義字

七月 28, 2009
» IBM 教學

五月 31, 2007
» Google gears !

今天進 google reader的時候發現右上角多了幾個字: offline

好奇的按下去之後發現 google reader已經引進了
google的離線儲存新技術: google gears.

也就是說安裝之後,
google reader瞬間變成離線也能閱讀的RSS瀏覽器了 !
看來離線的gmail也不遠了...

以技術面來說google gears
以new bsd license放出,是完完全全的自由軟體.
支援Windows/Mac/Linux ,
並且支援IE/Firefox/Safari(未來將會支援,目前在mac上支援firefox)
等於所有主流系統全部支援.

google gears除了離線存取現有的web application之外,
還提供了一個WorkerPool的API幫助programmer將資源吃重的一部份程式以非同步方式存取,
並且還內建輕量級資料庫sqlite 支援使用javascript撰寫sql
(沒錯... 就是像下面這樣
var rs = db.execute('SELECT dish FROM recipe WHERE recipe MATCH ?', ['tomatoes']);
)
之前雖然也有如dojo storage之類的解決方案.但總不如早已習慣的rdbms來的方便. google幹的好啊!

google gears目前雖然仍是beta中,
但解決了web application離線存取這個麻煩的問題,
由於是完完全全的自由軟體(允許商業使用)
在未來有機會成為業界的新標準.

更多詳細的資訊請參考:

http://code.google.com/apis/gears/index.html
http://gears.google.com/

五月 5, 2007
» [link] 誰說只有wiki可以這樣搞.....orz

pure html+js ... 越來越有趣了 :P

Terminal

Home

Blog

A Feedjack powered Planet
A Django site.