mockup

guideline

wireframe

fireworks
sketch
xara
axure
balsamiq
moqups
wireframe.cc

mockup tool

invision
marvelapp.com
mockplus.com
fluidui.com
placeit.net
lucidchart.com
cacoo
lumzy
pencil
gliffy
mockflow
mockup designer

magic numbers

abed, ab1e, aced, a1ec, a1ef, a10e, bade, ba1d, ba1e, bead, b1ae, b1ed, b10c, b0de, b01a, b01d, b01e, cade, cafe, ca1f, c1ad, c1ef, c10d, c0al, c0da, c0de, c0ed, c01a, c0ld, c01e, dace, da1e, deaf, dea1, dec0, de1f, d01e, face, fade, fad0, fea1, fe0d, f1ab, f1ea, f1ed, f10c, f10e, f0al, f01d, 1ace, 1ade, 1ead, 1eaf, 10ad, 10af, 10be, 10ca, 10de, 0dea, 01ea
0xABBA, 0xABBE, 0xABED, 0xACED, 0xBABA, 0xBABE, 0xBADE, 0xBAFF, 0xBEAD, 0xBEEF, 0xB0DE, 0xB0FF, 0xB00B, 0xCACA, 0xCADE, 0xCAFE, 0xCECA, 0xCEDE, 0xC0BB, 0xC0CA, 0xC0C0, 0xC0DA, 0xC0DE, 0xC0ED, 0xC0FF, 0xC00F, 0xDACE, 0xDADA, 0xDAD0, 0xDAFF, 0xDEAD, 0xDEAF, 0xDEC0, 0xDEED, 0xD0D0, 0xD0FF, 0xEDD0, 0xFACE, 0xFADE, 0xFAD0, 0xFEED, 0xFE0D, 0xF00D, 0x0B0E, 0x0DEA

ab0de, ac01d, ad0be, ba1ed, b1ade, cab1e, c0b1e, c01ed, decaf, deca1, d0b1a, d01ce, fab1e, faced, feca1, f0ca1, 1aced, 10bed
0xABACA, 0xAB0DE, 0xADDED, 0xAD0BE, 0xAD0B0, 0xBAAED, 0xBAB00, 0xBACCA, 0xB0CCE, 0xB0DED, 0xB0FF0, 0xB00ED, 0xCAB0B, 0xCACA0, 0xCAECA, 0xCEDED, 0xC0C0A, 0xC0DEC, 0xC0DED, 0xC00ED, 0xC00EE, 0xDECAF, 0xEBBED, 0xFACED, 0xFADED, 0xFE0FF, 0x0FFED

a1bed0, cab1ed, c0a1ed, c01ead, d0ab1e, fab1ed, f0a1ed, 10afed
0xAB0DED, 0xACCEDE, 0xBACCAE, 0xBAFFED, 0xBA0BAB, 0xBEADED, 0xBEDDED, 0xBEEBEE, 0xBEEFED, 0xB0BBED, 0xB00BED, 0xB00B00, 0xCABBED, 0xC0DDED, 0xC0FFEE, 0xC00C00, 0xC00EED, 0xDABBED, 0xDAD0ED, 0xDAFFED, 0xDECADE, 0xDEC0DE, 0xDEEDED, 0xDEFACE, 0xD0FFED, 0xD00DAD, 0xEFFACE, 0xFACADE, 0xF0BBED

c0dab1e
0xACCEDED, 0xDEC0DED, 0xDEFACED, 0xEFFACED, 0xFE0FFED, 0xFE0FFEE

b01dface, f1a7bed5, 0b57ac1e, deadc0de, c001c0de, ad0beace, c01dc01a, ba5ed0c5…

https://en.wikipedia.org/wiki/Magic_number_(programming)

thoughts

現在的實體書主要承載的已經不是知識了,而是出版產業的利益。
沒人買書;產業蕭條,也是剛好而已。

光有才華能力而無洞見人心是只有在效率最大化的合作組織裡才能生存的。
一但組織並不以合作共榮為前題,視效率為次要時,只有才華並不會得到辛福。還必需有壓制他人心機慾望的手腕和理解。

當你沒能力理解個中因果相關時,把一切成敗都歸為運氣是最簡單的。

導入障礎的各種成本背後都有其原因

世上最垃圾的東西就是分析了
不說運匠大哥,即便是路邊的阿伯都可以跟你分析一下政治情勢。
有沒有價值?除了當成鄉野考察研究樣本,還真沒什麼價值。

那有大數據佐視覺化有沒有比較好賣?
大學生做報告都會再多來個雲端和IoT,我相信經過這八年,口號我們都聽膩了。

當你以為你要佔便宜了,好興奮時,冷靜下來。所有的事情都是give and take。

你不用去新創也會。新創教不了你什麼有價值的東西。

誰在騙你
有資源的新創跟沒資源的新創,成功的機會和結果會一樣嗎?
當然不會!你爸爸給你五千萬練手跟你畢業有五十萬學貸負債怎麼會一樣。

幾億人口裡出一個Jobs,那個叫生存者偏差。
代表的是你成功的可能性又被稀釋掉了一大塊,而不是你也有可能成為Jobs。

看是找人力還是找人才的判斷很簡單。就是你來面試跟你什麼時候有空我去找你聊聊的差別。

團隊裡有C咖真是傷害巨大。要不你找不到A咖願意跟C咖共事,要不你得付出超額代價來讓A咖忍受和C咖一起共事還得不到A咖的效率。


study
大量閱讀,挑撿過濾出精要部份。
使用適當工具不斷練習


murmur

大多數人的想像力都很差,也造成對其他文化的新事物難以接受。

即使好東西放在面前,沒那個格也是無福消受。

若找不來優秀的人才,則團隊必定平庸。 若人才來了卻待不久,則團隊必在平庸之下。

tomcat 6.0.35 to 8.0.33

起因於 tomcat6 不支援 jdk8 ,而我想在 tomcat 上試試G1GC,所以試著更新版本就出現相容性問題了。

issue 在jsp中使用 fullpackage.classname 會導致 cannot be resolved to a type

改用 <@import “fullpackage.*” %> 解決

issue javax.el.ELException: Cannot convert m of type class java.lang.String to class java.lang.Long

el 裡有 a.mark==’m’ 的判斷,在新版中不允許 char 的判斷了。必需當成數字而改寫成 a.mark==77

cassandra

version

3.5

quick start

1
2
bin\cassandra
bin\cqlsh

configuration

1
2
3
4
5
6
7
vi conf/logback.xml
vi conf/cassandra.yaml
#data_file_directories視資料量通當指定到比較大的磁碟上
data_file_directories: g:/var/lib/cassandra/data
saved_caches_directory: g:/var/lib/cassandra/saved_caches
#commitlog_directory可以放到比較快的SSD上
commitlog_directory: g:/var/lib/cassandra/commitlog

test drop/create keyspace/table, import data, count table, find data

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
28
29
30
31
32
33
34
35
36
37
38
39
#####create keyspace/table
# use system; drop keyspace test;
#CREATE KEYSPACE test WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 2 };
CREATE KEYSPACE test WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
#describe keyspaces; describe keyspace test;
use test;
create table test(id varchar primary key, value text)
with bloom_filter_fp_chance=1;
alter table test
with bloom_filter_fp_chance=1;
desc test.test;
insert into test(id,value)values('testid','testvalue');
select * from test.test;
delete from test where id='testid';
select * from test.test;
#default 0.01, use 1 to disable bloomfilter and save memory
create table content (id varchar primary key, content text)
with bloom_filter_fp_chance=1;
#default 0.01, use 1 to disable bloomfilter and save memory
alter table content
with bloom_filter_fp_chance=1;
#disable compression
alter table content WITH compression = { 'sstable_compression' : '' };
alter table content WITH compression = { 'sstable_compression' : 'LZ4Compressor' };
alter table content WITH compression = { 'sstable_compression' : 'DeflateCompressor'};
alter table content WITH compression = { 'sstable_compression' : 'DeflateCompressor', 'chunk_length_kb' : 64 };
select * from content;
~~select * from system.schema_keyspaces;~~
desc keyspaces;
desc keyspace test;
describe tables;
describe table content;

#####import from file
copy content(id,content ) from 'g:\t\test.content.data.csv';

#####
use test; select count(*) from content limit 2147483647;
select * from content where id='01435a9f57718a8080e44358b3ff060b';

#

insert into content (id,content) values(‘test’,’test中文許功蓋’);

#

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
28
29
30
31
32
33
34
#bin\nodetool flush [keyspace] [cfnames]
bin\nodetool flush test
bin\nodetool -h localhost -p 7199 flush
bin\nodetool -h localhost -p 7199 cfstats
bin\nodetool -h localhost -p 7199 status
bin\nodetool -h localhost -p 7199 gcstatus
bin\nodetool -h localhost -p 7199 cleanup
bin\nodetool -h localhost -p 7199 cleanupsnapshot
bin\nodetool -h localhost -p 7199 compact
bin\nodetool -h localhost -p 7199 compactionhistory
bin\nodetool -h localhost -p 7199 compactionstatus
bin\nodetool -h localhost -p 7199 describecluster
bin\nodetool -h localhost -p 7199 describering
bin\nodetool -h localhost -p 7199 info
bin\nodetool -h localhost -p 7199 join
bin\nodetool -h localhost -p 7199 netstats
bin\nodetool -h localhost -p 7199 repair
bin\nodetool -h localhost -p 7199 rebuild
bin\nodetool -h localhost -p 7199 ring
bin\nodetool -h localhost -p 7199 tpstats
bin\nodetool -h localhost -p 7199 version

bin\nodetool flush &bin\nodetool repair&bin\nodetool compact
bin\nodetool info&bin\nodetool cfstats drifty&bin\nodetool compactionstats
bin\nodetool info&bin\nodetool tpstats
bin\nodetool status
bin\nodetool info
bin\nodetool flush
bin\nodetool cleanup
bin\nodetool repair
bin\nodetool ompactionhistory
bin\nodetool drain
bin\nodetool disableautocompaction drifty
bin\nodetool enableautocompaction drifty

當要使用bin\cqlsh操作copy from/to csv檔時,必須調整cassandra.yaml和cqlsh.py加大數值

cassandra.yaml

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
< batch_size_warn_threshold_in_kb: 5
---
> batch_size_warn_threshold_in_kb: 5000
681c683
< batch_size_fail_threshold_in_kb: 50
---
> batch_size_fail_threshold_in_kb: 50000
731c733
< read_request_timeout_in_ms: 5000
---
> read_request_timeout_in_ms: 50000
733c735
< range_request_timeout_in_ms: 10000
---
> range_request_timeout_in_ms: 100000
735c737
< write_request_timeout_in_ms: 2000
---
> write_request_timeout_in_ms: 20000
737c739
< counter_write_request_timeout_in_ms: 5000
---
> counter_write_request_timeout_in_ms: 50000
746c748
< request_timeout_in_ms: 10000
---
> request_timeout_in_ms: 100000

cqlsh.py

1
2
3
4
5
import csv
import getpass

#avoid "field larger than field limit (131072)"
csv.field_size_limit(sys.maxsize)

log timezone

比較新版的cassandra使用logback。透過conf/logback.xml修改設定。
預設是沒有指定timezone,所以顯示的時間跟本地時間不一致。
修改方式很簡單,只要在conf/logback.xml裡的加上時區即可。

1
2
<pattern>%-5level [%thread] %date{ISO8601,Asia/Taipei} %F:%L - %msg%n</pattern>
<pattern>%-5level %date{HH:mm:ss.SSS,Asia/Taipei} %msg%n</pattern>

JVM crash

3.5
3.4
3.2.1
降到3.0.6後終於不再有JVM crash了
2.2.6 no crash

java options

1
-Duser.language=en -Duser.timezone=Asia/Taipei -Djavax.net.ssl.trustStore=d:/jssecacerts -Xverify:none^

-Dfile.encoding=utf-8不能用,不然console輸出的error msg會亂碼

1
-XX:+UseStringDeduplication -XX:+UseG1GC^

java8的G1GC到目前來看還不錯用。但xmx小於6G並不適合。

compaction tuning

  1. 可以說cassanda預設的設定值都是為cluster或高檔設備而存在的,對開發機使用很傷。常造成問題。
  2. cassandra.yaml裡改設定concurrent_compactor=1。預設值太大,會讓系統hang著。
  3. 使用cql的copy指令大批量的匯入資料前先下nodetool disableautocompaction {keyspace} ,減少匯資料時compact搶IO。匯完資料再enableautocompaction就好。
  4. 使用cql的copy指令大批量的匯入資料一定要設定with numprocesses=1。一般7200rpm碟磁可以跑到2500rows/s,不限制也頂多跑到4500rows/s,但IO很忙。預設的numprocesses是{機器core數-1},但disk跟不上時就很悲劇。

cqlsh很渣,無法處理\n換行字元

不像mysql的load data,用cqlsh操作copy from csv時,csv必需先跳脫\n成\\n不然會有問題。
所以匯出mysql資料給cqlsh匯入要使用replace(content,’\n’,’\\n’);並且程式中在取出資料後解除跳脫字元 replace(content,”\\n”,”\n”)。

如果是使用程式操作cassandra-driver就不用多做這個處理。完全是cqlsh渣,用python寫的無法良好處理換行字元。

cassandra3.5

quick start

1
2
bin/cassandra
bin/cqlsh

configuration

1
2
3
4
5
6
7
vi conf/logback.xml
vi conf/cassandra.yaml
#data_file_directories視資料量通當指定到比較大的磁碟上
data_file_directories: g:/var/lib/cassandra/data
saved_caches_directory: g:/var/lib/cassandra/saved_caches
#commitlog_directory可以放到比較快的SSD上
commitlog_directory: g:/var/lib/cassandra/commitlog

test drop/create keyspace/table, import data, count table, find data

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
28
29
30
31
32
33
34
35
36
37
38
39
#####create keyspace/table
# use system; drop keyspace test;
#CREATE KEYSPACE test WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 2 };
CREATE KEYSPACE test WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
#describe keyspaces; describe keyspace test;
use test;
create table test(id varchar primary key, value text)
with bloom_filter_fp_chance=1;
alter table test
with bloom_filter_fp_chance=1;
desc test.test;
insert into test(id,value)values('testid','testvalue');
select * from test.test;
delete from test where id='testid';
select * from test.test;
#default 0.01, use 1 to disable bloomfilter and save memory
create table content (id varchar primary key, content text)
with bloom_filter_fp_chance=1;
#default 0.01, use 1 to disable bloomfilter and save memory
alter table content
with bloom_filter_fp_chance=1;
#disable compression
alter table content WITH compression = { 'sstable_compression' : '' };
alter table content WITH compression = { 'sstable_compression' : 'LZ4Compressor' };
alter table content WITH compression = { 'sstable_compression' : 'DeflateCompressor'};
alter table content WITH compression = { 'sstable_compression' : 'DeflateCompressor', 'chunk_length_kb' : 64 };
select * from content;
~~select * from system.schema_keyspaces;~~
desc keyspaces;
desc keyspace test;
describe tables;
describe table content;

#####import from file
copy content(id,content ) from 'g:\t\test.content.data.csv';

#####
use test; select count(*) from content limit 2147483647;
select * from content where id='01435a9f57718a8080e44358b3ff060b';

#

insert into content (id,content) values(‘test’,’test中文許功蓋’);

#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#bin/nodetool flush [keyspace] [cfnames]
bin/nodetool flush test
bin/nodetool -h localhost -p 7199 flush
bin/nodetool -h localhost -p 7199 cfstats
bin/nodetool -h localhost -p 7199 status
bin/nodetool -h localhost -p 7199 gcstatus
bin/nodetool -h localhost -p 7199 cleanup
bin/nodetool -h localhost -p 7199 cleanupsnapshot
bin/nodetool -h localhost -p 7199 compact
bin/nodetool -h localhost -p 7199 compactionhistory
bin/nodetool -h localhost -p 7199 compactionstatus
bin/nodetool -h localhost -p 7199 describecluster
bin/nodetool -h localhost -p 7199 describering
bin/nodetool -h localhost -p 7199 info
bin/nodetool -h localhost -p 7199 join
bin/nodetool -h localhost -p 7199 netstats
bin/nodetool -h localhost -p 7199 repair
bin/nodetool -h localhost -p 7199 rebuild
bin/nodetool -h localhost -p 7199 ring
bin/nodetool -h localhost -p 7199 tpstats
bin/nodetool -h localhost -p 7199 version

bin\nodetool flush &bin\nodetool repair&bin\nodetool compact
bin\nodetool info&bin\nodetool cfstats drifty
bin\nodetool info&bin\nodetool tpstats
bin\nodetool status
bin\nodetool info
bin\nodetool flush
bin\nodetool cleanup
bin\nodetool repair
bin\nodetool compactstatus
bin\nodetool ompactionhistory
bin\nodetool info&bin\nodetool cfstats drifty
bin\nodetool drain

當要使用bin\cqlsh操作copy from/to csv檔時,必須調整cassandra.yaml和cqlsh.py

cassandra.yaml

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
< batch_size_warn_threshold_in_kb: 5
---
> batch_size_warn_threshold_in_kb: 5000
681c683
< batch_size_fail_threshold_in_kb: 50
---
> batch_size_fail_threshold_in_kb: 50000
731c733
< read_request_timeout_in_ms: 5000
---
> read_request_timeout_in_ms: 50000
733c735
< range_request_timeout_in_ms: 10000
---
> range_request_timeout_in_ms: 100000
735c737
< write_request_timeout_in_ms: 2000
---
> write_request_timeout_in_ms: 20000
737c739
< counter_write_request_timeout_in_ms: 5000
---
> counter_write_request_timeout_in_ms: 50000
746c748
< request_timeout_in_ms: 10000
---
> request_timeout_in_ms: 100000

cqlsh.py

1
2
3
4
5
import csv
import getpass

#avoid "field larger than field limit (131072)"
csv.field_size_limit(sys.maxsize)

log timezone

比較新版的cassandra使用logback。透過conf/logback.xml修改設定。
預設是沒有指定timezone,所以顯示的時間跟本地時間不致。
修改方式很簡單,只要在conf/logback.xml裡的加上時區資料即可。

1
2
<pattern>%-5level [%thread] %date{ISO8601,Asia/Taipei} %F:%L - %msg%n</pattern>
<pattern>%-5level %date{HH:mm:ss.SSS,Asia/Taipei} %msg%n</pattern>

python memo

@see python程式設計入門 -葉難

基本

保留字

and as assert break class continue def del elif else except exec finally for from global if import in is lambda nonlocal not or pass print raise return try while with yield None False True

弱型態

可以是int,long,float,str,bool,list,tuple。都是object。

強制指定型態

int(3)
long(123L)
float(3.14)
str(‘aaa’),str(3.14),str([1,2,3]),str([]),str(()),str(True),str()
bool(True),bool([]),bool(()),bool(‘’),bool(0),bool(0.0),bool(None)
list([0,1,2,3,4,’a’,’b’])
tuple((0,1,2,3,4,’a’,’b’))

字串用’或”都可以, 預設用’

以換行做為statement結尾。也可用分號結尾,合並多個statement。

list

從0開始
內容不需是同一種型態
list=[0,1,2,3,4,5,6]
list=[‘frank’,111,3222,[‘c’,’python’]]
list
list[0]
list[3]
list[3][1]
list[1]*list[2]
list[1]=999
list[1]
s=”wijefiwjeifj”
s=’iiu2iu3i5u3iu’
s

tuple; immutable list

()
t=(0,1,2,3,4,5,6,7)
t[0]
t=(‘zero’,1,2,22.33,’kk’,(‘final’,”FINAL”))
t[5]
t[5][1]

tuple注意事項

t[1]=333 #you got error to assign value on tuple
oneElementStr=(‘juststr not tuple’)
oneElementStr
oneElementTuple=(‘only1’ ,) #need comma in the end
oneElementTuple
t3=’asdfw’,’aaa’,’vvvv’ #simplify expression of tuple
t3

operator +-*/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
% 除法只取餘數
// 除法只取商
** 次方

>>> 17/3
5
>>> 17.0/3.0
5.666666666666667
>>>

>>> 'hello'+ ' '+ 'world' +'!'
'hello world!'
>>> 'hello'*3
'hellohellohello'
>>> [1,2,3]*3
[1, 2, 3, 1, 2, 3, 1, 2, 3]
>>> [1,2,3]+['a','b','c']
[1, 2, 3, 'a', 'b', 'c']

comparison operator < <= > >= != <> ==

in, not in for list/tuple

is, is not for reference check

logical comparator and, or, not

boolean True, False

False == () #False
False == [] #False
False == [‘0’] #False
False == [0] #False
False == (0,) #False
False == ‘0’ #False
False == 0 #True

False

False
None
0
‘’
[]
()

True

not False
‘0’
[0]
(0,)

assignment

a=b=c=3
b=4;c=5
x=y=z=[0,1,2,3,4]
x,y,z #自動組成tuple

serial assignment

(a,b,c)=(0,1,2)
a;b;c;
a,b,c=0,1,2
a,b=b,a #exchange a,b
a;b;c;
[a,b,c]=[9,8,7] #list或tuple寫法都可以
a;b;c;

star mark for only python3

x=[0,1,2,3,4,5]
a,*b,c=x
a,b,c #等於(0,[1,2,3,4],5)

+= -= = /= %= //= *= >>= <<= &= ^= |=

if/elif/else 使用:和tab做區塊包圍檢查

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
a,b,c=1,2,3
x=None;
if a<b:
if b<c:
x=c
else:
x=b
else:
if a<c:
x=c
else:
x=a
#多一個換行結束if操作

x
print x
print(x)
1
2
3
4
5
a,b,c=0,'',[]
if a and b and c:
print('all true')
else:
pass #do nothing for avoid error in else statement

while

1
2
3
4
5
6
i=1;x=0;
while i<100:
x+=i
i+=1

i,x

for

1
2
3
4
5
6
7
8
9
scores=[23,54,52,55,99]
total=0
n=0
for x in scores:
n+=1
total+=x

avg=total/n
avg,total,n
for char in str
1
2
3
4
5
6
7
s='hello world'
count=0
for x in s:
if x=='e':
count+=1

count
serial assignment for list/tuple in for
1
2
3
4
5
6
7
nameScores=(('banana',32,55),('apple',67,48),('orange',72,8)) #list/tuple都可以
highs=[]
for x,y,z in nameScores:
if y>30 and z>40:
highs+=[x,y,z]

highs

break/continue for while/for

function; def/return

1
2
3
def testfunction(param):
return 0
#多一個換行結束if操作
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
def sum(numbers,initial):
total=initial
for x in numbers:
total+=x
return total

sum((1,2,34,6,7),0)
sum([1,2,34,6,7],100)

#test return list/tuple
def avg(scores,initial=0):
n=0;total=initial;
for x in scores:
total +=x
n+=1
return (total,total/n)
#return total,total/n也行

avg((1,2,34,6,7))
avg([1,2,34,6,7],100)

scope: del, global

del強制變數gc
global在函數內強制使用全域變數

1
2
3
4
5
6
7
8
a=10 #什麼數值都無所謂
#del a #讓a變成未定義也不影響後面的global操作
def foo(n):
global a
a=100
return n+a

foo(5),a #105,100

內建函式

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
a=[0,1,2,3,4]
len(a)
sum(a) #python2.x必需用 sum(a,0)
sum(a,1000)
max(a),min(a)
abs(3),abs(-3),abs(-3.14159)
pow(2,5)
pow(333,0),pow(0,0)
pow(2,5,3) #2^5%3
round(3.14159265358979323846,2) #四捨五入到小數第二位
round(3.14159265358979323846) #四捨五入到小數第0位
divmod(123,11) #商,餘
divmod(123.2389,11) #商,餘 float操作也OK

all(([0,1],'aaa',True,3)) #True
all(([],'',False,0)) #False
all(([],'',False,0,4)) #False

any(([0,1],'aaa',True,3)) #True
any(([],'',False,0)) #False
any(([],'',False,0,4)) #True

a=1234
def f():pass

id(a) #uid
type(a),type(f) #type
callable(a),callable(f)


range(10) #從0到param-1的list
range(5,10) #從5到param-1的list
range(5,10,2) #從5到param-1的list, step=2
range(5,-12,-4) #向負數跳也OK

for i in range(len(a)): #i是索引值
a[i]=a[i]+100

a

a=3
print a,a,a

a=raw_input() #python2.x的console input, python3.x用input()
a
#python2.x版的input()等同於eval(raw_input())

module

寫mymodule.py檔,其中可定義變數/函式

1
2
3
4
5
6
7
import mymodule #這就可以引入mymodule.py裡定義的一切
x=mymodule.functionA(1,2,3,4)
y=mymodule.valueB
`````` bash
import mymodule as mm#這就可以引入mymodule.py裡定義的一切, module name改用alias name使用
x=mm.functionA(1,2,3,4)
y=mm.valueB

1
2
3
from mymodule import * #引入一切,使用時不需要加上mymodule.
x=.functionA(1,2,3,4)
y=valueB
1
2
3
from mymodule import functionA #引入一切,使用時只有指定的import功能不需要加上mymodule.
x=functionA(1,2,3,4)
y=mymodule.valueB

standard module

builtins
dir(builtins)
keyword
iskeyword
math
pi e log10 log sqrt sin ceil floor trunc …
random
seed random randint uniform shuffle choice …
sys
path
maxint
-sys.maxint-1

module name

name
future

python file name

.py
.py3
.pyc
.pyo

file encoding

-- encoding: utf-8 --
-- encoding: big5 --
-- encoding: ascii --
-- encoding: iso-8859-1 --

as script file

!/usr/bin/python

chmod +x ./hello.py
./hello.py

List Comprehensions

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
28
29
30
31
32
33
34
35
36
37
38
39
40
>>> S = [x**2 for x in range(10)]
>>> V = [2**i for i in range(13)]
>>> M = [x for x in S if x % 2 == 0]
>>> S;V;M;
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
[1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096]
[0, 4, 16, 36, 64]
>>> noprimes = [j for i in range(2, 8) for j in range(i*2, 50, i)]
>>> primes = [x for x in range(2, 50) if x not in noprimes]
>>> primes
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
>>> words = 'The quick brown fox jumps over the lazy dog'.split()
>>> words
['The', 'quick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog']
>>> stuff = [[w.upper(), w.lower(), len(w)] for w in words]
>>> for i in stuff:
... print i
...
['THE', 'the', 3]
['QUICK', 'quick', 5]
['BROWN', 'brown', 5]
['FOX', 'fox', 3]
['JUMPS', 'jumps', 5]
['OVER', 'over', 4]
['THE', 'the', 3]
['LAZY', 'lazy', 4]
['DOG', 'dog', 3]
>>> stuff = map(lambda w: [w.upper(), w.lower(), len(w)], words)
>>> for i in stuff:
... print i
...
['THE', 'the', 3]
['QUICK', 'quick', 5]
['BROWN', 'brown', 5]
['FOX', 'fox', 3]
['JUMPS', 'jumps', 5]
['OVER', 'over', 4]
['THE', 'the', 3]
['LAZY', 'lazy', 4]
['DOG', 'dog', 3]

數值型別

#

0b1101,0xaa,0o1234
bin(100),hex(100),oct(100)
11111111111111111L #凡超過int最大值的數都自動轉成無窮精確度的long型別
1e6
314159e-5
314159E-5
float(‘nan’),float(‘inf’),float(‘-inf’)
import math
math.isnan(float(‘nan’))
math.isinf(float(‘inf’))
math.isfinite(float(‘inf’)),math.isfinite(float(‘nan’)) #only python3.x

三元運算

x,y,z=1,2,3
x if y>0 else z
1
(x>0 and x) or z #等效三元運算
1
d=100;n=None
a=d if n==None else n
b=(n==None) and d or n
b1=(n==None and d) or n
b2= n==None and d or n
c=(n and d ) or n
a,b,b1,b2,c
(100, 100, 100, 100, None)

operator from/to function

list=[0,1,2]
list.len()
3
list.append(3)
list
[0, 1, 2, 3]

x=’good’;y=’bye’
x+y
‘goodbye’
x.add(y)
‘goodbye’
x=3;y=4
x+y
7
x.add(y)
7
x.add(y).sub(y.pow(2))
-9

type complex

type(complex())
complex(1)
complex(1,2)
complex(1+2j,3+4j)
complex(‘5-6j’)
complex(‘5 - 6j’) #error
complex()

z=4+5j;z
z.real #實部
z.imag #虛部
z==z.real+z.imag*1j
z.conjugate() #共軛複數

+ - / * pow abs == !=
座標系轉換

import cmath
abs(x) #絕對值;模
cmath.phase(x) #輻角;弧度
ct=cmath.polar(x) #模和輻角的tuple
cmath.rect(ct[0],ct[1]) #以模和輻角建立complex
cmath.sqrt(-1) #負數的平方根

#

import cmath
exp log log10 acos asin acosh asinh …

轉型

str()
repr()

十進位 Decimal

from decimal import *
Decimal
Decimal(0.1), Decimal(3.14)
Decimal(‘0.1’), Decimal(‘3.14’)
D=Decimal
a=D(‘2.33’);b=D(‘4.82’)
a+b

分數 Fraction

from fractions import
Fraction
Fraction(1,3) #1/3
F=Fraction
F(‘-1/3’)
a,b,c=F(‘1/3’),F(‘11/3’),F(‘5/12’)
a+b,b-c,c
a,a/b
abs(a-b),round(b)
gcd(64,48) #最大公因數

位元運算 ~ << >> & ^ |

#

callable()
isinstance(x , types.FunctionType)
isinstance(x, tuple)
dir()
dir(int)
dir(list)
a=3,list=[0,1,2,3]
a.class, list__class
type(a),type(list)

namespace

local enclosing global builtin

Sized, Container, Sequence, MutableSequence, Iterable, Iterator

list=[0, 1, 2, 3]
lit=iter(list)
lit


next(lit)
0
next(lit)
1
next(lit)
2
next(lit)
3
next(lit)
Traceback (most recent call last):
File ““, line 1, in
StopIteration

index, slice
is, is not, ==, !=, in, not in, +, , +=, =
len min max sum iter next slice range xrange reversed sorted zip enumerate
index count append del extend insert pop reverse sort copy deepcopy

#

list=[33,44,55]
itr=iter(list)
while True:
try:
x=next(itr)
print(x)
except StopIteration:
break

n=0
for i in list:
n+=i;i,n

n=0
for i in iter(list):
n+=i;i,n

n=0
for i in range(1,10+1):
n+=i;i,n

n=0
for i,v in enumerate(list):
i,v

ii=[3,2,1]
for i,v in zip(ii,list):
i,v

data=zip(ii,list)
sorted(data)
data

def k(x):return x[1];

sorted(data,key=k)

list comprehension

list=[0,1,2,3,4,5]
[x*x for x in list]

[str(x)+’‘+str(y)+’=’+str(xy) for x in range(2,9+1) for y in range(1,9+1)] #九九乘法

li0=[‘a’,’b’,’c’]
li1=[‘.jpg’,’.png’,’.bmp’]
[x+y for x in li0 if x!=’a’ for y in li1 if y!=’.jpg’]

string

\’
\”
\
\n
\r
\t #HT; tab
\v #VT
\a #bell
\b #backspace
\f #page
\xff #hex
\ooo #oct

‘’’附號用來合併多行

s=’’’abc def
ghi kkl mno
pqr\t\nstu
vwxyz’’’
s

raw r或R都可以

r’\‘
R’\‘
r’\”‘
R’\”‘

\標示下一行繼續

s=’abc\
def\
hij’
s

dict

d={}
d={‘name’:’John’,’name’:27} #同key會被取代
d={‘name’:’John’,’age’:27,’list’:[3,4,5]}
d[‘name’]
type(d)
dict(d)
type(dict(d))
keys=[‘name’,’age’,’job’]
values=[‘john’,33,’programmer’]
d2=dict(zip(keys,values));d2

d={‘a’:1,’b’:2,’c’:3}
for k in d:
k

for k in d.keys():
k

for v in d.values():
v

for k,v in d.items():
k,v

len del get setdefault keys values items

set

x={1,2,3,4,4,4,4};x
set(x);
set({1,2,3234,234,1,1,1,1})
set([2,3,2,2,2,2,2])

python

@see python程式設計入門 -葉難

基本

保留字

and as assert break class continue def del elif else except exec finally for from global if import in is lambda nonlocal not or pass print raise return try while with yield None False True

弱型態

可以是int,long,float,str,bool,list,tuple。都是object。

強制指定型態

int(3)
long(123L)
float(3.14)
str(‘aaa’),str(3.14),str([1,2,3]),str([]),str(()),str(True),str()
bool(True),bool([]),bool(()),bool(‘’),bool(0),bool(0.0),bool(None)
list([0,1,2,3,4,’a’,’b’])
tuple((0,1,2,3,4,’a’,’b’))

字串用’或”都可以, 預設用’

以換行做為statement結尾。也可用分號結尾,合並多個statement。

list

從0開始
內容不需是同一種型態
list=[0,1,2,3,4,5,6]
list=[‘frank’,111,3222,[‘c’,’python’]]
list
list[0]
list[3]
list[3][1]
list[1]*list[2]
list[1]=999
list[1]
s=”wijefiwjeifj”
s=’iiu2iu3i5u3iu’
s

tuple; immutable list

()
t=(0,1,2,3,4,5,6,7)
t[0]
t=(‘zero’,1,2,22.33,’kk’,(‘final’,”FINAL”))
t[5]
t[5][1]

tuple注意事項

t[1]=333 #you got error to assign value on tuple
oneElementStr=(‘juststr not tuple’)
oneElementStr
oneElementTuple=(‘only1’ ,) #need comma in the end
oneElementTuple
t3=’asdfw’,’aaa’,’vvvv’ #simplify expression of tuple
t3

operator +-*/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
% 除法只取餘數
// 除法只取商
** 次方

>>> 17/3
5
>>> 17.0/3.0
5.666666666666667
>>>

>>> 'hello'+ ' '+ 'world' +'!'
'hello world!'
>>> 'hello'*3
'hellohellohello'
>>> [1,2,3]*3
[1, 2, 3, 1, 2, 3, 1, 2, 3]
>>> [1,2,3]+['a','b','c']
[1, 2, 3, 'a', 'b', 'c']

comparison operator < <= > >= != <> ==

in, not in for list/tuple

is, is not for reference check

logical comparator and, or, not

boolean True, False

False == () #False
False == [] #False
False == [‘0’] #False
False == [0] #False
False == (0,) #False
False == ‘0’ #False
False == 0 #True

False

False
None
0
‘’
[]
()

True

not False
‘0’
[0]
(0,)

assignment

1
2
3
4
a=b=c=3
b=4;c=5
x=y=z=[0,1,2,3,4]
x,y,z #自動組成tuple

serial assignment

1
2
3
4
5
6
7
(a,b,c)=(0,1,2)
a;b;c;
a,b,c=0,1,2
a,b=b,a #exchange a,b
a;b;c;
[a,b,c]=[9,8,7] #list或tuple寫法都可以
a;b;c;
star mark for only python3
1
2
3
x=[0,1,2,3,4,5]
a,*b,c=x
a,b,c #等於(0,[1,2,3,4],5)

+= -= = /= %= //= *= >>= <<= &= ^= |=

if/elif/else 使用:和tab做區塊包圍檢查

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
a,b,c=1,2,3
x=None;
if a<b:
if b<c:
x=c
else:
x=b
else:
if a<c:
x=c
else:
x=a
#多一個換行結束if操作

x
print x
print(x)
1
2
3
4
5
a,b,c=0,'',[]
if a and b and c:
print('all true')
else:
pass #do nothing for avoid error in else statement

while

1
2
3
4
5
6
i=1;x=0;
while i<100:
x+=i
i+=1

i,x

for

1
2
3
4
5
6
7
8
9
scores=[23,54,52,55,99]
total=0
n=0
for x in scores:
n+=1
total+=x

avg=total/n
avg,total,n
for char in str
1
2
3
4
5
6
7
s='hello world'
count=0
for x in s:
if x=='e':
count+=1

count
serial assignment for list/tuple in for
1
2
3
4
5
6
7
nameScores=(('banana',32,55),('apple',67,48),('orange',72,8)) #list/tuple都可以
highs=[]
for x,y,z in nameScores:
if y>30 and z>40:
highs+=[x,y,z]

highs

break/continue for while/for

function; def/return

1
2
3
def testfunction(param):
return 0
#多一個換行結束if操作
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
def sum(numbers,initial):
total=initial
for x in numbers:
total+=x
return total

sum((1,2,34,6,7),0)
sum([1,2,34,6,7],100)

#test return list/tuple
def avg(scores,initial=0):
n=0;total=initial;
for x in scores:
total +=x
n+=1
return (total,total/n)
#return total,total/n也行

avg((1,2,34,6,7))
avg([1,2,34,6,7],100)

scope: del, global

del強制變數gc
global在函數內強制使用全域變數

1
2
3
4
5
6
7
8
a=10 #什麼數值都無所謂
#del a #讓a變成未定義也不影響後面的global操作
def foo(n):
global a
a=100
return n+a

foo(5),a #105,100

內建函式

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
a=[0,1,2,3,4]
len(a)
sum(a) #python2.x必需用 sum(a,0)
sum(a,1000)
max(a),min(a)
abs(3),abs(-3),abs(-3.14159)
pow(2,5)
pow(333,0),pow(0,0)
pow(2,5,3) #2^5%3
round(3.14159265358979323846,2) #四捨五入到小數第二位
round(3.14159265358979323846) #四捨五入到小數第0位
divmod(123,11) #商,餘
divmod(123.2389,11) #商,餘 float操作也OK

all(([0,1],'aaa',True,3)) #True
all(([],'',False,0)) #False
all(([],'',False,0,4)) #False

any(([0,1],'aaa',True,3)) #True
any(([],'',False,0)) #False
any(([],'',False,0,4)) #True

a=1234
def f():pass

id(a) #uid
type(a),type(f) #type
callable(a),callable(f)


range(10) #從0到param-1的list
range(5,10) #從5到param-1的list
range(5,10,2) #從5到param-1的list, step=2
range(5,-12,-4) #向負數跳也OK

for i in range(len(a)): #i是索引值
a[i]=a[i]+100

a

a=3
print a,a,a

a=raw_input() #python2.x的console input, python3.x用input()
a
#python2.x版的input()等同於eval(raw_input())

module

寫mymodule.py檔,其中可定義變數/函式

1
2
3
4
5
6
7
import mymodule #這就可以引入mymodule.py裡定義的一切
x=mymodule.functionA(1,2,3,4)
y=mymodule.valueB
`````` python
import mymodule as mm#這就可以引入mymodule.py裡定義的一切, module name改用alias name使用
x=mm.functionA(1,2,3,4)
y=mm.valueB

1
2
3
from mymodule import * #引入一切,使用時不需要加上mymodule.
x=.functionA(1,2,3,4)
y=valueB
1
2
3
from mymodule import functionA #引入一切,使用時只有指定的import功能不需要加上mymodule.
x=functionA(1,2,3,4)
y=mymodule.valueB

standard module

builtins
dir(builtins)
keyword
iskeyword
math
pi e log10 log sqrt sin ceil floor trunc …
random
seed random randint uniform shuffle choice …
sys
path
maxint
-sys.maxint-1

module name

name
future

python file name

.py
.py3
.pyc
.pyo

file encoding

-- encoding: utf-8 --
-- encoding: big5 --
-- encoding: ascii --
-- encoding: iso-8859-1 --

as script file

1
2
3
#!/usr/bin/python
chmod +x ./hello.py
./hello.py

List Comprehensions

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
28
29
30
31
32
33
34
35
36
37
38
39
40
>>> S = [x**2 for x in range(10)]
>>> V = [2**i for i in range(13)]
>>> M = [x for x in S if x % 2 == 0]
>>> S;V;M;
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
[1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096]
[0, 4, 16, 36, 64]
>>> noprimes = [j for i in range(2, 8) for j in range(i*2, 50, i)]
>>> primes = [x for x in range(2, 50) if x not in noprimes]
>>> primes
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
>>> words = 'The quick brown fox jumps over the lazy dog'.split()
>>> words
['The', 'quick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog']
>>> stuff = [[w.upper(), w.lower(), len(w)] for w in words]
>>> for i in stuff:
... print i
...
['THE', 'the', 3]
['QUICK', 'quick', 5]
['BROWN', 'brown', 5]
['FOX', 'fox', 3]
['JUMPS', 'jumps', 5]
['OVER', 'over', 4]
['THE', 'the', 3]
['LAZY', 'lazy', 4]
['DOG', 'dog', 3]
>>> stuff = map(lambda w: [w.upper(), w.lower(), len(w)], words)
>>> for i in stuff:
... print i
...
['THE', 'the', 3]
['QUICK', 'quick', 5]
['BROWN', 'brown', 5]
['FOX', 'fox', 3]
['JUMPS', 'jumps', 5]
['OVER', 'over', 4]
['THE', 'the', 3]
['LAZY', 'lazy', 4]
['DOG', 'dog', 3]

數值型別

0b1101,0xaa,0o1234
bin(100),hex(100),oct(100)
11111111111111111L #凡超過int最大值的數都自動轉成無窮精確度的long型別
1e6
314159e-5
314159E-5
float(‘nan’),float(‘inf’),float(‘-inf’)
import math
math.isnan(float(‘nan’))
math.isinf(float(‘inf’))
math.isfinite(float(‘inf’)),math.isfinite(float(‘nan’)) #only python3.x

三元運算

1
2
3
4
5
6
7
8
9
10
11
12
13
>>> x,y,z=1,2,3
>>> x if y>0 else z
1
>>> (x>0 and x) or z #等效三元運算
1
>>> d=100;n=None
>>> a=d if n==None else n
>>> b=(n==None) and d or n
>>> b1=(n==None and d) or n
>>> b2= n==None and d or n
>>> c=(n and d ) or n
>>> a,b,b1,b2,c
(100, 100, 100, 100, None)

operator from/to function

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
>>> list=[0,1,2]
>>> list.__len__()
3
>>> list.append(3)
>>> list
[0, 1, 2, 3]

>>> x='good';y='bye'
>>> x+y
'goodbye'
>>> x.__add__(y)
'goodbye'
>>> x=3;y=4
>>> x+y
7
>>> x.__add__(y)
7
>>> x.__add__(y).__sub__(y.__pow__(2))
-9

type complex

type(complex())
complex(1)
complex(1,2)
complex(1+2j,3+4j)
complex(‘5-6j’)
complex(‘5 - 6j’) #error
complex()

z=4+5j;z
z.real #實部
z.imag #虛部
z==z.real+z.imag*1j
z.conjugate() #共軛複數

1
+ - * / ** pow abs == !=
座標系轉換
1
2
3
4
5
6
7
8
import cmath
abs(x) #絕對值;模
cmath.phase(x) #輻角;弧度
ct=cmath.polar(x) #模和輻角的tuple
cmath.rect(ct[0],ct[1]) #以模和輻角建立complex
cmath.sqrt(-1) #負數的平方根
import cmath
exp log log10 acos asin acosh asinh ...

轉型

1
2
__str__()
__repr__()

十進位 Decimal

1
2
3
4
5
6
7
from decimal import *
Decimal
Decimal(0.1), Decimal(3.14)
Decimal('0.1'), Decimal('3.14')
D=Decimal
a=D('2.33');b=D('4.82')
a+b

分數 Fraction

1
2
3
4
5
6
7
8
9
from fractions import *
Fraction
Fraction(1,3) #1/3
F=Fraction
F('-1/3')
a,b,c=F('1/3'),F('11/3'),F('5/12')
a+b,b-c,c*a,a/b
abs(a-b),round(b)
gcd(64,48) #最大公因數

位元運算 ~ << >> & ^ |

#

callable()
isinstance(x , types.FunctionType)
isinstance(x, tuple)
dir()
dir(int)
dir(list)
a=3,list=[0,1,2,3]
a.class, list__class
type(a),type(list)

namespace

local enclosing global builtin

Sized, Container, Sequence, MutableSequence, Iterable, Iterator

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
>>> list=[0, 1, 2, 3]
>>> lit=iter(list)
>>> lit
<listiterator object at 0x02ADD1D0>
>>> next(lit)
0
>>> next(lit)
1
>>> next(lit)
2
>>> next(lit)
3
>>> next(lit)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration
index, slice
is, is not, ==, !=, in, not in, +, , +=, =
len min max sum iter next slice range xrange reversed sorted zip enumerate
index count append del extend insert pop reverse sort copy deepcopy

#

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
28
29
30
31
32
33
34
35
36
37
38
list=[33,44,55]
itr=iter(list)
while True:
try:
x=next(itr)
print(x)
except StopIteration:
break

n=0
for i in list:
n+=i;i,n

n=0
for i in iter(list):
n+=i;i,n

n=0
for i in range(1,10+1):
n+=i;i,n

n=0
for i,v in enumerate(list):
i,v


ii=[3,2,1]
for i,v in zip(ii,list):
i,v

data=zip(ii,list)
sorted(data)
data


def k(x):return x[1];

sorted(data,key=k)
list comprehension
1
2
3
4
5
6
7
8
list=[0,1,2,3,4,5]
[x*x for x in list]

[str(x)+'*'+str(y)+'='+str(x*y) for x in range(2,9+1) for y in range(1,9+1)] #九九乘法

li0=['a','b','c']
li1=['.jpg','.png','.bmp']
[x+y for x in li0 if x!='a' for y in li1 if y!='.jpg']
string

\’
\”
\
\n
\r
\t #HT; tab
\v #VT
\a #bell
\b #backspace
\f #page
\xff #hex
\ooo #oct

‘’’附號用來合併多行

s=’’’abc def
ghi kkl mno
pqr\t\nstu
vwxyz’’’
s

raw r或R都可以

r’\‘
R’\‘
r’\”‘
R’\”‘

\標示下一行繼續

s=’abc\
def\
hij’
s

dict

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
d={}
d={'name':'John','name':27} #同key會被取代
d={'name':'John','age':27,'list':[3,4,5]}
d['name']
type(d)
dict(d)
type(dict(d))
keys=['name','age','job']
values=['john',33,'programmer']
d2=dict(zip(keys,values));d2


d={'a':1,'b':2,'c':3}
for k in d:
k

for k in d.keys():
k

for v in d.values():
v

for k,v in d.items():
k,v

len del get setdefault keys values items

set

1
2
3
4
x={1,2,3,4,4,4,4};x
set(x);
set({1,2,3234,234,1,1,1,1})
set([2,3,2,2,2,2,2])

linux commands

telnet
login
exit
shutdown
reboot
&
&&
nohup
ps -aux
kill
cd
pwd
ls
cat
more
head
tail
mkdir
rmdir
rm
touch
cp
mv
ln
find
whereis
chmod
chgrp
chown
df -ha
du
dd
mount
umount
fdisk
mke2fs
mkfs
mkfs.ntfs
mkswap
fsck
fsck.netfs
fdformat
file
rpm
apt-get
su
sudo
clear
dmesg
groupadd
useradd
userdel
userconf
passwd
who=w
whoami
who am i
top
htop
free
quotacheck,edquote
compress
zip
unzip
gzip
tar
7z
ifconfig
route
netstat
hostname
ping
nslookup
talk
traceroute
mail
date
cal
grep
ftp
sftp
ncftp
scp
ssh
wget
curl
tcpdump
set
uname -a
lsb_release -a
setup
lilo
Xconfigurator
xf86config
startx
netconf
XF86Setup
makebootdisk
badblocks
sync
uptime
man
help
locate
whatis
at
crontab
echo
write
mesg
mesg y
mesg n
history
nmap
alias
bc
cmp
diff
ifconfig
ifup
ifdown
sort
vi
vim
joe
nano
pico
wc
lsmod
lspci
ip link
lshw
iostat
iotop
iftop
split
last
lastlog
pkill
iptables
tune2fs
dumpe2fs

nc
ab/wrk

CentOS 5/6 安裝 GNOME 與 KDE 桌面環境

最小安裝的CentOS,另外安裝desktop manager的操作。

安裝桌面環境

yum 提供 groupinstall 的方式來安裝套件組,可以下指令查看目前有哪些套件組:
yum grouplist | more

CentOS 5.x 與 6.x 套件組的名稱不太一樣,例如桌面環境套件:

CentOS 5.x:
GNOME: GNOME Desktop Environment
KDE: KDE (K Desktop Environment)
CentOS 6.x:
GNOME: Desktop
KDE: KDE Desktop

以下步驟以 CentOS 6.x 的套件組名稱來做安裝示范

  1. 安裝 XWindow
    yum -y groupinstall ‘X Window System’

  2. 安裝 GNOME 與 KDE (可擇一安裝)
    yum -y groupinstall ‘Desktop’
    yum -y groupinstall ‘KDE Desktop’

  3. 安裝中文語系套件 (非必要)
    yum -y groupinstall “Chinese Support”

  4. 如有安裝中文語系套件,要再修改預設語系
    vi /etc/sysconfig/i18n
    將 LANG=”en_US.UTF-8” 改為 LANG=”zh_TW.UTF-8” ,如果檔案是空白的,直接加入:
    LANG=”zh_TW.UTF-8”

  5. 設定開機直接進入桌面環境 (非必要)
    編輯: /etc/inittab,將 id:3:initdefault: 改為 id:5:initdefault:

  6. 重新開機
    reboot