顯示具有 Notes 標籤的文章。 顯示所有文章
顯示具有 Notes 標籤的文章。 顯示所有文章

2010年12月26日 星期日

幾個有趣的 Project 和文章

因為分頁開著放很久了,又沒時間去看,先紀錄下來,以後如果有空再...。

pep8:
pep8 is a tool to check your Python code against some of the style conventions in PEP 8.

archery
:
Archey is a system information tool written in Python.

psutil :
psutil is a module providing an interface for retrieving information on running processes and system utilization (CPU, memory) in a portable way by using Python, implementing many functionalities offered by command line tools like ps, top, kill, lsof and netstat.

shellinabox:
Shell In A Box implements a web server that can export arbitrary command line tools to a web based terminal emulator. This emulator is accessible to any JavaScript and CSS enabled web browser and does not require any additional browser plugins.

How to get your code into an open source project

2009年10月26日 星期一

Network basic concept

最近在設定 iptables , 要有一些基本知識,就翻了些網頁,順便做點筆記,以後忘掉時才有東西可查

Ref:鳥哥私房菜 - 網路基礎概念、Network Sorcery - IP、RFC791、酷學園 - TCP 與 UDP、Network Sorcery - TCP、RFC793




A Class :
0xxxxxxx.xxxxxxxx.xxxxxxxx.xxxxxxxx ==> NetI_D 的開頭是 0
|-Net-ID|-----------Host-ID-------|
B Class :
10xxxxxx.xxxxxxxx.xxxxxxxx.xxxxxxxx ==> NetI_D 的開頭是 10
|-----Net-ID-----|----Host-ID-----|
C Class :
110xxxxx.xxxxxxxx.xxxxxxxx.xxxxxxxx ==> NetI_D 的開頭是 110
|----------Net-ID---------|-Host-ID|

三種分級在十進位的表示:
A Class : 0.xx.xx.xx ~ 126.xx.xx.xx
B Class : 128.xx.xx.xx ~ 191.xx.xx.xx
C Class : 192.xx.xx.xx ~ 223.xx.xx.xx

Network : Host-ID all '0' , first IP in that that network
Broadcast : Host-ID all '1' , last IP in that that network
Netmask : Net-ID all '1' , Host-ID all '0'
Network / Netmask : Network / bits , bits = How many Net-ID bits

example.
a.
192.168.0.0 / 24
available ip -- 192.168.0.0 ~ 192.168.0.255
b.
192.168.0.128 / 25 is the same with 192.168.0.128/255.255.255.128
25 bits fo Net-ID , available ip -- 192.168.0.128 ~ 192.168.0.255

private IP
A Class:10.0.0.0 - 10.255.255.255
B Class:172.16.0.0 - 172.31.255.255
C Class:192.168.0.0 - 192.168.255.255

three-way handshake:
1.
Server is listening , Client sent TCP packet (SYN , seq = 1200)
# 1200 is the initial sequence number ,
# server expect the first data byte seq = 1200+1
# server also replies a sequence number to client
2.
Server replies packet ( SYN ,ACK, seq = 2340 ack = 1201 )
# Client will also expect server to sent data for seq = 2340+1
3.
Client replies packet (ACK , ack = 2341, seq = 1201 )

2009年10月19日 星期一

[Python] Slicing on sequences

今天在 comp.lang.python 的討論裡看到一篇 Reverse Iteration Through Integers
,提到 list[::-1] 的用法,就找了一下 python docs

Sequences also support slicing: a[i:j] selects all items with index k such that i <= k < j.

When used as an expression, a slice is a sequence of the same type.

This implies that the index set is renumbered so that it starts at 0.

Some sequences also support “extended slicing” with a third “step” parameter: a[i:j:k] selects all items of a with index x where x = i + n*k, n >= 0 and i <= x < j.



所以 a[::-1]  的 index X 會由 X = 0+1*(-1) = -1,X = 0+2*(-1) = -2 這樣慢慢往回跑

Test code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
a = 123450
print "a=",a,"\t type = ",type(a)
b = str(a)
print "b=",b,"\t type = ",type(b)
c = b[::-1]
print "c=",c,"\t type = ",type(c)
d = int(c)
print "d=",d,"\t type = ",type(d)