Archive for the ‘编程’ Category.

PiCloud 基于Python的云计算平台

PiCloud frontpange

PiCould


Continue reading ‘PiCloud 基于Python的云计算平台’ »

Print directory tree on Windows and Linux using tree, sed, awk or Python

Windows: there is ‘tree.com‘ command showing the directory structure.
http://chxkyy.javaeye.com/blog/213864

Linux: there is a ‘tree‘ program for Linux and also available on some Linux distributions, such as Debian. (apt-get install tree)
http://www.debian-administration.org/article/Commands_you_might_have_missed_tree

Continue reading ‘Print directory tree on Windows and Linux using tree, sed, awk or Python’ »

Formlayout – an user-friendly way to interact

The online document is very simple but maybe too simple. It shows how to create a basic dialog WITHOUT tab, but formlayout in fact can do more, like building a tabbed dialog shown in the picture.

Continue reading ‘Formlayout – an user-friendly way to interact’ »

Bash: exit codes for background jobs

Useful commands:

  • wait <pid>: wait the background job with specified pid to be finished and return the exit code ( hint: stored in $? )
  • jobs -p: list the pids of all the background jobs (hint: use for statement of bash to loop over each process)
  • ( sleep 30s; /bin/false ) & : generate a background testing job with a error exit code

First, submit all the background jobs, no matter you use loop or line by line in a script.
Next, get the PIDs of the background jobs. After submitting EACH job, the PID of that job is in $!, which can be store to any user defined variable for later use.
Last, check the exit codes. You can either check the exit code of each job one by one or calculate the accumulative exit code. To check them one by one, just call wait command for each PID stored in previous step and check the value of $?; to check them cumulatively, see this post. (the trick is the sum of exit codes for all jobs should be zero if all jobs are finished successfully, or the sum must be non-zero)

重定向 Bash “time” 命令的输出

bash下time是一个很有用的命令,它可以为一段脚本或一个程序的执行计时,这通常在粗略比较程序执行效率的时候很方便。但是你会发现,time命令输出的时间文字不能被简单地重定向,例如重定向至一个文本文件,只能显示在屏幕上,这对于非交互计时很不方便。例如:

time command > file.txt

Continue reading ‘重定向 Bash “time” 命令的输出’ »

O3D and missing atlbase.h

Followed the installation instruction given by O3D, I could not compile it still. The compiler complaint a missing “atlbase.h”. According to this link http://benjamin.smedbergs.us/blog/tag/atlbaseh/ , this header file is not available because I have just VS2008 Express version installed. And this file is not included in the Windows 2008 SDK. Apparently, Google guys assumed people should have VS professional version and SDK installed.:) But I’m not that rich yet. Looking for a solution!

update: got a VC++ 2008 pro, the problem is solved.

Equivalent of “which” in Windows Command Shell Pankaj Kumars Weblog

如果想要知道一个程序或命令在Windows操作系统上的全路径,请使用下面这个脚本,它和Linux的which命令一样。

Equivalent of “which” in Windows Command Shell Pankaj Kumars Weblog.

这个脚本的核心语句是 set fullpath=%~$PATH:1, 这是一个DOS批处理命令的modifier的特殊用法,会自动在环境变量中检索参数1并返回第一找到的结果,如果没找到则返回空字符串。(参见:http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/percent.mspx?mfr=true

Continue reading ‘Equivalent of “which” in Windows Command Shell Pankaj Kumars Weblog’ »

lammps扩展命名冲突

曾经写过一些lammps的扩展,可是在最近的lammps更新中,有些类的命名和官方Molecule模块新加入的一些类有冲突。无奈这里不讲先来后到,谁让人家是官方发布的呢。看来以后要注意命名空间的使用了。不过说实话也感觉有些自由软件的作者有些“霸道”,他们的函数和类名称不加什么特殊的关键词,而是使用很常用的名字,明白着就是让别人让路嘛。只是笑谈,还是自己注意才对。

逆向切分由Python zip函数合并的列表

Unzip a Python list.

This is cool!

Suppose that you have a list with tuples as the member.

1
>>> test = [('x',1), ('y',2), ('z',3)]

Continue reading ‘逆向切分由Python zip函数合并的列表’ »

IPython的彩色显示

无论刚安装完IPython还是Engthought的套装,IPython默认的命令行上没有彩色显示。原因是IPython接受一些命令行参数,而默认安装后“colors”和“color-info”这两个magic函数并没有被调用。下面我们看怎样打开彩色显示:

1. 下载pyreadline, Windows上的命令行彩色显示需要这个模块。

Continue reading ‘IPython的彩色显示’ »