1. Display python version:
python -V
2. Python help:
python
>>>help('len') ## help for 'len'
>>>help() ## enter help mode
help>return ## help for 'return'
...................
help>q ## return to python mode
>>>
3. Comments
In python are using # as comment symbol.
4. Single Quote '' and Double Quotes ""
Strings in double quotes work exactly the same way as strings in single quotes.
You can use triple quotes - (""" or ''') for specify multi-line strings. An example is:
''' This is a multi-line string. This is first line.
This is second line.
"How are you?," I asked.
He said "I'm fine."
'''
5. Strings are Immutable
Can not change string after created.
6. Concat strings in python
Example:
age = 20
name = 'Wayne'
print '{0} was {1} years old'.format(name, age)
print 'Why is {0} playing with that python?'.format(name)
print name + ' is ' + str(age) + ' years old too'
print 'My name is', name
Output:
Wayne was 20 years old when he wrote this book
Why is Wayne playing with that python?
Wayne is 20 years old too
My name is Wayne
7. Special char in strings
Can use backreferences \ or raw string: r"This is change line indicated \n"
8. If elif else
number = 23
guess = int(raw_input('Enter an integer:'))
if guess == number:
print 'Guess it'
elif guess < number:
print 'No, it is a litter higher than that'
else:
print 'No, it is a little lower than that'
print 'Done'
8. While
number = 23
running = True
while running:
guess = int(raw_input('Enter an integer : '))
if guess == number:
print 'Congratulations, you guessed it.'
running = False
elif guess < number:
print 'No, it is a little higher than that.'
else:
print 'No, it is a little lower than that.'
else:
print 'The while loop is over.'
print 'Done'
9. For
for i in range(1, 5):
print i
else:
print 'The for loop is over'
10. Function
def say_hello(a):
# block belonging to the function
print 'hello world', a
# End of function
a = 'test'
b = 'happy'
say_hello(a) # call the function
say_hello(b) # call the function again
11. global statement and local scope
x = 50
y = 10
def func(input):
global x ## use global value 50, otherwise will be local scope
print 'input is', input
y = 100
print 'x is', x
print 'y is', y
x = 2
print 'Changed global x to', x
func(y)
print 'Value of x is', x
print 'Value of y is', y
Output:
input is 10
x is 50
y is 100
Changed global x to 2
Value of x is 2
Value of y is 10
12. Default argument values
def say(message, times=1):
print message * times
say('Hello')
say('World', 5)
Output:
Hello
WorldWorldWorldWorldWorld
13. Keyword arguments
def func(a, b=5, c=10):
print 'a is', a, 'and b is', b, 'and c is', c
func(3, 7)
func(25, c=24)
func(c=50, a=100)
#func(b=10) ## Add this line will compile error, should be removed
Output:
a is 3 and b is 7 and c is 10
a is 25 and b is 5 and c is 24
a is 100 and b is 5 and c is 50
14. Varargs parameters
def total(initial=999, *numbers, **keywords):
count = initial
print 'count is', count
for number in numbers:
print 'number is', number
count += number
print '[number]count is', count
for key in keywords:
print 'keywords[key] is', keywords[key]
count += keywords[key]
print '[key]count is', count
return count
print total(10, 1, 2, 3, vegetables=50, fruits=100) ##Cannot use total(10, 1, test=9, 3, vegetables=50, fruits=100) or total(10, 1, 3, vegetables=50, fruits=100, 99) will compile error
Output:
count is 10
number is 1
[number]count is 11
number is 2
[number]count is 13
number is 3
[number]count is 16
keywords[key] is 50
[key]count is 66
keywords[key] is 100
[key]count is 166
166
15.
2015年10月14日 星期三
2015年6月29日 星期一
Broadcom NetXtreme 57xx Gigabit Wireshark VLAN 如何讓網卡可抓到VLAN?
在此是以Broadcom NetXtreme 57xx Gigabit Controller為例,是DELL E5400的筆記型電腦.
- 開始->執行->輸入"regedit"
- 點擊HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet,搜尋"TxCoalescingTicks"
- 找到後在同一個目錄下,右鍵新增字串,名稱輸入"PreserveVlanInfoInRxPacket",值改成"1".
2015年6月18日 星期四
How to build "android-gif-drawable-sample" by Android Studio
1. Download source code from here:
https://github.com/koral--/android-gif-drawable-sample#android-gif-drawable-sample
2. Create a new Project of Android Studio, select "Add no Activity".
3. Copy all folder and file from /android-gif-drawable-sample/sample/src/ to your /project/app/src/
4. Add dependencies of android-gif-drawable:
a. File->Project Structure
b. Select app->Dependencies
c. Add "Library dependency", search "pl.droidsonroids.gif:android-gif-drawable:1.1.7", select it press ok.
5. Build->Rebuild Project.
Done.
https://github.com/koral--/android-gif-drawable-sample#android-gif-drawable-sample
2. Create a new Project of Android Studio, select "Add no Activity".
3. Copy all folder and file from /android-gif-drawable-sample/sample/src/ to your /project/app/src/
4. Add dependencies of android-gif-drawable:
a. File->Project Structure
b. Select app->Dependencies
c. Add "Library dependency", search "pl.droidsonroids.gif:android-gif-drawable:1.1.7", select it press ok.
5. Build->Rebuild Project.
Done.
2015年6月11日 星期四
Android Studio安裝教學與問題排解
1. 安裝Android Studio前要先安裝好
a. JAVA jdk ----- 編譯java用
b. Gradle ------ 用來管理Project的程式
1.1 Java JDK 安裝:
設定環境變數:
JAVA_HOME: C:\Program Files\Java\jdk1.8.0_45
1.2 Gradle 安裝:
a. Download Gradle from here : https://gradle.org/downloads/ , select Complete distribution.
b. Unzip this file.
c. 設定環境變數, 新增變數GRADLE_HOME, 在原有Path後新增%GRADLE_HOME%\bin:
GRADLE_HOME: F:\software\gradle-2.4
Path: xxx;%GRADLE_HOME%\bin
d. 測試是否安裝成功: 在cmd下執行gradle -v, 若有版本顯示則安裝成功。
2. 安裝Android Studio:
Download from here: https://developer.android.com/sdk/index.html, click "Download Android Studio For Windows".
########## 問題排解 #############
Q1.使用ActionBar時啟動出現 java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity...... ?
A: change styles.xml to
A: install plugins "Android Drawable Importer".
1. File->Settings->Plugins search "Android Drawable Importer" and install.
2. To use: Right clicks on "Drawable" folder->New->, you can see four options.
Select what you want.
a. JAVA jdk ----- 編譯java用
b. Gradle ------ 用來管理Project的程式
1.1 Java JDK 安裝:
設定環境變數:
JAVA_HOME: C:\Program Files\Java\jdk1.8.0_45
1.2 Gradle 安裝:
a. Download Gradle from here : https://gradle.org/downloads/ , select Complete distribution.
b. Unzip this file.
c. 設定環境變數, 新增變數GRADLE_HOME, 在原有Path後新增%GRADLE_HOME%\bin:
GRADLE_HOME: F:\software\gradle-2.4
Path: xxx;%GRADLE_HOME%\bin
d. 測試是否安裝成功: 在cmd下執行gradle -v, 若有版本顯示則安裝成功。
2. 安裝Android Studio:
Download from here: https://developer.android.com/sdk/index.html, click "Download Android Studio For Windows".
########## 問題排解 #############
Q1.使用ActionBar時啟動出現 java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity...... ?
A: change styles.xml to
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar" />Q2.How to add pic to android studio ?如何將圖檔加入android studio專案中?
A: install plugins "Android Drawable Importer".
1. File->Settings->Plugins search "Android Drawable Importer" and install.
2. To use: Right clicks on "Drawable" folder->New->, you can see four options.
Select what you want.
2014年12月8日 星期一
How to change linux kernel on Ubuntu
-----Ubuntu 10.04 linux kernel upgrade form 2.6.32-21-generic to 3.18.0 --------
P.S. Commands marks as purple.
1.
Download linux kernel from https://www.kernel.org/
Choose file: linux-3.18.tar.xz
2.
sudo apt-get install xz-utils
tar Jxvf linux-3.18.tar.xz
3.
sudo apt-get install libncurses5-dev
sudo apt-get install kernel-package
cd linux-3.18
sudo cp /boot/config-2.6.32-21-generic .config
make menuconfig
fakeroot make-kpkg --initrd --revision huang.001 --append-to-version -20141208 kernel_image
4.
double click and install "linux-image-3.18.0-20141208_huang.001_i386.deb"
5.
check new linux kernel module name:
ls /lib/modules/
2.6.32-21-generic 3.18.0-20141208
6. create initrd:
cd /boot
sudo makinitramfs -k -o initrd.img-3.18.0-20141208 3.18.0-20141208
sudo update-grub2
sudo reboot
P.S. if you doesn't do step6 will occur "kernel panic - not syncing : VFS : unable to mount root fs on unknown block (0,0)".
7.
When Ubuntu reboot, long press SHIFT will into GRUB menu,
Select new kernel "3.18.0-20141208", done.
P.S. Commands marks as purple.
1.
Download linux kernel from https://www.kernel.org/
Choose file: linux-3.18.tar.xz
2.
sudo apt-get install xz-utils
tar Jxvf linux-3.18.tar.xz
3.
sudo apt-get install libncurses5-dev
sudo apt-get install kernel-package
cd linux-3.18
sudo cp /boot/config-2.6.32-21-generic .config
make menuconfig
fakeroot make-kpkg --initrd --revision huang.001 --append-to-version -20141208 kernel_image
4.
double click and install "linux-image-3.18.0-20141208_huang.001_i386.deb"
5.
check new linux kernel module name:
ls /lib/modules/
2.6.32-21-generic 3.18.0-20141208
6. create initrd:
cd /boot
sudo makinitramfs -k -o initrd.img-3.18.0-20141208 3.18.0-20141208
sudo update-grub2
sudo reboot
P.S. if you doesn't do step6 will occur "kernel panic - not syncing : VFS : unable to mount root fs on unknown block (0,0)".
7.
When Ubuntu reboot, long press SHIFT will into GRUB menu,
Select new kernel "3.18.0-20141208", done.
2014年11月3日 星期一
Bluestacks更改視窗大小新方法!!
之前有找到更改Bluestacks視窗大小都是改regedit登錄值的方法,但改來改去還是沒用.
現在有一個更快更簡便的方法,重點是一定會成功!!!
就是用這個軟體:Divvy ----- Windows or Mac的視窗分割軟體
Divvy : http://mizage.com/windivvy/
下載網址 : windows
mac
簡介使用方法就是安裝完後:
1. 先設置快捷鍵如圖,意思是當你想要改變視窗大小時就按"space" :
P.S. 個人是設定鍵盤最右邊的減號(-),因為空白鍵太常用了,截圖用space是為了方便辨識.
2. 點選欲縮小的視窗,按space,之後拖曳想要的大小, 完成!!!!!!!!
從此擺脫用regedit修改BS的方法!!
2014年9月23日 星期二
2014年4月11日 星期五
Password for '(null)' GNOME keyring
用svn checkout時發生以下問題,無法登入:
Password for '(null)' GNOME keyring:
解決辦法:
rm ~/.gnome2/keyrings/login.keyring
再重新輸入帳密即可
2014年3月26日 星期三
ubuntu 10.04 libstdc++5 not found solution
1. download libstdc++5_3.3.6-20~lucid1_i386.deb from here .
2. dpkg -i libstdc++5_3.3.6-20~lucid1_i386.deb
done!
-------------------------------------------------------------------------------------
If you using Debian OS, just type:
sudo apt-get install libstdc++5
done!
2. dpkg -i libstdc++5_3.3.6-20~lucid1_i386.deb
done!
-------------------------------------------------------------------------------------
If you using Debian OS, just type:
sudo apt-get install libstdc++5
done!
2013年12月26日 星期四
紅米 記憶卡置換 將SD卡設為第一順位
2014/10/06 update:
紅米手機更新新版後似乎有些變動:
dev_mount sdcard2 /storage/sdcard1 auto /devices/platform/goldfish_mmc.1 /devices/platform/mtk-msdc.1/mmc_host --- SD卡會變成手機儲存空間,有些遊戲會有問題(ex.蜘蛛人:飛越無限無法下載額外章節 or House of the Dead Overkill:file not found problem)
or
dev_mount sdcard2 /storage/sdcard0 auto /devices/platform/goldfish_mmc.1 /devices/platform/mtk-msdc.1/mmc_host --- SD卡仍是SD卡,如果已將手機空間蔽屏,會無法使用相機
=====================================================================
此方法需準備一張SD卡容量越大越好(最大32GB)
1. 手機要先root. (沒有root可用root大師,或是百度一鍵root)
2. 將800MB手機儲存空間內的資料COPY到SD記憶卡內,然後格式化800MB那個空間.
3. 用Root Explorer到目錄: \etc 找到vold.fstab
4. Root Explorer切換為 "Mount R/W" 這樣才能修改系統檔案.
5. 打開vold.fstab照以下修改:
找到兩行:
修改前:
dev_mount sdcard /storage/sdcard0 emmc@fat /devices/platform/goldfish_mmc.0 /devices/platform/mtk-msdc.0/mmc_host
dev_mount sdcard2 /storage/sdcard1 auto /devices/platform/goldfish_mmc.1 /devices/platform/mtk-msdc.1/mmc_host
修改後:
#dev_mount sdcard /storage/sdcard0 emmc@fat /devices/platform/goldfish_mmc.0 /devices/platform/mtk-msdc.0/mmc_host
dev_mount sdcard2 /storage/sdcard0 auto /devices/platform/goldfish_mmc.1 /devices/platform/mtk-msdc.1/mmc_host
將上面註解掉是為了將800MB的手機空間蔽屏,不要使用,下面改成0是將SD卡預設改成"手機空間".
這樣以後裝遊戲或軟體就不會出現"手機內存不足"的問題了.
改完之後儲存空間的截圖:
紅米手機更新新版後似乎有些變動:
dev_mount sdcard2 /storage/sdcard1 auto /devices/platform/goldfish_mmc.1 /devices/platform/mtk-msdc.1/mmc_host --- SD卡會變成手機儲存空間,有些遊戲會有問題(ex.蜘蛛人:飛越無限無法下載額外章節 or House of the Dead Overkill:file not found problem)
or
dev_mount sdcard2 /storage/sdcard0 auto /devices/platform/goldfish_mmc.1 /devices/platform/mtk-msdc.1/mmc_host --- SD卡仍是SD卡,如果已將手機空間蔽屏,會無法使用相機
=====================================================================
此方法需準備一張SD卡容量越大越好(最大32GB)
1. 手機要先root. (沒有root可用root大師,或是百度一鍵root)
2. 將800MB手機儲存空間內的資料COPY到SD記憶卡內,然後格式化800MB那個空間.
3. 用Root Explorer到目錄: \etc 找到vold.fstab
4. Root Explorer切換為 "Mount R/W" 這樣才能修改系統檔案.
5. 打開vold.fstab照以下修改:
找到兩行:
修改前:
dev_mount sdcard /storage/sdcard0 emmc@fat /devices/platform/goldfish_mmc.0 /devices/platform/mtk-msdc.0/mmc_host
dev_mount sdcard2 /storage/sdcard1 auto /devices/platform/goldfish_mmc.1 /devices/platform/mtk-msdc.1/mmc_host
修改後:
#dev_mount sdcard /storage/sdcard0 emmc@fat /devices/platform/goldfish_mmc.0 /devices/platform/mtk-msdc.0/mmc_host
將上面註解掉是為了將800MB的手機空間蔽屏,不要使用,下面改成0是將SD卡預設改成"手機空間".
這樣以後裝遊戲或軟體就不會出現"手機內存不足"的問題了.
改完之後儲存空間的截圖:
2013年8月5日 星期一
XP清除自訂通知
Q:如何清除XP右下角自訂通知內 沒用到的項目?
A:
下載微軟修復程式
http://go.microsoft.com/?linkid=9643521
執行即可。
參考網頁:
http://support.microsoft.com/kb/283084/zh-tw
A:
下載微軟修復程式
http://go.microsoft.com/?linkid=9643521
執行即可。
參考網頁:
http://support.microsoft.com/kb/283084/zh-tw
2013年6月10日 星期一
Chrome Firefox 私密瀏覽 捷徑 參數
Chrome :
1. 新增一個正常的Chrome捷徑.
2. 在捷徑按右鍵選內容,
目標後多加參數 --incognito
例:
"C:\Program Files\Google\Chrome\Application\chrome.exe" --incognito
3. 保存即可.
=========================================================
Firefox :
1. 新增一個正常的Firefox捷徑.
2. 在捷徑按右鍵選內容,
目標後多加參數 -private
例:
D:\FirefoxPortable\FirefoxPortable.exe -private
3. 保存即可.
1. 新增一個正常的Chrome捷徑.
2. 在捷徑按右鍵選內容,
目標後多加參數 --incognito
例:
"C:\Program Files\Google\Chrome\Application\chrome.exe" --incognito
3. 保存即可.
=========================================================
Firefox :
1. 新增一個正常的Firefox捷徑.
2. 在捷徑按右鍵選內容,
目標後多加參數 -private
例:
D:\FirefoxPortable\FirefoxPortable.exe -private
3. 保存即可.
2013年4月23日 星期二
重新啟動OnDo SIP Server
有時更新完Java後
SIP Server會無法使用,
這時候要重新啟動服務.
1.執行->輸入Services.msc
2.找到OnDo SIP Server設為啟動.
SIP Server會無法使用,
這時候要重新啟動服務.
1.執行->輸入Services.msc
2.找到OnDo SIP Server設為啟動.
2012年3月21日 星期三
2012年2月15日 星期三
Soluation: Wireshark cannot see traffic from a VirtualBox(Linux)
Step1 : Install Wireshark in VirtualBox OS (Linux).
Step2 : Excute command "sudo chmod u+s /usr/bin/dumpcap"
(refer:http://softsmith.blogspot.com/2008/10/non-root-wireshark.html)
Step3 : Change VirtualBox network Promiscuous mode to "Allow All". Done!
Step2 : Excute command "sudo chmod u+s /usr/bin/dumpcap"
(refer:http://softsmith.blogspot.com/2008/10/non-root-wireshark.html)
Step3 : Change VirtualBox network Promiscuous mode to "Allow All". Done!
2012年1月19日 星期四
Generate random number in a loop and call srand one time when function be called
In stdlib.c, the random seed "holdrand= 1L".
If you don't change random seed,
random sequence will be same when you execute program.
To change seed can use srand().
In some situation, function will be called repeatedly.
You want to call srand() just one time, how to do??
There is a soluation.
Because the first rand() value will be 1804289383.
We can design the code:
=======================================
int GetRandomNum() {
int tempnum = rand();
if ( 1804289383 == tempnum ) {
srand( time(NULL) );
}
for ( int i = 0 ; i < ( maxnum - minnum ) ; i++ ) {
outValue = minnum + tempnum%( maxnum - minnum + 1 );
if ( outValue != xx ) {
return outValue;
}
tempnum = rand();
}
}
=======================================
It will guarantee "srand()" will be executed once.
Have fun!!
If you don't change random seed,
random sequence will be same when you execute program.
To change seed can use srand().
In some situation, function will be called repeatedly.
You want to call srand() just one time, how to do??
There is a soluation.
Because the first rand() value will be 1804289383.
We can design the code:
=======================================
int GetRandomNum() {
int tempnum = rand();
if ( 1804289383 == tempnum ) {
srand( time(NULL) );
}
for ( int i = 0 ; i < ( maxnum - minnum ) ; i++ ) {
outValue = minnum + tempnum%( maxnum - minnum + 1 );
if ( outValue != xx ) {
return outValue;
}
tempnum = rand();
}
}
=======================================
It will guarantee "srand()" will be executed once.
Have fun!!
2011年10月31日 星期一
2011年10月28日 星期五
2011年10月20日 星期四
Linux 設置 永久 PATH
1.
#gedit /etc/profile
(如果開啟profile發現是唯獨的話要改變權限)
#sudo chmod 777 /etc/profile
2.
在profile最後一行加入
export PATH="$PATH:/opt/toolchains/xxx/usr/bin"
3.
重新登入PATH就會被加進去了。
#gedit /etc/profile
(如果開啟profile發現是唯獨的話要改變權限)
#sudo chmod 777 /etc/profile
2.
在profile最後一行加入
export PATH="$PATH:/opt/toolchains/xxx/usr/bin"
3.
重新登入PATH就會被加進去了。
2011年6月15日 星期三
provider registration API
Provider registration API : the system uses it to register implementations, giving clients access to them.
Service access API : clients use to obtain an instance of the service.
Service access API : clients use to obtain an instance of the service.
訂閱:
文章 (Atom)






