程序人生

撰写生活代码,等待编译美好人生
随笔 - 48, 文章 - 0, 评论 - 29, 引用 - 0
数据加载中……

2007年1月13日

Python为自身模块添加属性

试了好半天才始出来,几经曲折,所以写下来:

A模块:
1 import sys, os
2 selfMod = __import__(__name__)
3 setattr(selfMod, "field""value")


在B模块中调用
1 import A
2 print A.field
输出: value

模块A的这种写法与在模块A中直接写field = "value"的效果是一样的。这看起来似乎多余,但是在某些特殊的情况下可以用该方法动态设置当前模块的属性。



posted @ 2008-05-20 02:21 405 Studio 阅读(763) | 评论 (0)编辑 收藏

蔬菜沙拉

前几天跟朋友去吃了一次蔬菜沙拉。做的很精致,但并不合我的口味,但朋友很喜欢。
今天闲暇之际研究一下“沙拉”的来源:
google了一下"define:沙拉"

沙拉(香港称为沙律)通常是配菜,有时会作为一道主菜。 

不详细,在answers.com找了一下:

Originally derived from the Latin sal  for  salt, meaning something dipped into salt. Now normally a dish of uncooked vegetables; either a mixed salad or just one item (commonly lettuce or tomato). 
的确,我们吃的都是卷心菜(当时我以为卷心菜就是生菜 -_-|||)和小西红柿。

食物文化百科:
Although the ancient Greeks and Romans did not use the word "salad," they enjoyed a variety of dishes with raw vegetables dressed with vinegar, oil, and herbs. Pliny the Elder in Natural History, for instance, reported that salads (acetaria) were composed of those garden products that "needed no fire for cooking and saved fuel, and which were a resource to store and always ready" (Natural History, XIX, 58). They were easy to digest and were not calculated to overload the senses or stimulate the appetite.
...........
...........

最终,我在怀疑是不是中国凉拌传入西方之后变味了的结果。

posted @ 2007-12-05 01:43 405 Studio 阅读(413) | 评论 (1)编辑 收藏

感觉我是無賴

这种感觉不好。。

posted @ 2007-12-03 22:04 405 Studio 阅读(250) | 评论 (0)编辑 收藏

Windows DB2 Express-C 9 启动不了的原因

这几天想尝试一下 DB2 Express-C 9 ,找了个Windows的版本,几个"下一步"几个确定之后就装玩了. Reboot以下以为可以开始探索DB2 9了.没想到DB2却怎么都启不来.
折腾了几天才知道原来DB2 服务的启动还跟系统的一些其他服务有联系于是把在服务列表中把Server服务启动了再启动DB2, 启动成功!

posted @ 2007-08-04 17:05 405 Studio 阅读(691) | 评论 (1)编辑 收藏

Vim的16进制模式

今天有人问我VIM能不能像UE那样进行16进制编辑以,一时间没有答上来。执行了一下 :help hex才发现原来用 %!xxd 命令实现。为了方便,在vimrc上做了个map,实现了了<leader> + h切换文本模式和16进制模式,虽然简单,但是很有用 :)

"To hex modle
let s:hexModle = "N"
function! ToHexModle()
  if s:hexModle == "Y"
    %!xxd -r
    let s:hexModle = "N"
  else
    %!xxd
    let s:hexModle = "Y"
  endif
endfunction

map 
<leader>h :call ToHexModle()<cr>

在使用上面这段代码之前,你得确定你设置了<leader>且与你原来的键盘映射不冲突。

posted @ 2007-06-17 15:01 405 Studio 阅读(3839) | 评论 (0)编辑 收藏

Arch下安装Virtualbox

1.下载virtualbox:
当然,在官方下。
http://www.virtualbox.org/wiki/Downloads
这里我用的是 binaries 版本,由于我用Archlinux所以我选了 All distributions
2.安装
说明:以下操作均以root用户身份执行
a)修改下载的文件的属性为可执行:

#chmod +x VirtualBox_1.3.4_Linux_x86.run

VirtualBox_1.3.4_Linux_x86.run是安装文件

b)运行安装程序
#./VirtualBox_1.3.4_Linux_x86.run install 

install 后可以跟安装路径,默认会安装在/opt/VirtualBox-1.3.4/下

c)进入安装目录,并为所有用的so文件做链接到/usr/lib/

#cd /opt/VirtualBox-1.3.4/ #ln *.so /usr/lib/

d)把要运行virtualbox的用户加入vboxusers组

# gpasswd -a ausername vboxusers 

我运行这个命令后用groups命令发现ausername没有立刻被加到vbxousers组,这时你要重启以下。(我想应该有更好的办法,虽然我没有找到)
e)加载virtualbox 核型模块
#modprobe vboxdrv f)
3.运行virtualbox

# /opt/VirtualBox-1.3.4/VirtualBox


posted @ 2007-02-20 23:11 405 Studio 阅读(818) | 评论 (0)编辑 收藏

配置xinetd

     摘要: 今天打算把所有得网络服务都用xinetd来启动。找了几篇文章看了看。很快FTP,CVS,SSH都搞定了,然后配置Postgresql。死活起不来。于是去找xinetd的官方文档,这才发现原来很多的文章都没有很详细地说明type这个参数得作用。我误以为象ssh那样省去Type也没有问题。下面是官方文档对type得说明:
xinetd can manage 3 types of services :
...........  阅读全文

posted @ 2007-02-15 16:52 405 Studio 阅读(712) | 评论 (0)编辑 收藏

不错的鼠标增强软件 Strokeit

strokeIt_show.jpg 我向来喜欢在Firefox里用鼠标手势。今天找到一个软件,叫strokeit这软件可以让你在任何windows程序下使用鼠标手势。记得搞系统编程的时候我也曾想过做一个这样的东西。对于搞过Windows核心编程的人来说,应该觉得原理比较简单——鼠标钩子,但当我仔细试用之后,感觉作者做得非常用心。小小的软件提供了许多十分贴心的功能。而默认的设置也是经过作者用心配置的。更让人兴奋的是,这是一款完全免费的软件!!

posted @ 2007-01-14 13:41 405 Studio 阅读(389) | 评论 (0)编辑 收藏

用find实现批量压缩

一开始还以为要用for才才能做得了,今天仔细研究了一下find命令,只要一行就搞定了。
以下命令实现了对当前目录下的所有文件夹分别执行tar命令。

find . -type d -exec tar -vcf {}.tar {} \;


下面对这句东东解释一下:
  • "-type d" -type是find的一个参数 d表示文件夹。也就是说只搜寻当前目录下的文件夹
  • "-exec tar -vcf {}.tar {} \;"   该参数表示把搜索出的结果(文件名)给指定的命令进行操作。-exec 后跟的第一个参数应该是一个命令,这里是tar。{}是搜索的结果。另外要注意,命令必须以 \;结束(注意\前的空格)


posted @ 2007-01-13 20:27 405 Studio 阅读(920) | 评论 (0)编辑 收藏

Bash Shell脚本学习小结

     摘要: shell是很有趣的东西,今天从新学习了一下shell编程的一些基本知识,温故而知新。这里做个今天学习的总结  阅读全文

posted @ 2007-01-13 20:01 405 Studio 阅读(10039) | 评论 (3)编辑 收藏