2012年10月29日 星期一

[asp]使用VS2008,怎麼對 asp debug

如果使用VS2008,若直接對 asp 按下 debug,會出現

image

經過搜尋,解決方法是,

(1)設定iis,使得該頁可以直接使用。

image

(2)打開VS2008,開啟網站(檔案->開啟->網站),選擇網站所在的目錄

image

(3)附加至處理序(偵錯->附加至處理序),選擇 w3wp.exe (適用於 iis 6)

image

按下附加之後,VS2008,就會進入偵錯模式。

(4)瀏覽器跑一下 asp 網頁,方案總管會出現指令碼文件。

image

(5)雙擊 asp 文件,打開文件後,即可設中斷點,開始正式 debug。

image

 

結尾:

美中不足,不能邊改邊debug,你可以看到這文件是唯讀的。

[asp] 最近又用到 asp,幾個筆記需要記

判斷 access 資料庫某個欄位值為 null

我以為用 if cursor.fields(i).value = null then…可以判斷。我錯了。

要用 if isnull(cursor.fields(i).value) then … 才行。

 

到底權限怎麼開才能寫入?

首先,我的 os 是 windows 7,iis是 7 (應該吧…)

如果是 asp .net 的程式,IIS_USRS 這個使用者要開啟權限到寫入。

如果是 asp 的程式,IUSR 這個使用者要開啟權限到寫入。

 

如何存取utf-8 編碼的文字檔內容?

asp 直接 openTextFile 是不對的。它會按執行環境的預設值讀寫檔案。

我有改過CODEPAGE="65001",無效。

目前使用 ADODB.Stream 可。

有人提供小函數使用。

Sub Save2File (sText, sFile)
    Dim oStream
    Set oStream = CreateObject("ADODB.Stream")
    With oStream
        .Open
        .CharSet = "utf-8"
        .WriteText sText
        .SaveToFile sFile, 2
    End With
    Set oStream = Nothing
End Sub

Function ReadUtf8File(sFile)

    Set objStream = CreateObject("ADODB.Stream")
    With objStream
        .Charset = "utf-8"
        .Type=2
        .mode=3
        .Open
        .loadfromfile sFile
        ReadUtf8File=.readtext
        .Close
    End With
    Set objStream = Nothing

End Function

使用 javascript 的 escape 的文字,asp 怎麼解?

我基本上放棄了。試了幾次都不成功。這個問題很大,需要前後程式配合(html, javascript, asp)。因此會另外再寫詳細的文章。

簡單來說,我後來轉用 htmlencode。那 javascript 怎麼做 htmlencode 或 htmldecode?

以下有兩個小函數可以使用

function htmldecode(strHtmlEncode){
    var div =  document.createElement('div');
    div.innerHTML = strHtmlEncode;
    return div.innerText
}

function htmlencode(strHTML)
{
    var div = document.createElement('div');
    div.innerText = strHTML;
    return div.innerHTML;
}

asp 的程式,直接取值就好,不用解。

2012年10月23日 星期二

[html]用 javascript 查詢在網頁裡有多少定義過的 style?

原來,在 document.styleSheets 裡,存放了我們定義過的 style (class)。
也就是在 <style type="text/css"> 或 <link rel="stylesheet" type="text/css" href="src.css"> 這兩類地方寫的 style。

使用 javascript 可以取出內容。

var count = document.styleSheets.length;
    for (var y=0; y < count; y++)
    {
        var classes = document.styleSheets[y].rules || document.styleSheets[y].cssRules
        for(var x=0;x<classes.length;x++) {
            console.log("sheet"+y.toString()+" rule"+x.toString()+":"+classes[x].selectorText+":"+((classes[x].cssText) ? (classes[x].cssText) : (classes[x].style.cssText)));
        }
    }

2012年9月18日 星期二

[plone]plone.app.theming 1.0 升到 1.1a2

據說,plone 4 開始,佈景主題 (theme) 可以使用 diazo 引擎來更換管理佈景主題。要達成這個功能,plone 要安裝 plone.app.theming 模組。令人混亂的是,在 pypi 看到的是 plone.app.theming,在自己安裝好的 plone site 的 add-on 的管理畫面,是看到 Diazo theme support。光是名稱就把我搞掉一天了。

最近的 plone 到4.2.1,只有 *nix 跟 Mac OS 安裝檔。目前 (2012/09/18),windows 的安裝檔是到 4.2,plone.app.theming 是 1.0,它只有選擇已安裝的佈景主題,或手動指定 rules.xml。對於我來說應該夠了,只是看到 pypi 上 1.1 的描述,很想要試,不知該怎辦,我也找了很久…。看著下載下來的 plone.app.theming-1.1a2.zip 不知從何下手。

後來在那個 zip 檔裡,看到 buildout.cfg 裡有一段:

[versions]
plone.app.theming =

那我就來試試吧。

先把 plone 給關了。

image

然後,編輯 c:\plone42\buildout.cfg,加入 plone.app.theming = 1.1a2 在 [versions] 底下。

[versions]
distribute = 0.6.27
plone.app.theming = 1.1a2

然後,就在命令列下, c:\plone42\ 下指令

C:\Plone42>bin\buildout.exe

結果就出現以下的訊息:

C:\Plone42>bin\buildout.exe
Getting distribution for 'plone.app.theming==1.1a2'.
warning: no previously-included files matching '*pyc' found anywhere in distribu
tion
Got plone.app.theming 1.1a2.
Getting distribution for 'plone.resourceeditor'.
Got plone.resourceeditor 1.0b1.
Getting distribution for 'roman==1.4.0'.
Got roman 1.4.0.
Updating zeo.
Created directory C:\Plone42\parts\zeo
Created directory C:\Plone42\parts\zeo\etc
Created directory C:\Plone42\parts\zeo\var
Created directory C:\Plone42\parts\zeo\log
Created directory C:\Plone42\parts\zeo\bin
Wrote file C:\Plone42\parts\zeo\etc\zeo.conf
Wrote file C:\Plone42\parts\zeo\bin\zeoctl
Changed mode for C:\Plone42\parts\zeo\bin\zeoctl to 777
Wrote file C:\Plone42\parts\zeo\bin\runzeo
Changed mode for C:\Plone42\parts\zeo\bin\runzeo to 777
Generated script 'C:\\Plone42\\bin\\zeo'.
Generated script 'C:\\Plone42\\bin\\zeopack'.
Generated script 'C:\\Plone42\\bin\\repozo'.
Changed mode for C:\Plone42\bin\zeo_runzeo.bat to 755
Changed mode for C:\Plone42\bin\zeo_service.py to 755
Generated script 'C:\\Plone42\\bin\\zeo_service'.
Updating instance.
Generated script 'C:\\Plone42\\bin\\instance'.
Updating run-instance.
Generated script 'C:\\Plone42\\bin\\run-instance'.
Updating run-zeo.
Generated script 'C:\\Plone42\\bin\\run-zeo'.
Updating service.
Updating service-zeo.
*************** PICKED VERSIONS ****************
[versions]
enfold.recipe.winservice = 0.7.2
pillow = 1.7.7
plone.resourceeditor = 1.0b1

*************** /PICKED VERSIONS ***************

 

再啟動 plone。

就看到新的 diazo theme 的控制面版,如下圖。

image

舊的 diazo theme 控制面板,如下圖。

image

剩下的,還是我該怎麼編 theme.html, rules.xml, theme.css 的問題…。

2012年9月6日 星期四

[python] os.rename 失敗?

在 mac 上,想要跨硬碟搬東西,結果 os.rename 就是出現

OSError: [Errno 18] Cross-device link。

試找了一下,用 shutil.move 就可以了。

2012年8月21日 星期二

[python]GUI 開發,使用 tkinter 與 wxpython 的感想

本來首選是 tkinter,他是 python 官方附帶的模組。但我有兩個問題沒有辦法克服。

第一個是文件不好找。python docs 有一篇大約講一下 tk 文件跟 tkinter 對應的規則。這也不能怪人,相同的問題也出現在 jython 上。只是 java 風格的文件比較容易看懂,jython 又比較多人用,文件也比較多。

第二個是,在mac上,有方塊字的問題。連 IDLE 的 python shell 都一樣,應該是無解。也許這就是為什麼 google app engine 在 windows 有提供 GUI 程式,但 mac 沒有的原因吧…。

後來轉而使用 wxpython。文件比較好找[註1]。容易看懂的原因是裡面就是講 python 話。在 mac 使用上也沒有方塊字的問題。只是要多裝 wxpython,安裝檔就 50多 MB。

wxpython 有一個 html 的模組[註2],可惜不能 javascript 互動。如果可以的話,擺一個 html window,剩下就是 html 與 javascript 的事,可以少學很多事情哩。

 

註1:http://wxpython.org/docs/api/wx-module.html

註2:http://docs.wxwidgets.org/2.8/wx_wxhtml.html, http://www.indicthreads.com/1106/incorporating-html-into-wxpython-part-1/, http://wiki.wxpython.org/wxHTML

2012年5月30日 星期三

[python] json 與中文

現場狀況是這樣的,在 json 編碼中,文字部份一定要 utf-8,大家都很清楚了,如果想搞別的編碼,就自己 escape,這種作法算偷吃步。在 python 的 json 模組裡面,算是很貼心(還是很雞婆?),預設就是幫大家把文字都 escape 了。當然使用 ascii 的人都不會有感覺(我想大家也很無奈)。

在 json.dump 裡面,有預設一個 ensure_ascii=True,就是強迫文字 escape 的選項。如果沒去動他的話,以下是出現的結果:

"\u53f0\u6ce5"

如果你確定你的文字是 utf-8,可設定成 ensure_ascii=False,像是:

id_name[stockid].decode('cp950').encode('utf8')

那結果就會是:

"台泥"

這樣就很清楚了。

只是,我光看 escape 完的字串,感覺像是 unicode 編碼而不是 utf-8 編碼耶…。是 json 故意又轉成 unicode 再 escape 的嗎?