2010年4月27日 星期二

CSS簡寫指南

CSS简写指南 | CSS | 前端观察

高效的css寫法中的一條就是使用簡寫。通過簡寫可以讓你的CSS文件更小,更易讀。而瞭解CSS屬性簡寫也是前端開發工程師的基本功之一。今天我 們系統地總結一下CSS屬性的縮寫。

色彩縮寫

色 彩的縮寫最簡單,在色彩值用16進制的時候,如果每種顏色的值相同,就可以寫成一個:
1
color:#113366
可 以簡寫為
1
color:#136
所 有用到16進制色彩值的地方都可以使用簡寫,比如background-color、border-color、text-shadow、box- shadow等。

盒子大小

這裡主要用於兩個屬性:margin和padding,我們以margin為 例,padding與之相同。盒子有上下左右四個方向,每個方向都有個外邊距:
1
2
3
4
margin-top:1px;
margin-right:1px;
margin-botton:1px;
margin-left:1px;
這 四個值可以縮寫到一起:
1
margin:1px 1px 1px 1px;
縮 寫的順序是上->右->下->左。順時針的方向。相對的邊的值相同,則可以省掉:
1
2
3
4
margin:1px;//四個方向的邊距相同,等同於margin:1px 1px 1px 1px;
margin:1px 2px;//上下邊距都為1px,左右邊距均為2px,等同於margin:1px 2px 1px 2px
margin:1px 2px 3px;//右邊距和左邊距相同,等同於margin:1px 2px 3px 2px;
margin:1px 2px 1px 3px;//注意,這裡雖然上下邊距都為1px,但是這裡不能縮寫。

邊 框(border)

border是個比較靈活的屬性,它有border-width、border-style、border- color三個子屬性。
1
2
3
border-width:數字+單位;
border-style: none || hidden || dashed || dotted || double || groove || inset || outset || ridge || solid ;
border-color: 顏色 ;
它 可以按照width、style和color的順序簡寫:
1
border:5px solid #369;
有 的時候,border可以寫的更簡單些,有些值可以省掉,但是請注意哪些是必須的,你也可以測試一下:
1
2
3
4
5
border:groove red;  //大家猜猜這個邊框的寬度是多少?
border:solid;  //這會是什麼樣子?
border:5px;  //這樣可以嗎?
border:5px red; //這樣可以嗎??
border:red; //這樣可以嗎???
通 過上面的代碼可以瞭解到,border默認的寬度是3px,默認的色彩是black——黑色。border的縮寫中border- style是必須的。
同時,還可以對每條邊採用縮寫:
1
2
3
4
border-top:4px solid #333;
border-right:3px solid #666;
border-bottom:3px solid #666;
border-left:4px solid #333;
還 可以對每個屬性採用縮寫:
1
2
3
border-width:1px 2px 3px; //最多可用四個值,縮寫規則類似盒子大小的縮寫,下同
border-style:solid dashed dotted groove;
border-color:red blue white black;

outline

outline 類似border,不同的是border會影響盒模型,而outline不會。
1
2
3
outline-width:數字+單位;
outline-style: none || dashed || dotted || double || groove || inset || outset || ridge || solid ;
outline-color: 顏色 ;
可 以縮寫為:
1
outline:1px solid red;
同 樣,outline的簡寫中,outline-style也是必須的,另外兩個值則可選,默認值和border相同。

背景 (background)

background是最常用的簡寫之一,它包含以下屬性:
1
2
3
4
5
background-color: color || #hex || RGB(% || 0-255) || RGBa;
background-image:url();
background-repeat: repeat || repeat-x || repeat-y || no-repeat;
background-position: X Y || (top||bottom||center) (left||right||center);
background-attachment: scroll || fixed;
background 的簡寫可以大大的提高css的效率:
1
background:#fff url(img.png) no-repeat 0 0;
background 的簡寫也有些默認值:
1
background:transparent none repeat scroll top left ;
background 屬性的值不會繼承,你可以只聲明其中的一個,其它的值會被應用默認的。

font

font簡寫也是使用最多的一個,它也是 書寫高效的CSS的方法之一。
font包含以下屬性:
1
2
3
4
5
6
font-style: normal || italic || oblique;
font-variant:normal || small-caps;
font-weight: normal || bold || bolder || || lighter || (100-900);
font-size: (number+unit) || (xx-small - xx-large);
line-height: normal || (number+unit);
font-family:name,"more names";
font 的各個屬性也都有默認值,記住這些默認值相對來說比較重要:
1
2
3
4
5
6
font-style: normal;
font-variant:normal;
font-weight: normal;
font-size: inherit;
line-height: normal;
font-family:inherit;
事 實上,font的簡寫是這些簡寫中最需要小心的一個,稍有疏忽就會造成一些意想不到的後果,所以,很多人並不贊成使用font縮寫。
不 過這裡正好有個小手冊,相信會讓你更好的理解font的簡寫:
font缩写

列 表樣式

可能大家用的最多的一條關於列表的屬性就是:
1
list-style:none
它 會清除所有默認的列表樣式,比如數字或者圓點。
list-style也有三個屬性:
1
2
3
list-style-type:none || disc || circle || square || decimal || lower-alpha || upper-alpha || lower-roman || upper-roman
list-style-position:  inside || outside || inherit
list-style-image:  (url) || none || inherit
list- style的默認屬性如下:
1
list-style:disc outside none
需 要注意的是,如果list-tyle中定義了圖片,那麼圖片的優先級要比list-style-type高,比如:
list-style:circle inside url(../img.gif)
這 個例子中,如果img.gif存在,則不會顯示前面設置的circle符號。
PS:其實list-style-type有很多種很有用的樣 式,感興趣的同學可以參考一下:https://developer.mozilla.org/en/CSS/list-style-type

border- radius(圓角半徑)

border-radius是css3中新加入的屬性,用來實現圓角邊框。這個屬性目前不好的一點兒是,各個瀏 覽器對它的支持不同,IE尚不支持,Gecko(firefox)和webkit(safari/chrome)等需分別使用私有前綴-moz-和 -webkit-。更讓人糾結的是,如果單個角的border-radius屬性的寫法在這兩個瀏覽器的差異更大,你要書寫大量的私有屬性:
1
2
3
4
5
6
7
8
9
-moz-border-radius-bottomleft:6px;
-moz-border-radius-topleft:6px;
-moz-border-radius-topright:6px;
-webkit-border-bottom-left-radius:6px;
-webkit-border-top-left-radius:6px;
-webkit-border-top-right-radius:6px;
border-bottom-left-radius:6px;
border-top-left-radius:6px;
border-top-right-radius:6px;
呃, 是不是你已經看的眼花了?這只是要實現左上角不是圓角,其它三個角都是圓角的情況。所以對於border-radius,神飛強烈建議使用縮寫:
1
2
3
-moz-border-radius:0 6px 6px;
-webkit-border-radius:0 6px 6px;
border-radius:0 6px 6px;
這 樣就簡單了很多。PS:不幸的是,最新的Safari(4.0.5)還不支持這種縮寫… (thanks @fireyy)

PostgreSQL 的自動備份策略

ChiaHu's Blog » PostgreSQL 的自動備份策略

如果 PostgreSQL 的連線設定需要使用密碼,那麼在利用 crontab 排程自動執行備份指令時,也會遇到需要輸入密碼而無法自動執行的情況。
如果你需要多台資料庫並行運作,共用負擔資料的操作動作,而且資料內容異動頻繁。那麼你需要採用 WAL 的方式。另一種採用 WAL 的場合在大型資料庫系統。當你的資料庫空間成長到數百MB或GB的單位時,你也需要考慮改用 WAL 。因為 WAL 採用 log 同步機制,每次備份時只需要傳輸上次備份時間到目前時間的異動資訊,而不會傳輸整個資料庫的內容。關於 WAL 的操作,不在本文的說明中。
PostgreSQL 在 8 版之後可以使用「.pgpass」來為使用者設定自動認證。
以下介紹詳細步驟
1. 假如我們要連線的資料庫位置為「localhost」(表示本機端)、連接埠為「5432」(PostgreSQL預設連接埠)、資料庫名稱為 「database」、資料庫帳號為「username」、密碼為「password」。注意,username 不一定要跟你執行 crontab 的帳號相同。
2. 切換到執行 crontab 的實體帳號,假如是「postgres」,則利用su指令切換:
[postgres@pgdb:/root/]# su postgres
3. 在該帳號的家目錄新增檔案「.pgpass」
[postgres@pgdb:/home/postgres/]# vi ~/.pgpass
4. 利用vi編輯器輸入以下資料:(格式為: hostname:port:database:username:password )
localhost:5432:database:username:password
完成之後儲存離開。
5. 修改 .pgpass 的權限為 600
[postgres@pgdb:/home/postgres/]# chmod 600 ~/.pgpass
6. 測試看看,利用 pg_dump 匯出資料庫到「/backups/dbbak.sql」
[postgres@pgdb:/]# pg_dump -U username database > /backups/dbbak.sql
7. 如果「/backups/dbbak.sql」有檔案,並且內文為正確的 SQL 檔,則表示認證成功。反之,如果系統要求你輸入密碼,那可能是哪個步驟做錯了,請回頭一一確認。
8.當確認可以自動通過認證,以指令執行 PostgreSQL 匯出的之後,就可以把這些指令撰寫於 backupdb.sh,將它放置在 /home/postgres 底下,backupdb.sh 參考內容如下:
#!/bin/sh

day=`date +%Y-%m-%d`
pg_dump -U username database > /backups/dbbak_$day.sql
說明:也就是將 database 資料庫備份到 /backups/ 底下,檔名則依 dbbak_年月日.sql 格式命名
9. 加入 crontab 排程內,每天凌晨3:30做備份。
30 3 * * * postgres /home/postgres/backupdb.sh

2010年2月24日 星期三

thin 無法啟動?Missing the Rails 2.3.5 gem?

Thin 是比 Mongrel 更快的Web服务器

安裝 thin 非常簡單
sudo gem install thin

啟動方式
到rails的應用目錄下,打入
thin start

但啟動後卻會出現錯誤訊息
Missing the Rails 2.3.5 gem. Please `gem install -v=2.3.5 rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.

解決方式:移除rack 1.1.0,保留rack 1.0.1
sudo gem uninstall rack

若沒有 rack 1.0.1,可自行安裝
sudo gem install rack -v 1.0.1

2010年2月7日 星期日

ubuntu 中文歌詞插件 for Rhythmbox

sogou-lyrics
鲁班歌词(RBLyrics):Rhythmbox的歌词下载显示插件
(a plugin for rhythmbox to download and display lyrics)

下載點Downloads

这是什么(Introduction)

这是一个Rhythmbox的插件。这个插件能够下载Rhythmbox当前播放歌曲的歌词,并使 用多种方式显示。
This is a lyrics plugin for Rhythmbox. Lyrics is downloaded and displayed automatically.

屏幕截图(Screenshot)

original[1280 x 800] now[30.4%]
screenshot
点击查看大图(click to enlarge)

功能特性(Feature)

  1. 从多个歌词源下载歌词并保存到本地(download lyrics from various sources)
  2. 自动载入本地歌词,自动检测文件编码(load local lyrics automatically)
  3. 嵌入界面显示歌 词(display lyrics embedded in the interface)
  4. 使用gnome-osd显示歌词(display lyrics using gnome-osd)
  5. 滚动显示歌词,鼠标左键拖动可以移动窗口,中键拖动可以定位歌词,右键拖动可以改变窗口大小 (display lyrics in a auto scroll window, press left button and drag will move the window, press right button and drag will resize the window, press middle button and drag will locate lyrics in roller mode)
  6. 使用系统默认编辑器打开歌词文件(open lyrics file using system default editor)
  7. 未能精确查找歌词时,弹出歌词选择对话框 供用户选择(pop choose lyrics dialog while no accurate lyrics found)
  8. 右键菜单中加入编辑歌词和手动下载歌词(edit lyrics and download lyrics manually in context menu)
  9. 可通过插件管理器 配置插件功能(totally configurable through plugin manager)
  10. 以上功能可能会随着项目进展有暂时改动(keep up with updates, discover yourself)

如何安装(Install)

下载最新的deb包安装,重启rhythmbox.你会在插件管理器中发现鲁班歌词.
Download latest deb package and install. RBlyrics will be listed in the plugin manager after restart rhythmbox.

2010年1月22日 星期五

ubuntu 9.10 禁用 IPV6

如何禁用IPv6

ubuntu 8.10之後的版本想要禁止 IPV6 需要在啟動內核後面加入“disable_ipv6=1” 做內核參數直接傳遞。

........................................

對於ubuntu 9.10 ,可用以下方法:


1. gksu gedit /etc/default/grub


將

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
变为
GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1 quiet splash"

2. sudo update-grub