2009年5月12日星期二

在Linux下统计你的Erlang程序的行数(SLOC)

统计代码行数(SLOC, soure line of code)的几种选择:
  1. 使用命令wc -l filename可以统计文件filename的行数,但是不能除去空行和注释。
  2. Linux下有个程序叫sloccount,可以统计各种语言的代码行数,但是不支持Erlang -_-!
  3. 我的最终解决方案是使用grep。
使用下面的命令即可统计当前目录下Erlang源代码的行数:
grep -cv '\(^%\)\|\(^\s*$\)' *.erl *.hrl
或者
egrep -cv '(^%)|(^\s*$)' *.erl *.hrl
返回的结果类似于:
module1.erl: 120
module2.erl: 38
module2.hrl: 45

参数c表示让grep统计行数
参数v, 也就是--invert-match,表示选取不符合正则表达式的行

正则表达式(^%)|(^\s*$)由两个正则表达式的并组成。正则表达式^%表示注释(Erlang的注释都以%开始),而正则表达式^\s*$表示开头(^)与结尾($)之间只有任意多个空白符(\s)的行,也就是空行。这样整个正则表达式(^%)|(^\s*$)即表示注释行或者空白行。

GNU的grep和egrep功能相当,区别在于前者使用GNU Basic Regular Expression(BRE),这是目前还在使用的最古老的正则表达式语法,而后者使用的是GNU Extended Regular Expression(ERE)。

两种正则表达式语法的主要区别是前者要求特殊符号前必须有转移字符\, 而后者不要求有\,但是当想表示特殊字符的原意的时候必须加\作为前缀。当正则表达式中有很多特殊符号的时候,ERE的表达就比BRE简洁不少。

关于BRE和ERE可以查看http://www.regular-expressions.info/gnu.html
关于grep的正则表达式的语法可以查看http://opengroup.org/onlinepubs/007908775/xsh/regexp.html

2009年5月7日星期四

Summary on Eleutian's vim tutorial

Eleutian gave a series of vim screencast tutorials , which I think it's good for beginners.

Here's summaries on the key points in his tutorials:

Tutorial 1

1. Vim is a modal editor. There are a lot of modes:
  • Normal mode: Press ESC or CRTL+[
  • Insert mode: Press i in normal mode
  • Command mode: Press : in normal mode
  • Visual mode: Press v in normal mode
  • Append mode: Press a in normal mode
2. In command mode, "e" means opening a file and "w" means saving a file.
  • :e filename : open a file whose name is "filename"
  • :e! : reopen the current file; all changes are lost
  • :w : save the current file
  • :w filename : save the current file as filename; primarily used when a file is to be saved for the first time
3. Stay in normal mode, unless you're actively typing text.
4. To move around in a most efficient way use "h", "j", "k", "l" as left, down, up, right respectively.
5. Move more quickly:
  • ^: Home; move to the head of the current line
  • $: End; move to the end of the current line
  • CRTL + D: Pagedown
  • CRTL + U: Pageup
  • w: Move to the next word
  • b: Move to the previous word
Tutorial 2
1. Move the beginning or the end of a document:
  • gg: Move to the beginning of the document
  • GG: Move to the end of the document
  • XGG: Move the Xth line of the document, like 10G(move to the 10th line)
2. Copy(yank), Cut(delete) and Paste
  • yy: Copy the whole line
  • yw: Copy the next word
  • y$: Copy till the end of line
  • x: cut the current letter
  • dd: Delete the whole line
  • dw: Delete the next word
  • p: Paste the text that just deleted or yanked
3. Change
  • cw: Change the next word
  • cb: Change the previous word
  • c$: Change till the end of line
  • ct: Change till , like ctD(change till the first occurence of letter D)
4. Swap two consecutive letter: xp

Tutorial 3
1. Search
  • :/<Pattern> : Search forward according to the <Pattern>
  • :?<Pattern> : Search backward
  • n: Go to the next occurence <Pattern>
  • p or N: Go to the previous occurence <Pattern>
2. Find
  • f<Symbol> : Find the first occurence of <Symbol>
  • ; : Go to the next occurence of the <Symbol>
  • , : Go to the previous occurence of the <Symbol>
3. Replace
  • %s/<TargetString>/<SubstituteBy>/g : % means the range is the whole text, % means substitution, is what we are looking for, is the substitution for . Don't forget the /g. For example, %s/Good/Bad/g will substitute all ocurrences of "Good" by "Bad" in the whole document.
4. Find occurences of the word under the cursor
  • # : Go to the previous occurence of the word under cursor
  • * : Go to the next occurence of the word under cursor

2009年4月26日星期日

Erlang的Mailbox或者MQ的性能问题

最近看了几篇帖子

erlang-questions mailing list上的讨论Low disk logging performane in SMP
Caoyuan's Blog: A Case Study of Scalability Related "Out of memory" Crash in Erlang
Caoyuan's Blog: Async or Sync Log in Erlang - Limit the Load of Singleton Process

它们都是关于Erlang的mailbox性能问题的。所谓mailbox,就是Erlang的process用于存储其他进程发来的尚未处理的消息的容器。

根据这些讨论我有下面几点总结:
  1. 不要把mailbox“撑爆”:当mailbox太大的时候,selective receive的性能就会大打折扣。在第二篇帖子中,作者的甚至把error_logger的mailbox塞到机器out of memory!
  2. 如何避免:这几篇讨论这中“撑爆”的mailbox都是日志process:一个是error_logger,另一个是file_logger。日志进程的io操作都是比较耗时间的,而发送来的消息又太多太快,以至于写日志的进程根本来不及处理,消息只能在mailbox中积累。所以这在种consumer速度跟不上producer的情况,要尽量减轻consumer(这里是logger)的负担,让操作尽量在producer处完成(比如日志的格式化操作在发送者处做好,而不是在logger处)。另外还可以考虑把logger从singleton变成分布式的。
  3. SMP:多核的使用会加剧这种多producer单consumer情形的速度差距,导致性能下降,甚至内存溢出。
  4. 根据第一篇中的讨论,file:write似乎也是把write的请求发给一个file server,所以过多的请求也会导致write请求的处理效率低下。把几个write请求大包成一个write请求再发送过去或许是一个提高性能的办法。

2009年4月21日星期二

Ubuntu下录制桌面

为了项目演示,我需要在Ubuntu下把我操作的软件的过程录制下来。我使用了RecordMyDesktop这款开源软件,使用下面的命令来安装它:

sudo apt-get install recordmydesktop gtk-recordmydesktop

这个软件的GUI很简洁,非常容易上手。录制出的结果是ogg格式的,在Windows下可能无法播放。我使用了mencoder把ogg转换成avi格式。安装mencoder使用下面的命令:

sudo apt-get install mencoder

使用命令就可以把ogg格式的文件转换成avi:

mencoder -idx input.ogg -ovc lavc -oac mp3lame -o output.avi

我参阅了这个关于Ubuntu下录制桌面的英文blog:http://ubuntuchocolate.wordpress.com/2007/09/01/howto-screen-capture-in-ubuntu-feisty-fawn/

2009年4月7日星期二

美化Ubuntu桌面:Wallpaper Clock





Wallpaper Clock集漂亮的桌布和方便的时钟于一身,将美观和实用完美的结合在了一起。而且在Ubuntu下你可以完全免费地使用Wallpaper Clock来美化你的桌面。

安装过程我参考了这篇国外的blog

使用Wallpaper Clock需要完成三个方面的准备:
  1. 下载Wallpaper Clock:你可以从它的官方网站http://www.vladstudio.com/zh/wallpaperclock/上下载,现在已经有200+的壁纸了,每张都很精美,其中至少有一半是可以免费下载的。壁纸的文件扩展名是wcz。
  2. Wallpaper Clock screenlet:你下载的这些wcz文件不像图片文件可以直接作为桌面的,必须使用专门的软件才能够作为动态桌面呈现出来(每分钟刷新一次以更新壁纸上的时间)。在Windows,Mac,Linux下都有软件可以显示wcz文件,其中Linux下的是一个叫Wallpaper Clock screenlet的screenlet,你可以到http://gnome-look.org/content/show.php?content=66717下载它。这个东东也不能独立运行,它需要利用screenlets manager安装并使用它。
  3. 安装screenlets包:在ubuntu下使用命令"sudo apt-get install screenlets"来安装,这样你就得到了Screenlets Manager以及自带的一些screenlets。注意,在我的Ubuntu 8.04下从源上安装的Screenlets Manager不能使Wallpaper Clock screenlet正确工作。如果你也遇到了同样的问题,根据前面提到的那篇blog,你可以从https://launchpad.net/screenlets/trunk/0.0.12/下载并安装了0.0.12版本的screenlets。在我的Ubuntu 8.04下0.0.12版的screenlets包可以使Wallpaper Clock screenlet正确工作。
至于如何通过Screenlets Manager安装Wallpaper Clock screenlet,以及如何安装wcz为扩展名的壁纸,这里就省略了(也可以参看前面提到的blog),因为都只需要简单的GUI操作就可以完成。

Enjoy!

2009年3月3日星期二

ubuntu下安装Acrobat Reader并显示中文

Adobe的Acrobat Reader还是比Ubuntu自带的Evince要好一些。

在Ubuntu下安装Acrobat Reader的方法如下:
Step1. 设置mediabuntu源,参考官方的指南https://help.ubuntu.com/community/Medibuntu
Step2. sudo apt-get install acroread

此时Acrobat Reader就可以用了,但是还不能显示中文。为了能显示中文还需要做下面几步
Step3. 到这个http://www.adobe.com/tw/products/acrobat/acrrasianfontpack.html网址上下载中文语言包
Step4. 解压后,运行里面的安装脚本(用命令./INSTALL.sh)。当安装脚本要求“
Enter the location where you installed the Adobe Reader [/opt]” ,你输入“/usr/lib”。

这样就可以在Ubuntu下使用Acrobat Reader查看中文文档了。
上述方法在Ubuntu 8.04下实验通过,其他版本应该也可以。

2009年2月26日星期四

判断三点共线问题的最佳程序

此问题与解答源于《Beautiful Code》,这里只是精炼地表达书上的解答。

问题:如何判断平面上三个点(x1,y1),(x2,y2),(x3,y3)是否在一条直线上。
思路:
这个问题的难度不在于如何解决它,而在于如何“完美”地解决它。“完美”,可以理解为代码必须正确,美观,简洁,高效而且不容易受到计算误差的影响。

判断三点共线的方法有很多。如果采用与斜率有关的方法(比如使用直线的截斜式),那么必然要对斜率无穷大或者说没有斜率的情况做特殊处理。也可以考虑计算第三点到另外两点所确立的直线的距离,如果用这种方法,那么会涉及到求直线方程Ax+By+C=0和开平方,这样做运算效率较底。

最终的解决方案是求三点所确立的三角形的面积,三点共线当且仅当三角形的面积为0。而计算面积最简单高效的方法是使用矢量法,即三角形面积的行列式公式,面积等于
| x1-x3 y1-y3|
| x2-x3 y2-y3| / 2

[ (x1-x3)*(y2-y3) -(X2-X3)*(y1-y3)] / 2
利用这个公式可以保证在无论三点是否互不相同都可以判断共线。

Lisp代码:
(defun area-collinear (x1 y1 x2 y2 x3 y3)
(= (* (- x1 x3) (- y2 y3))
(* (- x2 x3) (- y1 y3))))

2009年1月19日星期一

MSI(Microsoft Installer)二三事

最近跟MSI(Microsoft Installer)打了不少交道,下面是关于MSI的一点儿知识:

1. The Windows Installer (previously known as Microsoft Installer[1]) is an engine for the installation, maintenance, and removal of software on modern Microsoft Windows systems. -- Wikipedia
2. msi: Windows系统下的安装文件的格式
    msiexec:在Windows下执行安装的程序
    msiserver:运行msiexec会打开msiserver服务;这个服务会在安装完毕10分钟之后自动关闭
3. 使用msiexec的方法:
    msiexec /?                    查看msiexec的使用方法
    msiexec /i SoftwareInstaller.msi 安装SoftwareInstaller.msi
    msiexec /i SoftwareInstaller.msi /lv log.txt 安装SoftwareInstaller.msi,并将安装过程的日志保存在log.txt
    msiexec /i SoftwareInstaller.msi /quiet       以默认的参数静默安装,即安装过程没有任何提示
4. 结束未完成的安装的过程的方法:
    net stop msiserver
    第三四条命令可以在自动化安装脚本(.bat/.cmd)中用到
5. 在系统的隐藏文件夹%WinDir%\Installer下找到本机缓存的安装文件(.msi)。估计控制面板中的“添加删除程序”就是使用这里的.msi来做uninstallation的。在注册表的HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall下可以查看到反安装时所需要的各种信息
    

2009年1月15日星期四

用C#从注册表中读取%ProgramFiles%的值

%ProgramFiles%是Windows上软件的默认安装路径,常见的值是C:\Program Files或者D:\Program Files。这个值是在注册表中有记录的。如果你的C#程序想读取这个值,可以用下面的代码:

usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingMicrosoft.Win32;
namespaceConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
RegistryKey folders = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\");
if (folders == null)
Console.WriteLine("null");
else
{
string defaultInstallPath = folders.GetValue("ProgramFilesDir") as string;
Console.WriteLine(defaultInstallPath);
}
}
}
}

注意不能写成@"\SOFTWARE\Microsoft\Windows\CurrentVersion\"。

2008年6月3日星期二

Substance下Swing控件中文显示为方框

使用substance后Swing控件上的中文全部显示为方框。 这大概由于substance的look and feel替换了原来的字体,使得中文无法正常显示。解决办法是在设置使用substance的Look and Feel 之后,加入下面的语句:

int sizeOffset = 1 ;
Enumeration keys = UIManager.getLookAndFeelDefaults().keys() ;
while ( keys.hasMoreElements() )
{
Object key = keys.nextElement() ;
Object value = UIManager.get( key ) ;
if ( value instanceof Font )
{
Font oldFont = ( Font ) value ;
Font newFont = new Font( "Dialog", oldFont.getStyle(),
oldFont.getSize() + sizeOffset ) ;
UIManager.put( key, newFont ) ;
}
}

2008年4月12日星期六

matlab的函数参数传递

在网上查到:

如果函数内部试图修改输入参数的值则为值传递,如果没有修改则为地址传递。
采用这一处理方式的目的是:
一、不允许函数内部修改输入参数的值
二、兼顾执行效率(地址传递不需要将输入参数拷贝一份

2008年4月9日星期三

[转载]他们的心情好

http://criyun.blog.hexun.com/18163747_d.html


访美一年归来,当朋友们问起我对美国最大的感受是什么时,我会回答:他们的心情好。

由于心情好,他们对人就比较友善热情。那是我刚踏上美国的土地就感受到的。

刚到纽黑文那天,我与同行的中国朋友从机场打出租车到耶鲁。天下着小雨,我的朋友去联系租房子的事,我则在耶鲁神学院宿舍的大房沿下一边避雨一边看守着大堆的行李。从旁边路过的人看到我的情形,大多都会停下来或走过来问我:

“有什么问题吗?”

“需要帮助吗?”

我诚惶诚恐地回答:“没有,谢谢!”

但有的人走出几步还会回来问我:“是没有钥匙吗?我这有”。

“不是,谢谢!”我非常感激地回答。

即使这样,有的人还是带着很不放心的神情走开,还不时回头看看我。

这种情形在我们这里,是只有熟人和朋友间才会发生的,但在他们这里,会发生在陌生人之间。大体上说,你在中国能够期望熟人和朋友对待你的方式,在美国,大多数陌生人都能做到。

当你在路上散步,迎面遇到一个美国人时,除了像曼哈顿那样的闹市,你常能得到一声热情的问候,像老朋友见面一般。当你在公共场所偶然打扰、冒犯、碰撞了别人,在我们这里会遇到一双白眼,甚至会恶语相加的场合,对方往往只是善意地嫣然一笑。

这些年,我们搞起市场经济,在一些服务业,我们也能享受到“微笑服务”了。但在美国你会发现,当美国人向你问候的时候,往往眼睛深情地注视着你,面带真诚 的笑容。问候语因时因地各不相同,并不是千篇一律的那几句话。在我们这里,被老板和领班训练出来的服务员像大鹦鹉一样地喊:“欢迎光临”,“下次再来,眼睛不会看你,面部没有表情。这种问候和微笑是表演,不会使人感受到善意的温暖,而是感到浑身不自在。

在美国,微笑绝不仅仅是服务业的绝活,也不是服务员(侍者)们的职业技能。他们的问候和微笑是双向的,不仅服务生,而且顾客也会热情地回应,在很多场合, 是顾客主动地问候为他提供服务的服务生。我在耶鲁坐了一年的校车,据我观察,大多数乘客都会上车时向司机打个招呼或下车时向司机道一声“谢谢”。在公交车 上,也经常有乘客会这样做。在我们这里,顾客们会认为,这是我付钱买来的服务,我们不仅不会向服务员问候,而且认定服务员的问候有一种商业化的动机,所 以,面对声声问候和道别,我们大都会目无表情地昂然而入或昂然而去。

我猜想,美国的领班也许不需要刻意地训练他的员工,或 者他们的训练比较自然。因为热情友善地待人是他们的日常生活,是人与人相遇时的一般行为方式。不仅他们做服务生时才会这样,不仅在饭店里、在柜台前、在大 堂上才会这样做,而是街道上、走廊里、电梯中,在人与人相遇的各种场合,他们都会这样做。

记得有一次,我与两位多次来过美国的中国学者在纽黑文的街上散步。一个美国人低着头从我们身边匆匆走过,这时,一位中国学者转过身指着那位美国人的后背 说:你看,美国人的道德水准下降了。我问他为什么这样说,他回答:他看见我们没打招呼就过去了。我问他:以前美国人在路上遇见陌生人都打招呼吗?他和另一 位中国学者都非常肯定地说,绝大多数都会打招呼的,现在打招呼的的确比以前少了。

可是,在我看来,这种据说已经“下降了”的道德状况仍然是我们难以企及的。这种待人方式,将内心的善意传达给别人,也得到善意的回报,从而营造了一个友善和谐的社会气氛。

在美国,虽然也会遇上无家可归者呆滞迷茫的目光,游荡在大街上和公园里的无业游民令人不舒服甚至恐惧的神情——这些边缘群体难得有一个好心情,但在一般的场合,你随处都能看到笑脸,到处充盈着笑声。他们是如此的幽默,如此的开心,让人嫉妒。

美国电视的搞笑节目,大多是现编现卖的,总能赢得观众开心的笑声。我看过一个节目,一个女主持人在那里讲故事,讲她的经历,平均五六句话就使观众笑一次。可她一口气讲了三个钟头!

看美国的电视,主持人经常互相开玩笑,笑得前仰后合。从严肃的政治新闻、社会新闻,直到天气预报,他们都开着玩笑讲。

一次,副总统切尼打猎误伤了朋友。人们预料,大约在 一个星期的时间内,他会成为媒体开心的材料。果然如此。一个搞笑节目主持人一出场就兴奋地大喊:“大规模杀伤性武器找到了!”,然后扳着脸严肃地说“在切 尼这”。一家电视台制作了一个小卡通,切尼端着来福枪,牛气冲天的神态,嗵、嗵、嗵地一路打过来,让人忍俊不禁。

在美国,笑是如此廉价;在中国,笑是如此罕见的奢侈品。

中国人是很不容易逗笑的民族,所以竟使一个专门逗乐子的文艺种类濒临灭绝了。小品演员一年半载才鼓捣出来一台节目,其中的大多数竟然不容易让观众开怀笑一 下。尽管媒体一再煽情,什么“今天是个好日子”,什么“咱们老百姓今儿个真高兴”,观众就硬是心事重重眉头紧锁高兴不起来。

在美国,笑也是最慷慨也最有价值的馈赠。

在一年一度的白宫招待记者的宴会上,为了取乐大家,白宫主人安排两位平时专门拿布什总统开涮的电视搞笑明星来到招待会上表演。其中一个扮成布什,活灵活 现,俨然一对双胞胎。在布什致辞时,他在旁边以夸张和丑化的方式摹仿布什的语言和动作。布什显得有点不自在,脸上红一阵白一阵,但夫人劳拉在一旁却乐不可 支。

布什在耶鲁读书时,是个经常得C的学生,这段糗事当他竞选总统时被人发掘出来并大肆炒作。如果放在我们这儿,是足以让我们的官僚政客们嘴上起泡大便干燥的,但布什却拿自己的糗事逗别人开心。据说,他有一次对耶鲁的学生说:在耶鲁读书是很好的事,如果你是A类的学生,你能当大学教授;如果你是B类的学生,你可以做CEO;如果你是C类学生,还能做个总统。同时他还没忘了捎上他的铁杆搭档切尼,这位曾在耶鲁退学的副总统:如果你是个不合格的学生,也能当副总统。

看来 ,为了让别人开心而献出自己当笑料,这大概是美国人招待朋友和客 人的一种方式。在期末的时候,我应邀参加耶鲁政治学系的期末聚会,参加者是全系的教职工和研究生。按惯例,由二年级研究生表演节目。同样按惯例,节目的内 容是摹仿和讽刺他们的老师。表演者胸前挂着一个牌子,正面和背面各写一位他们所要摹仿的老师的名字。他们摹仿老师一些富于个性的动作和语言,常逗得台下的 师生开怀大笑。

当然,有时美国人的玩笑开大了,竟然涉及到中国和中国人,说不定会被哪家小报记者拿来炒作一把,一群神经质的“爱国主义”者一哄而起,将其定性为“反华” 或“辱华”事件,排泄出一堆国骂,有时会迫使他们像犯了错误的小学生一样道歉。他们绝对不了解中国的“国情”,中国人是很容易发怒的民族。中国的骂与美国 的笑一样多。

国内电视经常转播的“开心一笑”(just for laugh) 之类的节目,从中也许最能了解美国人的心情。这种节目往往以搞恶作剧即“整人”的方式寻开心,那些受到不明来由的惊吓、侵扰、诬谄、欺辱的受作弄者,或显 出惊愕、疑惑、茫然的神情,或幽然一笑,或无可奈何地耸耸肩,双手一摆,最多是理性与克制的争辩。我大胆设想,虽然我们能够摹仿“美国偶像”一类的节目, 但却无法摹仿“开心一笑”,因为电视台绝不敢用那种恶作剧向我们的同胞开玩笑。

美国人待人接物时的友善、热心助人、无所不在的幽默感——无论拿自己开心还是拿别人开心,以及被别人捉弄时的反应,都反映出他们的心境。我们想想,当我 们心情好的时候,大体上也能像他们那样。他们日常生活中表现出来的经常性的精神状态和行为方式,无非是我们在心情很好时才可能有的精神状态和行为方式。区 别在于,他们经常有一个好心情,我们却难得有一个好心情。

人们在获得基本的生活保障和安全后,精神的快乐应该成为衡量生活质量的最重要的指标。可是,一次次国际性研究,对各国人民生活的快乐指数排名,中国都远远地排在后面……远低于我们人均GDP的排名。

为什么我们得不到快乐?耶鲁的华人学者陈志武教 授有句名言:“一个典型的中国人一辈子是不幸福的”。他从养老金制度的角度对此做出了有力的论证。但是,使中国人活得沉重、忧郁、烦躁的,岂止是养老问题 呢?我们的制度放任专横任性的权力,在这种权力面前,人得不到尊重、不能自由地伸展,常常受到侮辱和欺凌而无可奈何。这种任性的权力本身就成为人们的一大 心病。我们的文化和风俗习惯有太多违背人性的东西,自己与自己过不去的东西。它使我们作茧自缚、自我糟贱。它像一张大网,将我们死死缠住。我们屈从于这种 制度和这种文化,甚至热心地维护和发展它们,从而使自己活得累、活得烦、活得不快活。

由于太多的个体经常处于心情不好的状态,于是大家相互传染,相互激荡,共同营造了一个恶劣的社会环境:人与人之间充满冷漠、不信任、嫉妒、敌意。每个人将 自己的坏心情释放给社会,也同等地遭遇其他人的坏心情。它们相互激荡,相互放大。在被大家共同毒化了的社会环境里,没有人会有好心情。当阴郁碰上烦躁、烦 躁撞上愤懑、愤懑遭遇仇恨的时候,你还能指望会发生什么呢?

每个人的行为和心境,一方面为他人营造了一个外部世界,同时也为自己创造了一个外部世界。对个人而言,外部世界不光是眼睛看到的,也是我们的心镜映射出来 的。不同的心情投射到外部世界,外部世界就会呈现出不同的色彩。所谓“心清水现月,意净天无云”。当我们心情好时,世界是明亮的:似乎百花在向我传情,百 鸟在为我鸣唱,云朵在向我招手,太阳也向我露出笑厣。我们在这时对人会比较友善,对事比较平和。当我们心情不好时,世界是阴郁的。在这时,我们会以敌意对 待周围的人:我们很容易惩罚孩子,羞辱学生,顶撞顾客,和同事发生争吵,与路人为敌。

如果我们从充满冷漠与敌意的社会中长大,我们便会以冷漠和敌意的眼光看待社会;我们从别人那里很少得到关爱和友善,我们便很难将关爱和友善给予别人;我们 在童年时代受到压抑和虐待,我们长大后就会充满怀疑与仇恨。当我们走向社会,一种恶意假设已经成为我们估量他人行为的基准。这种恶意假设使人与人之间没有 了信任和友善,使人们的心头充满怀疑、敌意和愠怒,不幸的是,在我们这里,这种恶意假设总是合理假设,而坏心情就成为我们的精神常态。

当我们在GDP上紧盯着美国较劲时,别忘了我们与美国的差距还有快乐指数!

2008年4月6日星期日

恢复windows xp的丢失的注册表

一台xp的机器开机后提示“无法找到\windows\system32\config\system”这个文件,导致xp启动失败。
到微软的官方技术支持网站上找到了解决办法。按照文章上面的指示一步步做了,果然系统又恢复如初。在解决问题 的过程中对windows又有了一些新的认识:
(1) windows\system32\config这个目录下的信息应该是xp的注册表信息。windows\repair 目录下存放了windows\system32\config的安装系统时候的备份。利用这个备份可以使原本挂掉的xp启动。
(2)诸如C:\System Volume Information\_restore{D86480E3-73EF-47BC-A0EB-A81BE6EE3ED8}\RP1\Snapshot
这样的目录下存放了xp的还原点信息,其中包括注册表的信息。可以用一个最近的还原点信息回复缺失的注册表。
(3)C:\System Volume Information这个目录似乎在恢复控制台下不能访问,这也就是为什么下面的文档要分三步。

原文如下:

How to recover from a corrupted registry that prevents Windows XP from starting

Article ID:307545
Last Review:November 12, 2007
Revision:10.15
This article was previously published under Q307545

SUMMARY

This article describes how to recover a Windows XP system that does not start because of corruption in the registry. This procedure does not guarantee full recovery of the system to a previous state; however, you should be able to recover data when you use this procedure.

Warning Do not use the procedure that is described in this article if your computer has an OEM-installed operating system. The system hive on OEM installations creates passwords and user accounts that did not exist previously. If you use the procedure that is described in this article, you may not be able to log back into the recovery console to restore the original registry hives.

You can repair a corrupted registry in Windows XP. Corrupted registry files can cause a variety of different error messages. See the Microsoft Knowledge Base for articles about error messages that are related to registry issues.

This article assumes that typical recovery methods have failed and access to the system is not available except by using Recovery Console. If an Automatic System Recovery (ASR) backup exists, it is the preferred method for recovery. Microsoft recommends that you use the ASR backup before you try the procedure described in this article.

Note Make sure to replace all five of the registry hives. If you only replace a single hive or two, this can cause potential issues because software and hardware may have settings in multiple locations in the registry.

Back to the top

MORE INFORMATION

When you try to start or restart your Windows XP-based computer, you may receive one of the following error messages:
Windows XP could not start because the following file is missing or corrupt: \WINDOWS\SYSTEM32\CONFIG\SYSTEM
Windows XP could not start because the following file is missing or corrupt: \WINDOWS\SYSTEM32\CONFIG\SOFTWARE
Stop: c0000218 {Registry File Failure} The registry cannot load the hive (file): \SystemRoot\System32\Config\SOFTWARE or its log or alternate
System error: Lsass.exe
When trying to update a password the return status indicates that the value provided as the current password is not correct.

Guided Help to recover a corrupted registry that prevents Windows XP from starting

Guided Help
Guided Help is available to help recover a corrupted registry that prevents Windows XP from starting. Guided Help can automatically perform the steps for you.

The actions that this Guided Help performs can be undone after Guided Help is finished. To undo the actions that this Guided Help performs and to restore the corrupted registry files, start Recovery Console, and then manually copy the Windows\Tmp\*.bak files to the Windows\System32\Config folder. Make sure to rename the files to remove the .bak extension.
For more information about Guided Help, click the following article number to view the article in the Microsoft Knowledge Base:
915092 (http://support.microsoft.com/kb/915092/) Description of Guided Help for Microsoft Knowledge Base articles

Requirements to install and to use this Guided Help

You must be logged on to Windows by using a computer administrator account to install and to use this Guided Help.
You must be running Windows XP Home Edition, Windows XP Professional, Windows XP Media Center Edition, or Windows XP Tablet PC Edition to install and to use this Guided Help.
You must first download Guided Help. To start, click the following link:
(http://support.microsoft.com/kb/307545/)

Manual steps to recover a corrupted registry that prevents Windows XP from starting

The procedure that this article describes uses Recovery Console and System Restore. This article also lists all the required steps in specific order to make sure that the process is fully completed. When you finish this procedure, the system returns to a state very close to the state before the problem occurred. If you have ever run NTBackup and completed a system state backup, you do not have to follow the procedures in parts two and three. You can go to part four.

Part one

In part one, you start the Recovery Console, create a temporary folder, back up the existing registry files to a new location, delete the registry files at their existing location, and then copy the registry files from the repair folder to the System32\Config folder. When you have finished this procedure, a registry is created that you can use to start Windows XP. This registry was created and saved during the initial setup of Windows XP. Therefore any changes and settings that occurred after the Setup program was finished are lost.

To complete part one, follow these steps:
1.Insert the Windows XP startup disk into the floppy disk drive, or insert the Windows XP CD-ROM into the CD-ROM drive, and then restart the computer.
Click to select any options that are required to start the computer from the CD-ROM drive if you are prompted to do so.
2.When the "Welcome to Setup" screen appears, press R to start the Recovery Console.
3.If you have a dual-boot or multiple-boot computer, select the installation that you want to access from the Recovery Console.
4.When you are prompted to do so, type the Administrator password. If the administrator password is blank, just press ENTER.
5.At the Recovery Console command prompt, type the following lines, pressing ENTER after you type each line:
md tmp
copy c:\windows\system32\config\system c:\windows\tmp\system.bak
copy c:\windows\system32\config\software c:\windows\tmp\software.bak
copy c:\windows\system32\config\sam c:\windows\tmp\sam.bak
copy c:\windows\system32\config\security c:\windows\tmp\security.bak
copy c:\windows\system32\config\default c:\windows\tmp\default.bak

delete c:\windows\system32\config\system
delete c:\windows\system32\config\software
delete c:\windows\system32\config\sam
delete c:\windows\system32\config\security
delete c:\windows\system32\config\default

copy c:\windows\repair\system c:\windows\system32\config\system
copy c:\windows\repair\software c:\windows\system32\config\software
copy c:\windows\repair\sam c:\windows\system32\config\sam
copy c:\windows\repair\security c:\windows\system32\config\security
copy c:\windows\repair\default c:\windows\system32\config\default
6.Type exit to quit Recovery Console. Your computer will restart.
Note This procedure assumes that Windows XP is installed to the C:\Windows folder. Make sure to change C:\Windows to the appropriate windows_folder if it is a different location.

If you have access to another computer, to save time, you can copy the text in step five, and then create a text file called "Regcopy1.txt" (for example). To use this file, run the following command when you start in Recovery Console:
batch regcopy1.txt
With the batch command in Recovery Console, you can process all the commands in a text file sequentially. When you use the batch command, you do not have to manually type as many commands.

Part two

To complete the procedure described in this section, you must be logged on as an administrator, or an administrative user (a user who has an account in the Administrators group). If you are using Windows XP Home Edition, you can log on as an administrative user. If you log on as an administrator, you must first start Windows XP Home Edition in Safe mode. To start the Windows XP Home Edition computer in Safe mode, follow these steps.

Note Print these instructions before you continue. You cannot view these instructions after you restart the computer in Safe Mode. If you use the NTFS file system, also print the instructions from Knowledge Base article KB309531. Step 7 contains a reference to the article.
1.Click Start, click Shut Down (or click Turn Off Computer), click Restart, and then click OK (or click Restart).
2.Press the F8 key.

On a computer that is configured to start to multiple operating systems, you can press F8 when you see the Startup menu.
3.Use the arrow keys to select the appropriate Safe mode option, and then press ENTER.
4.If you have a dual-boot or multiple-boot system, use the arrow keys to select the installation that you want to access, and then press ENTER.
In part two, you copy the registry files from their backed up location by using System Restore. This folder is not available in Recovery Console and is generally not visible during typical usage. Before you start this procedure, you must change several settings to make the folder visible:
1.Start Windows Explorer.
2.On the Tools menu, click Folder options.
3.Click the View tab.
4.Under Hidden files and folders, click to select Show hidden files and folders, and then click to clear the Hide protected operating system files (Recommended) check box.
5.Click Yes when the dialog box that confirms that you want to display these files appears.
6.Double-click the drive where you installed Windows XP to display a list of the folders. If is important to click the correct drive.
7.Open the System Volume Information folder. This folder is unavailable and appears dimmed because it is set as a super-hidden folder.

Note This folder contains one or more _restore {GUID} folders such as "_restore{87BD3667-3246-476B-923F-F86E30B3E7F8}".

Note You may receive the following error message:
C:\System Volume Information is not accessible. Access is denied.
If you receive this message, see the following Microsoft Knowledge Base article to gain access to this folder and continue with the procedure:
309531 (http://support.microsoft.com/kb/309531/) How to gain access to the System Volume Information folder
8.Open a folder that was not created at the current time. You may have to click Details on the View menu to see when these folders were created. There may be one or more folders starting with "RPx under this folder. These are restore points.
9.Open one of these folders to locate a Snapshot subfolder. The following path is an example of a folder path to the Snapshot folder:
C:\System Volume Information\_restore{D86480E3-73EF-47BC-A0EB-A81BE6EE3ED8}\RP1\Snapshot
10. From the Snapshot folder, copy the following files to the C:\Windows\Tmp folder:
_REGISTRY_USER_.DEFAULT
_REGISTRY_MACHINE_SECURITY
_REGISTRY_MACHINE_SOFTWARE
_REGISTRY_MACHINE_SYSTEM
_REGISTRY_MACHINE_SAM
11.Rename the files in the C:\Windows\Tmp folder as follows:
Rename _REGISTRY_USER_.DEFAULT to DEFAULT
Rename _REGISTRY_MACHINE_SECURITY to SECURITY
Rename _REGISTRY_MACHINE_SOFTWARE to SOFTWARE
Rename _REGISTRY_MACHINE_SYSTEM to SYSTEM
Rename _REGISTRY_MACHINE_SAM to SAM
These files are the backed up registry files from System Restore. Because you used the registry file that the Setup program created, this registry does not know that these restore points exist and are available. A new folder is created with a new GUID under System Volume Information and a restore point is created that includes a copy of the registry files that were copied during part one. Therefore, it is important not to use the most current folder, especially if the time stamp on the folder is the same as the current time.

The current system configuration is not aware of the previous restore points. You must have a previous copy of the registry from a previous restore point to make the previous restore points available again.

The registry files that were copied to the Tmp folder in the C:\Windows folder are moved to make sure that the files are available under Recovery Console. You must use these files to replace the registry files currently in the C:\Windows\System32\Config folder. By default, Recovery Console has limited folder access and cannot copy files from the System Volume folder.

Note The procedure described in this section assumes that you are running your computer with the FAT32 file system. For more information about how to access the System Volume Information Folder with the NTFS file system, click the following article number to view the article in the Microsoft Knowledge Base:
309531 (http://support.microsoft.com/kb/309531/) How to gain access to the System Volume Information folder

Part Three

In part three, you delete the existing registry files, and then copy the System Restore Registry files to the C:\Windows\System32\Config folder:
1.Start Recovery Console.
2.At the command prompt, type the following lines, pressing ENTER after you type each line:
del c:\windows\system32\config\sam

del c:\windows\system32\config\security

del c:\windows\system32\config\software

del c:\windows\system32\config\default

del c:\windows\system32\config\system

copy c:\windows\tmp\software c:\windows\system32\config\software

copy c:\windows\tmp\system c:\windows\system32\config\system

copy c:\windows\tmp\sam c:\windows\system32\config\sam

copy c:\windows\tmp\security c:\windows\system32\config\security

copy c:\windows\tmp\default c:\windows\system32\config\default
Note Some of these command lines may be wrapped for readability.
3.Type exit to quit Recovery Console. Your computer restarts.
Note This procedure assumes that Windows XP is installed to the C:\Windows folder. Make sure to change C:\Windows to the appropriate windows_folder if it is a different location.

If you have access to another computer, to save time, you can copy the text in step two, and then create a text file called "Regcopy2.txt" (for example). To use this file, run the following command when you start in Recovery Console:
batch regcopy2.txt

Part Four

1.Click Start, and then click All Programs.
2.Click Accessories, and then click System Tools.
3.Click System Restore, and then click Restore to a previous RestorePoint.

Back to the top

REFERENCES

For more information about using Recovery Console, click the following article numbers to view the articles in the Microsoft Knowledge Base:
307654 (http://support.microsoft.com/kb/307654/) How to install and use the Recovery Console in Windows XP
216417 (http://support.microsoft.com/kb/216417/) How to install the Windows Recovery Console
240831 (http://support.microsoft.com/kb/240831/) How to copy files from Recovery Console to removable media
314058 (http://support.microsoft.com/kb/314058/) Description of the Windows XP Recovery Console
For more information about System Restore, click the following article numbers to view the articles in the Microsoft Knowledge Base:
306084 (http://support.microsoft.com/kb/306084/) How to restore the operating system to a previous state in Windows XP
261716 (http://support.microsoft.com/kb/261716/) System Restore removes files during a restore procedure

金盾暂时性休克

莫非愚人节还没有结束,现在又可以直接上英文版的维基百科和blogger了。

这两天把Vista装上了,又试试了基于firefox的社会化浏览器Flock,有蛮多功能的。

2007年12月31日星期一

(转载)访问wiki的几种方法

一、使用在线网页代理:

http://www.wikientry.cn

用 Firefox 浏览器 + gladder 插件轻松访问维基百科

通过 anonymouse.org 直接访问 http://www.wikipedia.org

二、使用 Tor 代理工具:

教程1:Tor代理全套解决方案

教程2:Firefox+Tor必备教程

三、使用维基百科浏览器:

http://gollum.easycp.de/en/

推荐使用的firefox插件

Fission: Safari风格的进度条
一个直观而有用的功能

Personas: 主题、皮肤工具
方便选择各式各样的firefox主题和皮肤,让你firefox变得绚丽可爱