2016年3月9日 星期三

瀏覽器開發者工具-JavaScript Console

現在的瀏覽器功能強大,內建工具的協助編輯網頁

下面是各瀏覽器如何開啟JavaScript Console快捷鍵

Chrome Console Keyboard Shortcuts

  • Windows: Ctrl + Shift + J
  • Mac: Cmd + Option + J

Firefox Console Keyboard Shortcuts

  • Windows: Ctrl + Shift + K
  • Mac: Cmd + Option + K

Internet Explorer Console Keyboard Shortcuts

  • F12 key

Safari Console Keyboard Shortcuts

  • Cmd + Option + C

2016年3月1日 星期二

資料庫 CRUD

資料庫主要的操作CRUD為四個字的縮寫

  • Create
  • Read
  • Update
  • Delete

2016年2月23日 星期二

2016年2月15日 星期一

Python standard library string

python standard libray string
提供了一些字串操作基本功能

str.translate(table[, deletechars])

translate可以依據table來轉換str
如果轉換的目標是None,則match的字元就會被刪除

>>> 'read this short text'.translate(None, 'aeiou')
'rd ths shrt txt'

參考網址
https://docs.python.org/2.7/library/string.html?highlight=translate#module-string

python standard library os

python standard library裡提供os這個module
可以進行os的一些基本操作
例如取得資料夾底下的檔案名

os.listdir(path)
列出路徑下,所有檔案名字

os.rename(src,dst)
將src檔名改成dst

os.getcwd( )
取得work directory 路徑

os.chdir(path)
改變work directory 路徑

參考網址
https://docs.python.org/2/library/os.html

2016年2月11日 星期四

python escape convert

要將字串轉成escape的型式
程式碼如下

def escape_covert(s):
    for (i, o) in ( ('&',  '&'),
                   ('>', '>'),
                   ('<', '&lt;'),
                   ('"', '&quot;'),
                   ):
        s = s.replace(i, o)
 
    return s
要注意 ('&',  '&amp;')要放第一個
否則其他escape charater
轉換完的&會被轉成'&amp
造成錯誤


但有更簡便的做法
就是import python的standard library cgi

import cgi

def escape_covert(s):
    return cgi.escape(s,quote=True)

參考網址
https://docs.python.org/2/library/cgi.html

HTML escape characters


有時候在輸入字串時
字串裡的字會跟HTML TAG
相同而造成把字串當成HTML TAG
結果網頁輸出錯誤的內容
這時候就要用escape characters

較常使用的escape characters

  • Space   &nbsp;
  • "           &quot;
  • &         &amp;
  • <          &lt;
  • =          &#613
  • >          &gt;


Symbol Entity Name
€ &euro;
Space &nbsp;
" &quot;
& &amp;
< &lt;
= &#61;
> &gt;
Non-breaking space &nbsp;
¡ &iexcl;
¢ &cent;
£ &pound;
¤ &curren;
¥ &yen;
¦ &brvbar;
§ &sect;
¨ &uml;
© &copy;
ª &ordf;
¬ &not;
­ &shy;
® &reg;
¯ &macr;
° &deg;
± &plusmn;
² &sup2;
³ &sup3;
´ &acute;
µ &micro;
&para;
· &middot;
¸ &cedil;
¹ &sup1;
º &ordm;
» &raquo;
¼ &frac14;
½ &frac12;
¾ &frac34;
¿ &iquest;
À &Agrave;
Á &Aacute;
 &Acirc;
à &Atilde;
Ä &Auml;
Å &Aring;
Æ &AElig;
Ç &Ccedil;
È &Egrave;
É &Eacute;
Ê &Ecirc;
Ë &Euml;
Ì &Igrave;
Í &Iacute;
Î &Icirc;
Ï &Iuml;
Ð &ETH;
Ñ &Ntilde;
Ò &Ograve;
Ó &Oacute;
Ô &Ocirc;
Õ &Otilde;
Ö &Ouml;
× &times;
Ø &Oslash;
Ù &Ugrave;
Ú &Uacute;
Û &Ucirc;
Ü &Uuml;
Ý &Yacute;
Þ &THORN;
ß &szlig;
à &agrave;
á &aacute;
â &acirc;
ã &atilde;
ä &auml;
å &aring;
æ &aelig;
ç &ccedil;
è &egrave;
é &eacute;
ê &ecirc;
ë &euml;
ì &igrave;
í &iacute;
î &icirc;
ï &iuml;
ð &eth;
ñ &ntilde;
ò &ograve;
ó &oacute;
ô &ocirc;
õ &otilde;
ö &ouml;
÷ &divide;
ø &oslash;
ù &ugrave;
ú &uacute;
û &ucirc;
ü &uuml;
ý &yacute;
þ &thorn;