2012年10月4日 星期四

[Learning Python]不同型態的引號

建立字串時,可以使用『'(單引號)』、『"(雙引號)』、『'''(三個單引號)』或『"""(三個雙引號)』將字串的頭尾兩端括起來。

=>
    Var = 'This is a String'
    Var = "This is a String"
    Var = '''This is a String'''
    Var = """This is a String"""

與 Bash shell 不同,這四種型態的引號對Python來講在功能上是一樣的,Python提供四種型態的引號主要是要讓使用者在建立字串時可以有更多的彈性。

例如當使用單引號括住字串,而字串中又出現縮寫,Python會認為引號不成對,因此就會發生語法錯誤。

=>
Var =  'This isn't a string'

>>> Var =  'This isn't a string'                                              
  File "<stdin>", line 1
    Var =  'This isn't a string'
                     ^
SyntaxError: invalid syntax                







這時就可以改用雙引號或三引號括住字串來解決這個問題。

=>
Var = "This isn't a string"

Var =  '''This isn't a string'''

[Learning Python]建立字串

建立字串有兩種常見的方式可以選擇,

A.指定一個字串給變數 

語法:
    Var = 'String'
    Var = "String"
    Var = '''String'''
    Var = """String"""

    字串要用引號括起來,只要兩端用的引號是一致的即可。

 B.使用 str()函數建立

語法:
    Var = str(String)

    str() 函數也可以用來將其他型別的物件轉換成 str 型別

2012年9月22日 星期六

[Performance Tuning]Monitoring and Analyzing Linux System Performance

1.How to Monitor and Analyz Linux System Performance
2.CPU
3.Memory
4.IO
5.Storage
6.Networking

2012年8月21日 星期二

[Drupal]WYSIWYG Editor Module

1.安裝:http://drupal.org/project/Wysiwyg

2.設定:Modules -> USER INTERFACE -> Wysiwyg ->Configure

  • INPUT FORMAT : 設定在不同輸入模式的介面中可使用的編輯功能
  • INSTALLATION INSTRUCTIONS : 選擇要安裝的 Editor

2012年6月11日 星期一

[KVM]How to convert .vhd image file to the qcow2 image type

如果要將 .vhd 或其他 kvm-img 可辨識的映像檔格式轉換乘 raw 或其他其他 kvm-img 可辨識的映像檔格式,可以使用 kvm-img 命令進行轉換。

使用 kvm-img 轉換映像檔格式的語法如下,

kvm-img  convert -O <Output Format>   <FileName>  <Output FileName>

以下以轉換 .vhd 格式檔案為 .qcow2 格式檔案為例,
 
max@satomi:~$ kvm-img convert -O qcow2 FileName.vhd OutputFileName.qcow2       




所需的轉換時間視主機效能及轉換檔案的大小而定。


2012年6月9日 星期六

[Ubuntu]在Ubuntu 12.04 Desktop 加裝LXDE 與 Gnome 3 Classic 桌面環境(Desktop environment)

將舊筆電 (Fujitsu s6510)升級為 Ubuntu 12.04 Desktop 後發現內建的桌面環境還是沒有 LXDE 與 Gnome , 所以還是要自己動手裝。

加裝 LXDE 比較簡單只需要......
 
$ sudo apt-get update                    
$ sudo apt-get install lxde




就可以了。

如果只需要 LXDE 可以直接裝 lubuntu 12.04 (http://lubuntu.net/)。

加裝 Gnome 就比較麻煩,我是依據 
http://ubuntuguide.net/install-tweak-classic-gnome-desktop-in-ubuntu-12-04-precise/
的方法裝的,不過之後再查,似乎還有其他的安裝程序比較簡便,至於這些不同的程序有何差異......,比起Server 的管理,在 Desktop 的使用上我是採實用主義 , 所以並沒有花時間深入研究的打算 , 總之 , 在使用這個方法加裝 Gnome 前建議先找其他方法試試.....

以下是我加裝Gnome 的紀錄,

1.先加裝『gnome-session-fallback』這個套件 , 再增加『jconti/gnome3』的 repository 加到套件資料庫伺服器清單中



max@tomomi:~$sudo apt-get install gnome-session-fallback               
max@tomomi:~$sudo add-apt-repository ppa:jconti/gnome3





2.接著修改『/etc/apt/sources.list.d/jconti-gnome3-precise.list』的內容

max@tomomi:~$sudo vim /etc/apt/sources.list.d/jconti-gnome3-precise.list         


 


deb http://ppa.launchpad.net/jconti/gnome3/ubuntu precise main
deb-src http://ppa.launchpad.net/jconti/gnome3/ubuntu precise main   



 
 兩行中的『precise』改成『oneiric』....

# deb http://ppa.launchpad.net/jconti/gnome3/ubuntu precise main
deb http://ppa.launchpad.net/jconti/gnome3/ubuntu oneiric main
# deb-src http://ppa.launchpad.net/jconti/gnome3/ubuntu precise main
deb-src http://ppa.launchpad.net/jconti/gnome3/ubuntu oneiric main     






 3.更新套件庫清單後再安裝一大票東西.....

max@tomomi:~$sudo apt-get update     
max@tomomi:~$sudo apt-get install indicator-applet indicaator-applet-complete indicator-applet-session   





不過,目前的 Gnome3 似乎還有不少問題,裝完之後還需要手動調整一些東西,不然並不如Gnome2好用....=_= ~ 有點麻煩....

我調整了.....

1.ALT-TAB 失效。
2.將程式加到快速啟動列之後就無法刪掉。
3.功能表列的字體顏色是深灰色,跟底色幾乎一樣。

等問題 .....囧~~

如果不是 LXDE 沒有延伸桌面可用,以我的需求,其實用 LXDE 就夠了說....囧

2012年5月30日 星期三

[Ubuntu]How to configure network in bridge mode on Ubuntu 10.04 / 12.04

這個程序在 Ubuntu 10.04 及 12.04 都可以用



1.安裝橋接工具套件『bridge-utils』及『 uml-utilities』
 
$ sudo apt-get install bridge-utils uml-utilities



2.新增橋接器『br0』

    橋接器的名稱並沒有特別的規定,比較常看到的是『br0』或『bri0』。

   新增橋接器的語法如下,

        brctl  sddbr   <橋接器名稱>

$ sudo brctl addbr br0


 
3.將eth0接到橋接器『br0』

    概念上就跟使用實體橋接器是一樣的,這個動作可以當成是拿一條網路線連接主機的網路卡與橋接器。

    橋接網路卡的語法如下,

        brctl  sddif    <橋接器名稱>  <實體網卡名稱>

$ sudo brctl addif br0 eth0



4.檢視橋接器

    設定完畢看一下設定結果。

     檢視的語法如下,

        brctl  show

$ sudo brctl show

bridge name          bridge id           STP enabled         interfaces   
br0               8000.c89cdc26033b no                    eth0     
virbr0 8000.000000000000 yes







 5.修改『 /etc/network/interfaces』設定檔

    設定完橋接器之後接著還要修改網路介面設定檔,修改內容如下,

#將eth0的網路組態設定註解掉
# The primary network interface
#auto eth0
#iface eth0 inet dhcp


#新增橋接器網路組態設定
auto br0
iface br0 inet static
#將eth0接到橋接器 br0                                                          
bridge_ports eth0
address X.X.X.X #這是橋接器的IP
netmask A.B.C.D
gateway Y.Y.Y.Y 
















6.啟動 IP Forwarding

    找到『/etc/sysctl.conf』設定檔中的『#net.ipv4.ip_forward=1』 這一行,將前面的註解符號拿掉。

# Uncomment the next line to enable packet forwarding for IPv4 
#net.ipv4.ip_forward=1 
net.ipv4.ip_forward=1  #<--將這一行的註解拿掉,啟動IP Forwarding 』 





7.重開機    

$ sudo reboot                                          



8.收工



Powered By Blogger