Python笔记

inheritance search occurs only on attribute reference, not assignment: assigning to an object’s attribute always changes that object, and no other. (Unless the attribute assignment operation has been redefined by a class with the __setattr__ operator overloading method to do something unique.)

Don’t code C in Python. A note to C/C++ programmers: you don’t need to type parentheses around tests in if and while headers (e.g., if (X==1):); you can if you like (any expression can be enclosed in parentheses), but they are fully superfluous in this context. Also, do not terminate all your statements with a semicolon; it’s technically legal to do this in Python as well, but is totally useless, unless you’re placing more than one statement on a single line (the end of a line normally terminates a statement). And remember, don’t embed assignment statements in while loop tests, and don’t use { } around blocks (indent your nested code blocks consistently instead).

Don’t expect results from functions that change objects in-place . In-place change operations like the list.append( ) and list.sort( ) methods of Chapter 6 do not return a value (other than None); call them without assigning the result. It’s not uncommon for beginners to say something like mylist=mylist.append(X) to try to get the result of an append; instead, this assigns mylist to None, rather than the modified list (in fact, you’ll lose a reference to the list altogether).

–Learning Python, 2ed Edition

20060311冲浪纪念

http://mrl.nyu.edu/~jhan/ftirtouch/index.html
超酷的触摸屏技术,这种时候未来世界好像就不远了。

http://www.sunbelt-software.com/stu/iraq/sandstorm.htm
看看伊拉克的沙尘暴~ 在北京生活其实也没什么

http://www.thekidshalloffame.com/
The Kids Hall of Fame,致力于发现、宣传,小于20岁的杰出青少年的网站

http://www.artakiane.com/
11岁的天才少女。她的诗歌和绘画
“I have been blessed by God. And if I’m blessed, there is one reason and one reason only, and that is to help others. ——Akiane”

http://www.pipesnetwork.com/blog/archive/2006_03_03.php
稀奇古怪的google入口,google fan不应错过的。。。

动能原理笔记(1)

多头行情对超卖形态及其敏感,应寻找确认价格上升的信号买入;但多头行情对超买形态缺乏敏感,超买往往带来小幅下跌或一段横盘。

空头行情与之类似;

而无论长期趋势还是中期趋势,趋势的成熟程度往往会影响摆荡指标可能达到的极限水平

看了《勇往直前》

今晚看了《勇往直前》。最怕看这种完全不知道结局会怎样的电影,可是又丝毫 抵挡不了一种为之兴奋和战栗的感觉。

男人的软弱,从接触女人身体的那一刻就已经开始。Cahit的手指顺着滑下Sibel的鼻梁,这一刻我顿时想起了《芳芳》里面亚历在沙滩上为她涂防晒霜的那一幕。女人啊女人,世界真的因为你们而变得美好!

Technorati : , ,

关于“镜子中的物体是左右颠倒,而非上下颠倒”的一些想法

听同学提到这样一个问题:为什么镜子中的物体是左右颠倒,而不是上下颠倒呢?花了一个中午的时间仔细考虑了一下,自以为大致是把这个问题想清楚了。出于好奇,顺手google了一把,发现关于这个问题的讨论并不多。即便是网上存在的一些讨论,也只是简单地解释了一下,并没有深入下去。所以在这里说一下我的想法,以供参考。

这个问题据说是微软的一道面试题,另有一说是剑桥大学对新生的面试题。无论是真是假,至少在某种程度说明了这是一个相当“特别”的问题。而它之所以特别,其实就在于它的似是而非。“颠倒左右却不能颠倒上下”这个命题,第一印象感觉是对的,也符合我们日常的生活经验。但是细一想来又有很多的漏洞。其实这恰恰是这一类命题的价值所在,看似矛盾,说不通的事情,可能是命题本身的逻辑存在问题,也可能恰好揭示我们的习惯逻辑中不合理之处。爱因斯坦说,“No problem can be solved from the same level of consciousness that created it.”对此,我深表赞同。

要说清楚这个问题,当然还得从问题本身说起。“颠倒”一词本身是有误导性的。其实我们不难发现,镜子里的人和真实的人是完美对称的。回顾一下我们所熟悉的初中数学概念。一条线l1与另一条线l2关于x轴对称,就意味着,做任意一条与x轴垂直的直线,该线与l1、l2的两个交点到x轴的距离都相等。这是平面内图形关于线对称的情形。而照镜子其实就是三维立体图形关于平面做对称。从这个定义来看,镜子根本就不存在什么颠倒的问题。头和头的镜像对称,脚和脚的镜像对称,左手和左手的镜像对称,右手和右手的镜像对称。做任意一条和镜子平面垂直的线,它和物、像的两个交点到镜平面的距离都是相等的,也就说关于镜平面是对称的。

说到这里也就解释这个问题“而非”的一面,那么它又为什么“似是”呢?提问者(或者问题的设计者)其实想问的是:为什么镜子里的那个人跟真人比起来,看起来会是反的呢?为什么你的左手会是镜子里那个人的右手呢?为什么你的头不是镜子里那个人的脚呢?

我想,这个问题还是得从平面内曲线关于线对称说起。G.Gamov(伽莫夫)在他的名著《从一到无穷大》为了解释弯曲空间这个概念,提出了一种假想的二维扁片生物。一头平面内的侧身驴,有向左和向右两种。尽管它们在形状上完全相似,但是一头面向右的侧身驴无论在平面内怎样运动,都无法变成向左的侧身驴,除非我们把它拿起来在三维空间翻个身再放回去。Gamov在书中也提到一种左侧身驴和右侧身驴相互转化的可能,那就是在发生了扭曲的莫比乌斯面(Möbius Strip)上。但是如果一头左侧身驴没能幸运地找到莫比乌斯面的入口,它仍然有可能观察到和它相反的右侧身驴的模样。答案很简单,看一面镜子!当然了,对于二维扁片生物来说,它的镜子是一条线,也就是之前提到的那根x对称轴。而对于我们生活在三维空间的人来说,同样存在形状完全相似,却“永远无法”(假如不通过黑洞这样连接三维世界和四维世界的通道的话)相互转化。但万幸的是,我们有镜子!镜子里的像,左手系与右手系和真实的物体是完全相反的。也许有一天人类能够克服四维空间,实现了瓦普跳跃飞行。那么当一个人重返三维空间的时候,他就变成旅行之前他在镜子里的模样了!

当我想到这一点的时候,突然对镜子有了莫名的敬畏感。面对来自另一个空间的自己的模样,难道不是很神奇么?原来我们每天都会做如此不平凡的一件事:面对另一个自己刷牙、洗脸。:-p

那么这一切究竟是怎么发生的呢?我的猜测是这样的:二维图形关于线对称,其本质是将两个二维图形映射到一维空间(线)上,并在映射点两两对等。我们也可以认为是二维图形映射到一维空间,并根据映射信息重建二维图形的过程。在这个映射的过程中我们损失了一个维度的信息,并在重建中根据“对称”的原理补充了该信息并重建二维图形,得到一个相似却绝不相同的像。三维物体关于平面对称也是一样,在映射到镜子平面上损失了一个的信息(从三维到二维)。关于镜子平面重建的像已经补充了失去的信息,但是根据“对称”,这是一个相似却并不相同的像。而损失的这个维度,其实就是三维世界里和镜子平面相垂直的一个纬度。

最后还想简单感慨几句,科普其实有它丰富的内涵,并不像宣传科学知识那么简单。就像信仰远比宗教一词内涵丰富一样。我以为,科普应该更多地是一种理性精神和探索态度的介绍和传达。我也是偶然的机会读到了Gamov的《物理世界奇遇记》,一发不可收拾,从没想到相对论可以用这么简单的道理说清楚。之后就找了Gamov的《从一到无穷大》来读。再然后就发现,这方面值得一读的书其实还有很多。比如马丁·加德纳的《从惊讶到思考》,比如阿西莫夫最新科学指南,比如R.道金斯的《自私的基因》,比如蕾切尔·卡逊的《寂静的春天》……

最后推荐一下三思科学网(oursci.org),上面有不少科普文章和书籍,上面几本书的链接也都来自那里。

本来想贴几张图说的清楚一点,实在麻烦,也就作罢。

Linkers and Loaders笔记

linkers:

  • address binding, assigning relativeaddresses within each program
  • name management
  • lay out storageand assign the addresses both for the subprograms and the commonblocks
  • deal with object code libraries
  • overlays, a technique that let programmers arrange for different parts of a program to share the same memory(虚拟内存某种程度上抵消了对overlay技术的需要)

loader:

  • doing a final relocation step to assign actual addresses(现代的hardware relocation技术)
No tags for this post.

Subversion笔记

在dreamhost的主机上配置subversion
http://wiki.dreamhost.com/index.php/Subversion

通过SSH和TortoiseSVN访问subversion服务器
http://tortoisesvn.sourceforge.net/?q=node/5

在Linux/Unix服务器上生成SSH密钥
cd ~ssh-keygen -b 1024 -t rsa -N SomeLongTextForPassphrase -f rsakeymkdir .ssh
mv rsakey.pub .ssh/authorized_keys
chmod 700 .ssh
chmod 600 .ssh/authorized_keys
最后仍需通过puttygen进行格式转换。(通过putty工具包中的pageant,配置authentication agent认证代理,putty会自动从pageant取得认证密钥)

最后通过svn+ssh://mysiteSSH/home/myusername/svn/myproject访问服务器。其中mysiteSSH为服务器域名或putty中存储的session名;

For overnight checkouts
screen
svn co &> ~/log_co &
^ad

《使用Subversion进行版本控制》,O’Reilly
http://svnbook.red-bean.com/
SVN使用技巧
http://xyzboard.com/?q=node/110

subversion中的关键字替换
http://svnbook.red-bean.com/en/1.0/ch07s02.html
$Date$
$Rev$
$Author$
$URL$
$Id$
svn propset svn:keywords “LastChangedDate Author” weather.txt
svn propedit svn:ignore somedir
find ./ -name \*.tcl xargs svn propset svn:keywords “Date Author Id”

subversion客户端配置文件
### Section for configuring miscelleneous Subversion options.
[miscellany]
### Set global-ignores to a set of whitespace-delimited globs
### which Subversion will ignore in its `status’ output.
global-ignores = *.o *.lo *.la #*# .*.rej *.rej .*~ *~ .#*

enable-auto-props = yes
[auto-props]
*.c = svn:keywords=Date Author Id
*.cc = svn:keywords=Date Author Id
*.cpp = svn:keywords=Date Author Id
*.py = svn:keywords=Date Author Id
*.tcl = svn:keywords=Date Author Id

库的生成和使用

库的生成
========
ar cqs libtest.a test.o
ar r libtest.a test.o

gcc -c -fPIC -o test.o test.c
gcc -shared -Wl,soname,libtest.so.1.0 test.o

ar
==
operations:
d Delete modules from the archive.
q Quick append; Historically, add the files member… to the end of archive, without checking for
replacement.
r Insert the files member… into archive (with replacement).
t Display a table listing the contents of archive.
x Extract members (named member) from the archive.

modifiers:
a Add new files after an existing member of the archive.
b Add new files before an existing member of the archive.
s Write an object-file index into the archive, or update an existing one, even if no other change is
made to the archive.

Link Option
===========
-Bdynamic
-dy
-call_shared
Link against dynamic libraries. Only meaningful on platforms for which shared libraries are
supported.

-Bstatic
-dn
-non_shared
-static
Do not link against shared libraries. Only meaningful on platforms for which shared
libraries are supported.

Code Generation
===============
-fpic
Generate position-independent code (PIC) suitable for use in a shared library, if supported for the
target machine. Such code accesses all constant addresses through a global offset table (GOT). The
dynamic loader resolves the GOT entries when the program starts (the dynamic loader is not part of
GCC; it is part of the operating system). If the GOT size for the linked executable exceeds a
machine-specific maximum size, you get an error message from the linker indicating that -fpic does
not work; in that case, recompile with -fPIC instead. (These maximums are 8k on the SPARC and 32k on
the m68k and RS/6000. The 386 has no such limit.)

Position-independent code requires special support, and therefore works only on certain machines.
For the 386, GCC supports PIC for System V but not for the Sun 386i. Code generated for the IBM
RS/6000 is always position-independent.

-fPIC
If supported for the target machine, emit position-independent code, suitable for dynamic linking and
avoiding any limit on the size of the global offset table. This option makes a difference on the
m68k and the SPARC.

Position-independent code requires special support, and therefore works only on certain machines.

Reference
=========
http://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html
http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html

LoopDevice笔记

#insmod loop.o
dd if=/dev/zero of=/tmp/fsfile bs=1k count=4096
#mknod /dev/loop0 b 7 0
losetup /dev/loop0 /tmp/fsfile
mke2fs /dev/loop0 4096
mount -t ext2 /dev/loop0 /mnt
umount /dev/loop0
losetup -d /dev/loop0
#rmmod loop

mke2fs -m 0 -i 2000 /dev/loop0

mount -o loop -t ext2 /tmp/fsfile /mnt

dd if=/dev/loop0 bs=1k gzip -v > rhat2.img

fdisk -lu /dev/loop0
losetup -o 32256 /dev/loop0 image.dd
# 32256 = sector 64 * 512 bytes

# mount -o loop,offset=32256 image.dd /mnt/

注意区分访问硬盘镜像文件的不同方式:

1. 硬盘无分区,即创建时仅做了格式化
losetup /dev/loop0 hdisk.img
mke2fs /dev/loop0
mount -o loop hdisk.img /mnt/loopdevice/
在操作系统中挂载/dev/hdb

2.硬盘创建了分区
fdisk中看到的信息
Command (m for help): x

Expert command (m for help): p

Disk /dev/loop0: 255 heads, 63 sectors, 2 cylinders

Nr AF Hd Sec Cyl Hd Sec Cyl Start Size ID
1 00 1 1 0 254 63 1 63 32067 83 <– start = 63 2 00 0 0 0 0 0 0 0 0 00 3 00 0 0 0 0 0 0 0 0 00 4 00 0 0 0 0 0 0 0 0 00 第一个分区的起始偏移63*512 = 32256

之后可用mount -o loop,offset=32256 hdisk.img /mnt/loopdevice/
或 losetup -o 32256 /dev/loop0 hdisk.img挂载该分区

操作系统中挂载/dev/sdb1

注意,如果在host环境中losetup /dev/loop0 hdisk.img ,再对/dev/loop0分区可能会出现分区表错误!
fdisk的信息:Disk /dev/loop0: 255 heads, 63 sectors, 2 cylinders
其中柱面数与创建磁盘镜像时不匹配(应为40)
最好在guest操作系统中对磁盘镜像进行分区
update:
或在fdisk下输x进入expert模式,手工设置C/H/S值(cylinder/header/sector)
dd if=~/.bochs/guest.hd0 of=/tmp/hd0 bs=512 skip=63 可用于去除文件系统信息

other info
=======
Encrypted Root Filesystem HOWTO
http://lfs.linuxsir.org/main/?q=node/78

update: 2008-07-25
=======
image上安装grub
% ./grub-0.95/grub/grub –no-floppy
grub> device (hd0) c.img

(此处曾尝试使用预先losetup过的/dev/loop0,但没有成功)

grub> geometry (hd0) 3047 16 63
drive 0x80: C/H/S = 3047/16/63, The number of sectors = 3071376, c.img Partition num: 0, Filesystem type is ext2fs, partition type 0x83

grub> root (hd0,0)
Filesystem type is ext2fs, partition type 0x83

grub> setup (hd0)
Checking if “/boot/grub/stage1” exists… yes
Checking if “/boot/grub/stage2” exists… yes
Checking if “/boot/grub/e2fs_stage1_5” exists… yes
Running “embed /boot/grub/e2fs_stage1_5 (hd0)”… 22 sectors are embedded.succeeded
Running “install /boot/grub/stage1 (hd0) (hd0)1+22 p (hd0,0)/boot/grub/stage2 /boot/grub/menu.lst”… succeeded

Done.
http://kbarr.net/bochs

Misc Notes

grep -nHr gmake * –exclude *.svn* awk -F : ‘{print $1}’ xargs sed -si.bak -e ‘s/gmake/make/g’

doubt in find grep sed
http://www.codecomments.com/archive287-2005-1-369741.html

http://www.delorie.com/gnu/docs/sed/sed_toc.html#SEC_Contents
http://www.unix.org.ua/orelly/unix/sedawk/index.htm

rpm -qilp package.rpm
rpm -qf /usr/bin/filename
http://fedoranews.org/alex/tutorial/rpm/

find ./ -name ‘*.swp’ -exec rm {} ;
find ./ -name ‘*.swp’ -ok rm {} ;

objcopy –strip-all from to
objcopy –strip-debug from to

ls -ltru
-t sort by modification time
-r reverse
-u with -lt sort by, and show, access time
-l show access time and sort by name
otherwise sort by accsee time

grep -nHr FileSourced * –exclude=*.svn*

No tags for this post.