2012年2月21日星期二

Python学习路线(针对具备一定编程经验者)

相比C,C++,JAVA等编程语言,P​ython​是易学的。但要想深入地理解​Python,并熟练地编写Python风格的Python代码。我想还是有一长段路程要走的。下面即是我的一点经验总结,主要是为了整理自己学习的思路。


1. 花1-2天的时间阅读一本好的Python入门书籍,并在亲手实践书中的代码。推荐入门书籍:《A byte of Python》(中文翻译《简明Python教程》)或《Practical Programming:An Introduction to Computer Science Using Python》(中文翻译《Python实践教程》)或者其他的比较薄的入门书籍。


2. 抛开书籍,用Python去写一切你想写的程序。这时最好的参考文档即为:1.Python命令解释器中的help(),dir()辅助方法;2.Python官网文档:http://docs.python.org/ 。遇到不清楚的地方就用这两个方法查,再不行就去google一下。


3. 两三个月之后,积累一点的代码量,再重新找本讲解比较详细的书,重新梳理一下自己对Python的理解,纠正自己实践中一些不好的方式。推荐书籍:《Beginning Python: From Novice to Professional》(中文翻译《Python基础教程》),《Learning Python》(中文翻译《Python学习手册》),《Dive into Python》,《Core Python Programming》等。另外,也应该在编码的过程中重复地去查阅Python标准函数库,标准库里已有模块实现的功能就不要自己实现。


4. 之后,根据实际需要,去了解使用一下Python的各个方面的函数库(比如http://docs.python.org/modindex.html中罗列出来的,以及matplotlib, numpy等用于科学计算,图形图像处理的),特别是诸多的Web框架(django, web2py, cherrypy, tornado等),可以先从简单的开始。如果是对Python的底层实现感兴趣,那么就该去看看Python源码,阅读一下《Python源码剖析》; 如果对文本处理感兴趣,可以阅读一下《Text processing in Python》等; 如果对网络感兴趣,可以阅读《Foundations of Python Network Programming》,尝试实现一个简单的web server ...


5. Python相关的开源函数库非常非常的多,各个方面的都有,所以学习者应该尝试着去用它们,了解它们,而不是啥都要自己来实现。因为Python擅长的就是快速开发,而且站在前人的肩膀上,我们才能站得更高,看得更远。当然如果你想加深自己对某个方面的理解,也可以尝试去实现一些简单的模块。


6. 总之一句话:学习Python的关键就是用!而且是要多用别人的。动手实践才是王道!那么多优秀的开源函数库不要浪费了!

2012年2月16日星期四

VNC简介

VNC(Vitual Network Computing) is a graphical desktop sharing system that uses the RFB protocol to remotely control another computer. It transmits the keyboard and mouse events from on computer to another, relaying the graphical screen updates back in the other direction, over a network.

VNC is platform-independent --- a VNC viewer on one operating system may connect to a VNC server on the same or any other operating system. There are clients and servers for many GUI-based operating system and for Java. Multiple clients may connect to a VNC server at the same time. Popular uses for this technology include remote technical support and accessing files on one's work computer from one's home computer, or vice versa.

A VNC system consists of a client, a server, and a communication protocol:

  • The VNC server is the program on the machine that shares its screen. The server passively allows the client to take control of it.
  • The VNC client(or viewer) is the program that watches, controls, and interacts with the server. The client controls the server.
  • The VNC protocol(RFB) is very simple, based on one graphic primitive from server to client("Put a rectangle of pixel data at the specified X,Y position") and event messages from client to server.
By default, RFB is not a secure protocol. While passwords are not sent in plain-text(as in telnet), cracking could prove successful if both the encryption key and encoded password are sniffed from a network. For this reason it is recommended that a password of at least 8 characters be used.

由于VNC系统是服务器-客户端模式的,所以先得在服务器(被控制的一方)上装上VNCserver,然后在客户端(主动控制的一方)上装上client(VNCviewer)。按照vncserver --help说明启动vncserver。服务器端有三个命令可以使用:vncconfig---配置命令,vncpasswd---设置client连接到服务器时需要的密码,vncserver启动一个server进程(对应一个Display No.),监听端口。

在服务器端的/root目录下会有个隐藏的文件夹.vnc,里面有加密过的密码文件passwd,每个vncserver进程的日志文件,以及配置文件xstartup。

服务器端启动vncserver后,即可在客户端启动vncviewer,在server一项中输入服务器的ip,后面跟一个:,以及一个Display No.,如果服务器端只启动了一个vncserver进程,那么就是1。然后直接回车,出现需要输入密码的登录框,输入服务器端设置的密码,然后直接回车即可。

2012年2月15日星期三

Linux命令习题


For each of the outputs listed below, find one sequence of commands connected by pipes that produces the output. For each problem, turn in the command sequence that you used to generate the requested output. (Do NOT turn in the output itself.)

1. A listing of all processes that you are currently running on the machine you are using, sorted by the command name in alphabetical order (i.e. a process running acroread should be listed before a process running bash). The output should consist only of the processes you are running, and nothing else (i.e. if you are running 6 processes, the output should only have 6 lines). 
ps -e --sort cmd
2. The number of words in the file /usr/share/dict/words (*) which start with the letter a.
[* Note: On some Unix/Linux systems, the dictionary has the filename /usr/dict/words]
cat /usr/share/words | grep ^a.* | wc -l
3. A "long" listing of the smallest 5 files in the /etc directory whose name contains the string ".conf", sorted by increasing file size. 
ls -lSrp | grep [^/]$ | grep [\.]conf$ | head -n 5
4. An executable file, named "echo.sh", with one sequence of commands to print hello world! on screen. 
(1) vim echo.sh and the content of echo.sh is echo hello,world! 
(2) chmod +x echo.sh
(3) ./echo.sh