Feeds:
Posts
Comments

Archive for the ‘computer language’ Category

Twitter Typeahead is a fast and effective auto-complete jQuery plugin for form filling.

Twitter Typeahead 插件是一個jQuery 插件,用作快速而有效率的自動填表工具。

In desktop computer, this plugin (Twitter Typeahead) works properly. However, when this plugin is run on a mobile computer, it cannot detect the “blur” event properly. The suggested text cannot be closed when you click outside the suggestion box.

在正常的桌面電腦上,這個Twitter Typeahead插件能正常地運作。可是,一旦放在手機的瀏覽器上運行,卻因無法捕捉到“blur”的事件。如果輕觸瀏覽器的其他地方,無法可以正常關閉“提示列”。

One of the possible method is add a close button “x” to close the suggestion list. I’ve done an ugly example illustrate this: typeahead with close button “x”

其中一個可行的方法,就是在提示清單上加入一個關閉的按鈕”x”,小弟做了個核突的版本:typeahead with close button “x”

只要您修改第849行,
What you need to do is to change line 849:

 dropdown: '<span class="tt-dropdown-menu"></span>'

換成以下,
To

 dropdown: '<span class="tt-dropdown-menu"><a class="tt-dropdown-close" onclick="$(this).closest(\'span\').hide()">x</a></span>'

還有,只要修改CSS就能改善畫面。
If you feel this screen is ugly, what you need is to add CSS file.

Advertisements

Read Full Post »

我在網上看到有文章說可以很簡單的使用Java的Input Stream來開啟Big5 HKSCS編碼的網頁,然後直接轉成UTF-8。
I’ve seen some articles in internet saying that it’s quite easy to use Java’s Input Stream to open a webpage encrypted in Big5 HKSCS and convert it directly to UTF-8.

我將那些網頁介紹的方法,寫了一個到香港政府某網頁的程式,試試看轉出的內容是否UTF-8。
According to the method introduced, I’ve written a java program to test if it can download a Hong Kong Government’s webpage and display the content in UTF-8.

這個程式的內容如下:
The source code is as following:

import java.net.URL;
import java.net.URLConnection;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
class Building{
	public static void main(String args[]) throws Exception{
		URL bdgSite=new URL("https://bmis.buildingmgt.gov.hk/chi/building.php?count=0&ordfield=&district_id=0");
		StringBuffer s=new StringBuffer();
		String inputLine;
		URLConnection fc=bdgSite.openConnection();
		BufferedReader in=new BufferedReader(new InputStreamReader(fc.getInputStream(),"Big5_HKSCS"));
		while((inputLine=in.readLine())!=null)
			s.append(inputLine);
		in.close();
		Pattern p1=Pattern.compile("<option[^>]+>([^<]+)</option>");
		Matcher m1=p1.matcher(s);
		while(m1.find()){
			System.out.println(m1.group(1));
		}
	}
}

在程式中,我試圖將十八區的名稱找下來。(尤其是深水埗的「埗」字,這個若用普通的Big5編碼是看不到的。)
In the program, I tried to use regular expression to find the 18 regions in Chinese, one of the word “埗” cannot be processed properly if using Big5 encryption.

我在mac機的Terminal用UTF-8輸出,看到亂碼,用BIG 5 HKSCS輸出,看到正常。這表示,Java只能正常地讀取網頁,卻沒有將網頁的內容轉成Unicode或UTF-8。

I use mac os and set the output of terminal into UTF-8. I found the output is messy and is in wrong encoding. Then I switch the output of terminal to BIG 5 HKSCS, I found the output become normal. This shows that Java can process the encoding of the web page properly but, it doesn’t convert it into Unicode or UTF-8 for processing. Thus, the output is still in BIG 5 HKSCS.

我將這程式安裝在Ubuntu 13.04, JDK 1.7.0_21的環境運行卻發現正常,最後,我找到了Mac OS的Java 設定中,Default file encoding 是並不是UTF-8而很可能是ISO-8859-1。而要正常運行,必需要加入參數 -Dfile.encoding=UTF-8

I’ve tried to install this program in one of my Ubuntu desktop 13.04 with JDK 1.7.0_21. The program runs properly. Finally, I found out a fact that there is a setting “-Dfile.encoding” which affect Mac OS to output the result properly. In order to fix the problem, I need to add an option “-Dfile.encoding=UTF-8”:

java -Dfile.encoding=UTF-8 Bulding

Read Full Post »

I've just received a press release from Packt about the latest 
jQuery Campaign. Here is the press release:


Packt celebrates jQuery in October with exclusive book offer

Packt has this week announced a series of discounts and 
promotions to herald the publication of the Learning jQuery, 
Third Edition in October. Packt will offer readers the exclusive 
discounts of 20% and 30% off the cover price of all jQuery print 
books, including the just published third edition of the Learning 
jQuery book, for limited period only.

jQuery is a powerful, yet easy-to-use JavaScript library that helps 
web developers and designers add dynamic, interactive elements to 
their sites, smoothing out browser inconsistencies and greatly 
reducing development time.

Learning jQuery, Third Edition, written by Jonathan Chaffer, 
Karl Swedberg, is revised and updated for version 1.6 of jQuery. 
Readers will learn the basics of jQuery for adding interactions 
and animations to their pages. Even if previous attempts at writing 
JavaScript have left one baffled, this book will guide them past the 
pitfalls associated with AJAX, events, effects, and advanced JavaScript 
language features.

“jQuery is one of the topics Packt remains committed to publishing on, 
offering more interesting books that will help the diverse needs of 
jQuery users. The set of jQuery related books we’ve recently published 
shows our continued commitment to the topic area, and we intend to 
publish important jQuery books, such as the Learning jQuery, Third Edition, 
for a long time to come”, said Packt Open Source publisher Doug Paterson.

For more information on jQuery October and the discounts being offered 
throughout October, please visit: 

- https://www.packtpub.com/news/jquery-month

Read Full Post »

Using Application Scope Regular Expression 是一種使用IIS的冷知認。

在處理「搜尋器友善」(Search Engine Friendly)的網頁時,網頁瀏覽器每一次向服務器索取
網頁時,常常會利用「正規表達式」。其實,每次使用「正規表達式」時,服務器會重新將
「正規表達式」進行即時翻譯(Just-in-Time Compilation),當網頁傳送給瀏覽器後,「正規表達式」
就會從記憶體移除。

試想像一個繁忙的網站,同一時間有千多個客戶。每一個用戶會使用一個或以常的「正規表達式」,
而每次使用,都會從新「即時翻譯」。這些過程,對服務器是一個很大的負擔。

在微軟IIS上,有一個使用物件的方式,叫做Application Scope,表示物件在啟動後會一直運行,
直到IIS重新啟動、或者清理Application Pool時,才會從新載入、翻譯。我們可以將
「正規表達式」以Application Scope的方式,長期留在記憶體內。以下的情況,有四個常用的
「正規表達式」以Application Scope的方式運作的代碼(儲存在/global.asa):
<object runat="server" name="URL_RegExp" scope="application" progid="VBScript.RegExp"><object/object>
<object runat="server" name="NODE_RegExp" scope="application" progid="VBScript.RegExp"><object/object>
<object runat="server" name="SITEMAP_RegExp" scope="application" progid="VBScript.RegExp"><object/object>
<object runat="server" name="PART_RegExp" scope="application" progid="VBScript.RegExp"><object/object>
<script language="JScript" runat="server">
function Application_OnStart(){
  Application.lock();
  URL_RegExp.Pattern="404;http:\\/\\/[^\\/]+\\/(.+)$|^~404\\.asp$";
  NODE_RegExp.Pattern="^node/([01][a-z0-9]{3})$";
  SITEMAP_RegExp.Pattern="^sitemap/([01][a-z0-9]{3}|nodes)$";
  PART_RegExp.Pattern="^parts/([01][a-z0-9]{3})/([0-9A-Z\\-\\.\\/\\%\\s]{4,50})$";
  Application.unlock()
}
</script>
經過簡單比較,在繁忙的服務器上,用應用程式層面(Application Scope)會比(Session Scope)快十多倍。

Read Full Post »

最近有一位同事栛助我處理有關Search Engine Optimization(SEO)的事宜。
舊的系統產生了大量的網頁,我這位同事要建立新的系統。但舊的系統所
產生的網頁。有大量的ASP(Active Server Page)代碼,不應該直接移至新的系統中。

其中一個方法,他要使新的系統將所有ASP代碼移除。最有效的方法,就是
編寫合適的「正規表示式」Regular Expression,用「正規表示式」來表達及
辨識ASP代碼。

要辨識普通的ASP代碼,即以<%...%>所包裹的文字,可以用以下的「正規表示式」:
In order to recognize asp code inside a source code file, 
we can use the following Regular Expression:

<%([\S\s](?!%>))+[\S\s]%>

要辨識附加檔案(Include file),即以<!--#Include File="..."%>或
<!--#Include Virtual="..."%>所包裹的文字,可以用以下的「正規表示式」:
In order to recognize asp include file tags inside a source code file, 
we can use the following Regular Expression:

<\!\-\-\s*#([\S\s](?!\-\->))+[\S\s]\-\->

要辨識有內容的Server-side Javascript,即以<script language="JScript" 
runat="server">...</script>等所包裹的文字,可以用以下的「正規表示式」:
To identify the server-side javascript, we can use 
the following Regular Expression:

(<script runat|<script([^>](?!\brunat\b))+[\S\s]?runat)\s*=\s*"server"[^>]*>([\S\s](?!<\/script>))+[\S\s]<\/script>

如果將「正規表示式」利用JScript運行的話,我們要避免<script>的標籤
內藏有任何<script>的標籤,請參考以下的寫法:
If the regular expression is written in JScript, to avoid 
nested-javascript (i.e. javascript tag inside javascript), 
the Regular Expression should be written in a way similar 
to following example:

<script language="JScript" runat="server">
//... some code here
var serverjs=new RegExp("(<"+"script runat|<"+"script([^>](?!\\brunat\\b))+[\\S\\s]?runat)\\s*=\\s*"server"[^>]*>([\\S\\s](?!<\\/"+"script>))+[\\S\\s]<\\/"+"script>","g")
//... some code here
</script>

Read Full Post »

當你用微軟的VB或者C#寫程式的時候,你會預期他們會在相對應的Dot Net平台上正常地運作。最近,我用VB dot NetC#及Visual C++寫一樣的內容的程式,涉及純100%的Dot Net指令。在VC++ 10的環境下產生的程式,卻不留情面,要用戶安裝msvcr100.dll的庫程式,甚至我用command line來翻譯,強制/clr:pure參數,結果也是一樣。

試問有那一個Dot Net的開發者希望他的產品要附帶額外一個Runtime程式。Dot Net的本義就是不用再安裝任何一個Runtime,從網上下載就可以直接運行的平台。

Microsoft Visual Studio正式發表了一年多,而Visual C++的團隊卻無視這些根本性的問題。可以想像,C++的開發團隊,素質比較其他團隊差。不要以為越新的產品質素越高,要用C++開發100%純Dot Net程式,唯有試用較舊的Visual Studio吧!

Read Full Post »

最近有同事發現有一個Ms Access的VBA不能正常地在一部測試用的64bit 的Window 2003上運行。雖然那個是預訂在32bit 視窗上運行的。

我們追查原因的時候,發現Scripting engine 的版本太舊。是故我們到微軟的網頁,希望可以下載Window Script 5.7,才發現沒有64 bit的版本。Windows Script在視窗

之前希望安裝IIS 的監察軟件,也發現缺少了64bit 的支援。

眼看蘋果將64 bit OS正規化,而微軟則視它為「二奶」。很多更新只推出了32 bit,遲遲都未看到64 bit的蹤影。

想當年,微軟能一力擔成設計USB的創舉,現在連支援64 bit 都力有不遞。現在的微軟已是明日黃花了。

後記:經跟朋友討論,其實,微軟的32bit及64bit看來是不同的開發團隊,他們有不同的產品,所以很多時候,有些產品只有 32bit或64bit的版本。 至於Microsoft Scripting Engine沒有新的64 bit 版本是比較可惜的,用它來寫VBScript, JScript的文本程式是十分方便的。

Read Full Post »

Older Posts »