[CSS] IE 6, 7, 8 FireFox hack 支援透明背景圖 background or img javascript

先前在國外部落格發現一篇非常好用的教學:Quick Tip: How to Target IE6, IE7, and IE8 Uniquely with 4 Characters,裡面有提供一部教學影片,非常好用,也很實在,底下可以先看影片,看完大概就可以針對 IE, FireFox, Chrome 進行 CSS Hack。 目前網頁製作,要符合多瀏覽器跨平台(IE, Safari, Chrome, FireFox…等),就必須動到 CSS Hack,雖然 Google 已經宣稱不支援 IE6,但是很多單位,很多學校跟客戶都是使用 IE6 瀏覽器,不只國內這樣,國外大廠也都希望支援 IE 系列,包含 IE6, IE7, IE8,這時候就必須知道如何分別針對各種不同 IE 做設定,底下就來看看實做例子。

[Read More]
CSS  html 

[C/C++] strpbrk 在字串中找尋指定的符號或字母

繼上一篇:『[C/C++] 切割字串函數:strtok, Network mac address 分割』,內容寫到 Microsoft 用到 strpbrk 來找尋字串中特定符號,並且回傳該符號的位址,用法如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 #include "string.h" #include "stdlib.h" #include "stdio.h" int main () { char str[] = "This is a sample string"; char key[] = "aeiou"; char * pch; printf ("Vowels in '%s': ",str); pch = strpbrk (str, key); while (pch != NULL) { printf ("%c " , *pch); /* 也可以直接輸出字串 */ printf("\noutput=%s\n", pch); pch = strpbrk (pch+1,key); } printf ("\n"); system("pause"); return 0; } 輸出結果: 我們看一下 /usr/src/lib/libc/string/strpbrk. [Read More]

[C/C++] 切割字串函數:strtok, Network mac address 分割

今天寫了 strtok 的範例:『如何分離網路 mac address』程式碼如下,大家一定會有疑問 strtok 第一次呼叫,第一參數輸入愈分離的字串,在 while 迴圈,則是輸入 NULL 呢?底下就來解析 strtok.c 的程式碼。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 /* * * Author : appleboy * Date : 2010.04.01 * Filename : strtok.c * */ #include "string.h" #include "stdlib.h" #include "stdio.h" int main() { char str[]="00:22:33:4B:55:5A"; char *delim = ":"; char * pch; printf ("Splitting string \"%s\" into tokens:\n",str); pch = strtok(str,delim); while (pch ! [Read More]

[編輯器] CKeditor 更換 background-color and font-size

相信大家在製作 Web 過程,一定會用到編輯器,然而 CKeditor 前身 FCKeditor 非常有名,FCKeditor 運行了六年之久,在去年2009年的時候,轉換成了 CKeditor,目前開發團隊也專注於此版本,現在已經推出到 CKEditor 3.2 released!,可以參考 CKEditor 3.x - Developer’s Guide,裡面也整合了 jQuery,替很多開發者想到更多管道去整合網站,然而今天設計網站,需要改變編輯器的背景顏色,預設是白色背景,但是並非所有網站都是白色呈現,所以才需要動到背景顏色,這樣好讓使用者可以融入整個背景,在 Plurk 發表了這問題,也找了官方論壇,都沒有發現正確解答,官方論壇有篇類似問題:Change the background color of the CKEditor text area,這篇自己試過是沒有用的,正確解法可以參考 CKeditor 的 API:contentsCss。 1. 首先在 CKeditor 根目錄建立新檔案:mysitestyles.css body { /* Font */ font-family: Arial, Verdana, sans-serif; font-size: 12px; /* Text color */ color: #f0f0f0; /* Remove the background color to make it transparent */ background-color: #353c42; } html { /* #3658: [IE6] Editor document has horizontal scrollbar on long lines To prevent this misbehavior, we show the scrollbar always */ _overflow-y: scroll } img:-moz-broken { -moz-force-broken-image-icon : 1; width : 24px; height : 24px; } img, input, textarea { cursor: default; } 2. [Read More]

Apache 取得透過 Reverse Proxy (Varnish) 的 Client 真正 IP (mod_rpaf)

之前介紹 [FreeBSD]high performance caching reverse proxy: Varnish (安裝架設篇) 來當 Web 前端 Reverse Proxy,也有 load balance 的功能,不過碰到這樣的環境,後端 Apache Server 只會抓到 Reverse Proxy IP 來當作 log 紀錄,而無法正確取得 Client 端 IP,Varnish 官網 FAQ 有提到 log 檔案得的解決方法,不過在程式方面,要大量的修改,假設今天 Apache 跑10個 Virtual Host ,不就要去改10個網站程式,背後或許是一些大型 open source 的 Project,改起來相當不容易,也很費工夫。Darkhero 提供了 reverse proxy add forward module for Apache (mod_rpaf) 模組,只要裝上這模組,Apache 就不必動到其它設定就可以正確紀錄 log 檔案,且程式都不必修改,就可以得到正確 IP 了。 FreeBSD Ports 安裝方式: cd /usr/ports/www/mod_rpaf2/ make install clean 修改 httpd.conf (FreeBSD: /usr/local/etc/apache22/httpd.conf) LoadModule rpaf_module libexec/apache22/mod_rpaf. [Read More]

在 IE8 FireFox Chrome CSS 置中解決方法

在 IE8 還沒出來之前,都是利用 margin: 0 auto; 的方式來解決 div 置中的問題,但是這在 IE8 並沒有發揮作用,無效了,底下在網路上發現兩種解法,分享給大家知道: 1. Width:100% 在最外層 div 加入 Width:100% 的屬性,程式碼如下:

#container {width:100%;}
#centered {width:400px; margin:0 auto;}

2. Text-Align:Center 在 div tag 裡面加入 Text-Align:Center,這樣 IE8 會偵測到此語法,就會服從 margin:0 auto; 之屬性,不過這樣內容會被全部至中,如果您有需要將其 div 內容往左邊對齊,那就必須在加上語法 Text-Align:left,底下是範例程式碼:

#container {text-align:center;}
#centered {width:400px; margin:0 auto;text-align:left;}
IE6,IE7 則是利用下面語法:
#wrap {
  margin: 0px auto; /* firefox */
  *margin: 0px auto; /* ie7 */
  _margin: 0px auto; /* ie6 */
  height:100px; 
  width:860px;
  border:5px solid red;    
}
reference:

Centering a Div in IE8 Using margin:auto 【CSS 語法教學】區塊置中的三種寫法

CSS 

[FreeBSD]high performance caching reverse proxy: Varnish (安裝架設篇)

在上禮拜跟 DarkHero 兄聊到 How To Build a Scalable Web Site (3/6) 的上課講義,互相討論了 MySQL Load balance 以及 http reverse proxy 的方式,以前自己有用 HAProxy 當作 Web 平衡負載,順便紀錄了 HAProxy FreeBSD 安裝方式,這次要來介紹今天重點:Varnish Cache Server,在近幾年流行的 Caching 機制,大家會想到 Squid,只要您設定良好的 Squid 參數,它一定運作的非常穩定,然而它的核心依然是 forward proxy,要架設成 Reverse Proxy 還必需要設定一些參數才可以達到,是有一定的困難性,然而 Varnish Cache Server 底層就是高效能 caching reverse proxy,也因為 Squid 是 1980 年發展出來的,程式架構過於老舊,可以參考 ArchitectNotes 瞭解這部份詳情。也許您會問到 Varnish 可以架設成 forward proxy 嗎?答案是可以的,但是您也許不會這麼做,因為它需要 DNS 技術,以及需要一個非常大且複雜的 Varnish VCL(Varnish Configuration Language) file。 1. 今天要介紹如何在 FreeBSD 系統安裝,在介紹之前,系統必須先安裝好 apache,這樣才可以正確啟動,利用 ports 安裝: [Read More]

[Vim] 想套用 *.php syntax 顏色於 *.ros

vim_header Vim 是一套強大的編輯器,它分佈於各大 UNIX systems,安裝好一套 UNIX 系統,預設就是 Vi 編輯器(FreeBSD 預設是 ee),相當好用,他也支援各種語言的 syntax,讓您在編輯檔案能夠看到各種不同顏色,在 FreeBSD 底下可以去看 /usr/local/share/vim/vim64/syntax/ 該資料夾支援各種語言,例如 PHP、Ruby、css、html、java、C/C++…等,假設今天我們想要 .ros 的副檔名需要用 php.vim syntax 來開啟,就必須做底下設定: 執行底下:

mkdri ~/.vim
vi ~/.vim/filetype.vim 
寫入 filetype.vim 資訊 if version < 600 syntax clear elseif exists("b:current_syntax") finish endif augroup filetypedetect au! BufRead,BufNewFile *.ros setfiletype php augroup END[/code] ps. on freebsd 7.1-RELEASE-p11 vim version 6.4.9 reference:

Vim 套用 Markdown syntax vi 設定

[FreeBSD] DenyHosts 設定在 hosts.allow 注意事項

DenyHosts 是一套用 Python 跟 shell script 寫出來的 open source base on Linux or FreeBSD (/var/log/secure on Redhat, /var/log/auth.log on Mandrake, FreeBSD, etc…),用來阻擋 SSH Server 被攻擊,之前寫一篇 FreeBSD 安裝設定教學,有一點沒有注意到,就是打開 /etc/hosts.allow,注意要把 ALL : ALL : allow 放到最後一行,跟 iptables 設定原理是一樣的,會從第一條規則開始比對,如果比對成功,下面的 rule 就會略過比對了,參考英文說明: Start by allowing everything (this prevents the rest of the file from working, so remove it when you need protection). The rules here work on a “First match wins” basis. /etc/hosts.deny 已經被 FreeBSD 棄用,所以必須把 allow 跟 deny 的 rule 都寫到 hosts. [Read More]

[C/C++] 計算二進位任意數含有多少個位元為1?

今天看到一個有趣的題目,就是計算二進位任意數值,其中包含了幾個1,這非常有趣,利用每個 bit 做&就可以解出這個問題了: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 #include <stdio.h> #include <stdlib.h> int bitcount(unsigned int); int main(){ int count = 0, a; a = 1023; count = bitcount(a); printf("%d有%d個位元為1\n\n", a, count); system("pause"); return 0; } int bitcount(unsigned int n) { int count = 0 ; while (n) { count++ ; n &= (n - 1) ; //關鍵演算之處 } return count ; } 關鍵解法是在 n &= (n - 1) ; 這個地方,為什麼會是這樣寫呢,大家可以想看看,為什麼要 (n-1),其實可以帶數字進去跑看看就知道程式為什麼會這樣寫,這個 case 可以分作兩種,數值可能會有兩種狀況,一種是奇數,另一種就是偶數,8 代表 1000,9 代表 1001,最右邊 bit 是 1 代表奇數,剩下的都是偶數,拿9當例子帶入 while 迴圈試試看,首先將 count + 1,接下來 1001 會跟 1000 做相乘動作,就會變成 1000,接下來跑另一次 while 會變成 1000 & 0111 就會變成 0 了,退出 while 迴圈,所以結論是 (n -1) 的用意是去掉一個 1 位元 bit,就像 [xxxx10 … 0] -1 = [xxxx01 … 1] …. [Read More]