Archive for the ‘工作相关’ Category.
April 7, 2010, 2:08 am
Virtualbox支持客户机和宿主机之间共享目录,但是根据版本不同,会有些问题。例如对于3.1.x版本,windows XP host和Debian guest组合下,VBox自己的共享目录(写入)性能极差甚至报错(本人遇到)。其实,在客户机和宿主机之间共享文件的还有一些其他方式,例如可以通过ftp或samba,二者都支持所有操作系统下的共享,但是相比之下samba更具优点,因为在Windows和Linux下都可以把Samba共享目录映射为本地磁盘目录。
先来看Linux访问Windows共享目录的情况。这比较容易,因为Windows上共享文件十分方便,可以通过点击右键实现文件夹共享。在Linux客户端,只要使用smbclient或者smbmount命令即可以实现远程共享目录的访问和映射。具体步骤包括:
1. 在Windows机器上选择文件夹,点击属性-》共享,指定共享名称和权限(是否可写)
2. 在Linux客户机上安装smbclient,然后执行smbclient -L ip_of_win_server来查看服务器所有共享资源。
3. 链接到共享文件夹,smbclient //ip_of_win_server/sharename -U username来连接,如果成功则会出现smb提示符可以使用samba client的命令操作远程目录。(默认需要Windows用户密码)或者使用sudo smbmount //ip_of_win_server/sharename local_path -o uid=your_user_name gid=your_group_name 来映射磁盘目录。
Continue reading ‘通过Samba在VirtualBox的guest和host间共享目录’ »
April 6, 2010, 5:43 pm
1. Change the default keyboard shortcuts to ctrl+c and ctrl+v. They are more common shortcuts on most OS.
2. Highlighting texts and Middle mouse button clicking will do copy/paste. These are similar to the operation in PuTTY where right mouse button click is used.
April 2, 2010, 12:34 am

目前全球有约10亿台计算机,每台按100Wh实际功率计算,总功率为1亿千瓦时。也就是说每小时耗电量为1亿千瓦。按计算机一天工作10小时计算,一天全球消耗总电量为10亿千瓦时。世界超大型水电站(如三峡电站)在汛期全部机组开动发电量不过4亿千瓦时(参见)。意味着我们需要2-3个这样的超大水电站全负荷供电才能满足基本需求。我们知道,建设一个这样的电站要耗费数以亿计的金钱和数十年的人工。但是,如果作为程序员,往往可以轻易地提高编码质量和运行效率以达到节省计算时间的目的,变相地节约了宝贵的能源,有利于保护地球环境。我觉得如果所有程序员都朝这个方向努力,每天节省一个三峡电站的电量是完全可能的。
March 30, 2010, 11:23 pm
1. apt-get install mpich2 (remove other implementation to prevent trouble)
2. create .mpd.conf file under home dir ~/ , add a line “password=qwert” (replace qwert with any other texts)
3. create a hostfile or machine file (e.g. mpd.hosts) with node names listed one per line. (this file can be in any folder)
4. start mpd. There is a script shipped with mpich2 “mpdboot”. It accept some options. “mpdboot -f mpd.hosts -n #” with #<= number of nodes listed in mpd.hosts file. This command will start mpd on all the nodes if ssh or rsh is set correctly (without password).
5 use mpdtrace to verify the node names (nodes having been added to the mpd ring, ready to be used in the following mpirun calls).
6 mpirun -np N -host node1,node2 ./program (it’s not necessary to use all the nodes in the ring, but some of them is fine)
March 22, 2010, 7:54 pm
By default Notepad2 add a .txt extension to the file name when you save a newly created file. For files already having extensions, this will not be done. However, this is sometimes annoying if you often create files which do not use txt as extension although they are actually plain text files. I think this is almost a daily work for programmers. To cancel this feature, there are two ways. First, when you save the newly created file, simply add quote symbols around the file name like “new_file”, then the file will be save without an extension or with any extension you give. This trick also works for the Windows Notepad program. Another hack is to modify notepad2.ini, there you can create a new section (if it’s not there already) named “[settings2]“. The settings given in this section will override the default behavior. Then add an entry “DefaultExtension=”, yeah just leave nothing behind the equal sign, no suffix will be appended automatically then. There are more options for the customized section, see here.
No doubt, Notepad2 should be a must-have replacement on Windows.
March 22, 2010, 12:58 pm
经常在C++程序中加入中文注释,但是如果使用不同的编辑器,编码识别或转换不当,会导致非ASCII字符乱码。
考虑到目前绝大多数编辑器都支持unicode编码(UTF-8)的源文件,我觉得一个稳妥的方式是把自己的代码都保存为unicode(UTF-8)。把原来的ACSII编码的文件转换为unicode网上有一些批量转换工具。值得一提的是众多文本编辑器中只发现EditPlus可以做批量转换,其它编辑器如Notepad++都只能一个文件一个文件地转换(知道如何批量操作的朋友请给些提示?)。VS也可以选择保存文件时的编码格式(在高级保存选项中设置)。还有一个要注意的地方是unicode≠UTF-8,在这点上我以前没有注意,(这里的一篇博文说清楚了这两种编码间的异同,主要区别是unicode固定使用四字节编码所有语言,而UTF-8是可变长度的编码,所以并不一样。)
通过试验得知,VC++和Intel的编译器均支持直接编译带有BOM的UTF-8源文件,但是gcc却不支持。事实上gcc和iconv都不支持读取BOM,但是对于没有BOM的UTF-8编码文件却可以编译。因此,对于跨平台的程序,如果想同时使用VC++和gcc来编译有BOM或无BOM的UTF-8源文件都存在兼容问题。(关于BOM (Byte order mark),wikipedia上有所讨论。)
Continue reading ‘用VC和gcc同时编译unicode编码的c++源程序’ »
March 15, 2010, 1:55 pm
VS中编译有时很费时间,如果有声音提示编译结果会比较方便,这样就不用总是查看输出窗口了。根据这篇文章,VS声音提示并不在VS软件设置中,而是在系统的“控制面板”中。打开“声音和音频设备”点击“声音”选项卡,在“程序事件”列表下找到“Microsoft Visual Studio”,就可以为编译成功、编译失败和取消编译等事件指定声音了。
我的设置是:
编译成功 — notify.wav
编译失败 — Windows XP Critical Stop.wav
到达断点 — Windows Navigation Start.wav
March 15, 2010, 12:43 pm
呵呵,最近有幸结识了一位傲慢且无知的俄罗斯女人。她看人的眼神绝似沙皇接见群臣,居高临下且无可判断焦距。但其实我知道她的无知也是超一流的。:)全当路过吧!
March 11, 2010, 11:57 pm
某些VS的Addins会导致程序异常缓慢或出错,一个小技巧是在启动VS的时候提前按住左边的shift键,即可禁止加载所有插件。
March 10, 2010, 7:07 pm
An alternative and better ways is to use the ‘distance’, ‘angle’ and ‘dihedral’ commands of ‘cmd’ object. Note not using ‘get_distance’, ‘get_angle’ and ‘get_dihedral’, they are for different purpose. The syntax is e.g. ‘dihedral dih_obj_name, id 1, id 2, id 3, id4’, i.e. giving an object name and four atom selections. (In this example, we use atom IDs for atom selections. Other syntax for atom selection should work too.) Using this method, the measurement will be automatically updated while playing the movie