Cool Emacs operation animation

水木Emacs版上chunhui找到了这个动画,编辑C/C++文件的操作,太酷了。看了之后是不是就有努力学习坚持使用Emacs的决心了?用Emacs至少一个好处,就是可以一下变得貌似牛人。

水木的网友讨论了动画中功能的实现,摘抄下来:

发信人: ilovecpp (cpp), 信区: Emacs
C-SPC
#include <stdio.h>

#include <stdlib.h>
C-u 0 C-x a g includec RET
now create a new buffer and type
includec RET

info/emacs/abbrevs for detail

发信人: hrothgar (faith, valor, wisdom), 信区: Emacs
see here:
http://www.bloomington.in.us/~brutt/msf-abbrev.html
我觉得他的想法不错, 其实函数声明可以自动生成. 扫描一下 glibc 头文件就可以了.

发信人: dryice (孤独的狼~~有了水木不再孤独~~), 信区: Emacs
已经有人做了,见 User-Contributed abbrevs 一节 :)

发信人: ann77 (ann), 信区: Emacs
其实也花不了太多的时间,想想你可以节省多少时间啊。
我自己就有很多类似的 abbrev
例如 main, newclass , stdioh, inc 等等,在我的主页上
或者以前的文章里都有。

我觉得 abbrev 是一个很个人的东西,关键看你是否需要经常需要
输入同样的信息,这样配置 abbrev 就显得很值得。

我给我的朋友“秀”我的emacs 的时候,他们对 main, newclass
的功能印象十分深刻,但是看到我的配置文件的时候,都望而却步。
依然不愿使用 emacs

发信人: smdavidth (瀧), 信区: Emacs
http://www.bloomington.in.us/~brutt/msf-abbrev.html

Google Desktop Search 3.0发布,不用,继续等

Google 中文桌面第 3 版 Beta 今天发布,但是我还不打算安装。因为对我来说最重要的功能是搜索,但是GDS在搜索上还有很难接受的缺陷。

中文分词不好

当然,是相对于google网站上来说的,差得有点太多。

图片搜索不支持IPTC或EXIF

GDS倒是理所当然的支持Picasa的标签,但是这不是公开标准啊。我的感觉中,Google与MS相比较,更接近于GNU,更尊重标准,乐意开放。但是这个地方恐怕不是。
而且这个事情在Google Desktop新闻组 中早有提议,也没引起重视。
不知道Picasa标注的标签是什么格式。下图是Picasa标注前后Jpeg文件头的对比。

这个问题在

反正msn desktop 也好不到哪去,只支持Windows Explorer“属性”中标注的标签。

Copernic 这个软件倒是支持IPTC/EXIF,甚至Windows Explorer的标注。但是这个软件对中文支持太次。

其他

其他应该说都是小事吧。
删除和移动的文件不能很快更新。倒是可以看作给误删除动作留一个备份,要是机密的就完蛋了。
索引更新动作太隐蔽了,只听见硬盘咋咋响,到底索引哪些东西,不知道。比较起来还是Msn desktop好多了。

听说只能索引大文件前面的一小部分,要是想找到比如金庸全集里的一段话,恐怕就不能了。
有一个评测,Desktop Search: Not ready for prime time?,写得挺全,实验步骤也详尽可信。但是时间之后似乎不太准确,有偏袒Corpernic的意思。

不过

不过GDS是最早开始关注的桌面搜索工具,因为喜欢,因为觉得前途伟大,所以关注。有缺陷仍然是首选,不能接受就干脆不用桌面搜索了。不知道啥时候能变成自己想要的模样,毕竟是免费的玩意。也很希望国产的88data 啦,百度硬盘搜索啦,都能踏实做得更好,能坚持,能看得长远一点,不要剑走偏锋。

三国演义。滚滚长江东逝水。粤语版

水木三国版上找到的。第一次听是六七年前了,mp3下载到电脑上,结果丢了。后来广东的同学树熊回家找了CD给我,但是效果不太好,声音太小了。没想到今天又找到了,真是非常高兴啊。正好最近还在听袁阔成三国演义。
这个粤语版的和普通话版的感觉很不一样,节奏上起伏更大,很有滋味。

备份本地邮件到Gmail等邮箱

Requirements

把邮件备份到Gmail或者其他邮箱中。

Google GMail Loader (GML) 是一个实现这种功能的软件。

我的基本要求是Subject, From, Date, To 这几个字段能够保留,也就是说邮件看起来还能和当初接收时一样,发信人、收信人、日期等等都不会因为这个Backup的过程而发生变化。效果和邮件服务器“自动转发”类似。

Outline

直接通过客户端软件转发或者像备份Outlook中的邮件到Gmail 这篇文章中介绍的方法,实际上都是在原来邮件的基础上产生新的邮件,新的邮件的上述字段描述的都是这次转发的动作。

MIME-Type的邮件是文本格式,只要能保持邮件头中的相应Meta就可以了。
mbox 是Unix中邮件的存储格式,Thunderbird也使用这种格式。在Gmail中如果在More options中点击 Show original 也可以看到邮件的原始格式也是这样的。下面是一个mbox文件中的一封邮件,除了开头以From开始的一行,就是整个邮件的内容(包括附件)。.eml邮件也是一样的格式。
需要做的就是把要备份的邮件按照原始格式发出去。

From - Sat Mar 18 13:05:01 2006
X-Account-Key: account2
X-UIDL: GmailId109e4eefe4d8ed58
X-Mozilla-Status: 0001
X-Mozilla-Status2: 00000000
X-Gmail-Received: c8a53f9e65e27182a7181970efbd3fed4e69a43b
Received: by 10.70.56.14; Fri, 10 Mar 2006 08:13:21 -0800 (PST)
Message-ID:
Date: Fri, 10 Mar 2006 08:13:21 -0800
From: “Gmail Team”
Reply-To: caichanghui520@gmail.com
To: “charlie zhu”
Subject: =?GB2312?B?ssyzpLvUIGhhcyBhY2NlcHRlZCB5b3VyIGludml0YXRpb24gdG8gR21haWw=?=
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary=”—-=_Part_6342_7572464.1142007201426″

——=_Part_6342_7572464.1142007201426
Content-Type: text/plain; charset=GB2312
Content-Transfer-Encoding: base64
Content-Disposition: inline

ssyzpLvUIGhhcyBhY2NlcHRlZCB5b3VyIGludml0YXRpb24gdG8gR21haWwgYW5kIGhhcyBjaG9z
ZW4gdGhlIGJyYW5kIG5ldwphZGRyZXNzIGNhaWNoYW5naHVpNTIwQGdtYWlsLmNvbS4gQmUgb25l
IG9mIHRoZSBmaXJzdCB0byBlbWFpbCCyzLOku9QgYXQgdGhpcwpuZXcgR21haWwgYWRkcmVzcy0t
anVzdCBoaXQgcmVwbHkgYW5kIHNlbmQgssyzpLvUIGEgbWVzc2FnZS4KY2FpY2hhbmdodWk1MjBA
Z21haWwuY29tIGhhcyBhbHNvIGJlZW4gYXV0b21hdGljYWxseSBhZGRlZCB0byB5b3VyIGNvbnRh
Y3QKbGlzdCBzbyB5b3UgY2FuIHN0YXkgaW4gdG91Y2ggd2l0aCBHbWFpbC4KCgpUaGFua3MsCgpU
aGUgR21haWwgVGVhbQo=
——=_Part_6342_7572464.1142007201426
Content-Type: text/html; charset=GB2312
Content-Transfer-Encoding: base64
Content-Disposition: inline

PGh0bWw+Cjxmb250IGZhY2U9IkFyaWFsLCBIZWx2ZXRpY2EsIHNhbnMtc2VyaWYiPgo8cD6yzLOk
u9QgaGFzIGFjY2VwdGVkIHlvdXIgaW52aXRhdGlvbiB0byBHbWFpbCBhbmQgaGFzCiAgY2hvc2Vu
IHRoZSBicmFuZCBuZXcgYWRkcmVzcyBjYWljaGFuZ2h1aTUyMEBnbWFpbC5jb20uIEJlIG9uZSBv
ZiB0aGUgZmlyc3QgdG8gZW1haWwgCiAgssyzpLvUIGF0IHRoaXMgbmV3IEdtYWlsIGFkZHJlc3Mt
LWp1c3QgaGl0IHJlcGx5IGFuZCBzZW5kIAogILLMs6S71CBhIG1lc3NhZ2UuIGNhaWNoYW5naHVp
NTIwQGdtYWlsLmNvbSBoYXMgYWxzbyBiZWVuIGF1dG9tYXRpY2FsbHkgYWRkZWQgdG8KICB5b3Vy
IGNvbnRhY3QgbGlzdCBzbyB5b3UgY2FuIHN0YXkgaW4gdG91Y2ggd2l0aCBHbWFpbC4KPC9wPgo8
cD48YnI+CiAgVGhhbmtzLCA8L3A+CjxwPiBUaGUgR21haWwgVGVhbTwvcD4KPC9mb250Pgo8L2h0
bWw+Cg==
——=_Part_6342_7572464.1142007201426–

上面绿色的部分是Thunderbird加上去的。
需要注意的是,红色的Message-ID这行要去掉才可以被Gmail正确处理。我猜Gmail会因为这个ID已经存在而不会接收。不过这封邮件本来就是Gmail早先收到pop到本地的,一般也没有发回去的必要。

Implement

Python code:

smtp = smtplib.SMTP(MY_SMTP_SERVER, MY_SMTP_SERVER_PORT)
smtp.set_debuglevel(1)
smtp.login( MY_SMTP_USERNAME, MY_SMTP_PASSWORD )
”’
ms = mailbox.UnixMailbox( open(MY_SOURCE_MBOX_FILE))
m = ms.next()
while m:
msg = m.__str__()+ m.fp.read()
smtp.sendmail("dumi@me.com", MY_BACKUP_EMAIL, msg)
m = ms.next()
”’
mbx = open( MY_SOURCE_MBOX_FILE )
line = mbx.readline()
msg = ”
while line:
if line.find( ‘From -’ ) == 0: #@ New msg start
if not msg == ”:
smtp.sendmail("dumy@me.com", MY_BACKUP_EMAIL, msg )
msg = ”
if not line.find( ‘Message-ID:’ ) == 0:
#@ Nor perhaps refused by mail server as resent
msg += line
line = mbx.readline()
if not msg == ”:
smtp.sendmail("dumy@me.com", MY_BACKUP_EMAIL, msg )
mbx.close()
smtp.quit()

Result

下面是备份后邮件的情况,收、发者和接收时间都没有发生变化。

Programming with mBox

An mbox is a text file containing an arbitrary number of e-mail messages. Each message consists of a postmark, followed by an e-mail message formatted according to RFC 822. The file format is line-oriented. Lines are separated by line feed characters (ASCII 10). mbox

The mbox Format , If we use the mbox format to store emails, we put all of them in one file. This creates more or less long text file (Internet email always only exists as 7-bit ASCII text, everything else — attachments, for example — is encoded) containing one email message after the other. How do we know where one ends and another starts?

Fortunately, every email has at least one From-line at its very beginning. Every message begins with “From “ (From followed by a white space character, also called a “From_” line). If this sequence (”From “) at the beginning of a line is preceded by an empty line or is at the top of the file, we have found the beginning of a message.

Reading and writing mbox style mailbox files

mbox - file containing mail messages

More about Thunderbird

我个人建议使用Thunderbird等这种使用RFC标准的mbox格式存储邮件的客户端软件来管理邮件。因为不论在什么环境中,都可以保证可靠的访问。实际上我现在的邮件管理策略就是用Gmail来作为邮件处理的中心,其他的各个邮箱都自动转发到主Gmail帐号中。然后再通过Thunderbird pop下来作为本地的备份,以防不测。写这个程序就是为了把从前大量的直接用客户端邮件接收到的邮件再同步到Gmail中。毕竟Gmail的Label式管理搜索很好用。

Mozilla Thunderbird stores emails in the mbox format. http://www.broobles.com/imapsize/th2outlook.php

Calling Thunderbird from other programs
Thunderbird supports SimpleMAPI, which is a Microsoft standard way for a third party application to send email messages using the default email client. SimpleMAPI can be called from C , C++ and Visual Basic.

XPCOM (Cross Platform Component Object Model) is Mozilla’s framework for writing cross-platform, modular software. Despite some obvious similarities, Microsoft COM and XPCOM components are not compatible or interchangeable. XPCOM components can be written in and used from C, C++, Perl, Python, and JavaScript.

Thunderbird supports command line arguments to open the compose message window and fill in the headers, the message body and attachment(s), but you’d still have to press the send button.

Thunderbird doesn’t have a scripting capability. Its functionality can be modifed using XUL based extensions. It does not support traditional plug-ins.

If all you want to do is to process new messages don’t overlook writing a script that parses the “inbox.” mbox file using the X-Mozilla-Status headers to figure out if a message is a new message. A mbox file is essentially just a flat text file that has a seperator between the messages and special encoding for any “From” strings if they occur at the beginning of a line in either the headers or the message body.

您的邮件文件保存在你的配置文件中 (参阅 配置文件夹),在 Mail 和 ImapMail (如果您使用 IMAP) 文件夹里。每一个邮件文件夹 (收件箱,已发送消息,等等) 被储存为两个文件 — 一个没有扩展名 (例如 INBOX),这是邮件文件本身 (“mbox” 格式),一个带有 .msf 扩展名 (例如 INBOX.msf),这是邮件文件的索引 (邮件概要文件)。其他程序从没有扩展名的文件导入邮件。http://www.mozilla.org.cn/support/thunderbird/faq.html#q2.10

弃bloglines.com投reader.google.com

仅从阅读的习惯来说,google reader更合适。

现在每天读订阅的RSS,差不多成了一项任务。读不完就要积攒到明天。有时候积攒得多了,甚至都有些头疼。尤其是用bloglines,冷不丁一看,每个分类下都有成百上千未读条目时,实在没有勇气用鼠标一次打开这个分类。

firefox占用内存的确很吓人,一次打开这几百上千个条目,显示在一个页面上(看第一张图的滚动条),说不准就歇菜了。破机器跑得太辛苦。尤其是水木blog的推荐,说不定就有一串高质量大图在里面埋伏。经常打开一个好几十屏页面,干一会活就过来偷瞄一眼。结果咵嚓一下子firefox崩了,再打开这个分类都变已读了。这个时候就总会觉得没读到的东西里面肯定有值得一看的,一天都空涝涝的。

google reader阅读方式不错,也不知道还有多少未读的东西,一条一条跳出来。随时打开页面看两条,随时就关了。另外打个星星作保留也不错,Tag的方式而不是目录树的方式,描述一个feed也更准确方便。加上快捷键好用,一路空格,长短篇控制得都很体贴到位。

不过google reader比较起bloglines,添加feed不是那么好用。尤其是希望订阅被和谐掉的blogspot等blog的feeds的时候,就显出来了。

bloglines

google reader

XSLT中的DISTINCT和GROUP

主要思想,要考虑两个函数,key和generate-id

key, 对于string node返回一个string node (string function)。

generate-id, 对每一个节点(node),生成唯一的字符串标识(unique string identifier)。

参考:

http://www.w3.org/TR/xslt#key

Q: How do I count the number of elements with a given attributevalue?

上篇的翻译: XSLT问答:分组、计数和上下文

数据(内存)对齐

要点

  • 对齐参数一般是数据类型的大小,也可以通过编译指令指定。
  • 数据按照其类型的对齐参数在内存地址中对齐。
  • struct中的成员数据对齐之后,这个struct的sizeof()结果会变大。
  • struct本身的对齐参数等于其成员中对齐参数最大的一个。
  • struct的大小(sizeof)是其对齐参数的整数倍。
  • 32位系统中,指针类型的大小是4Bytes的,数组是成员的大小与成员的个数相乘。

实验

代码

#include “stdio.h”

// case1. memory alignment
typedef struct S00{
char A;
char a;
char b;
};

typedef struct S11{
unsigned A;
char a;
char b;
};

typedef struct S12{
char a;
int A;
char b;
};
// case2. pointer vs. array
typedef struct S21{
short* a;
};
typedef struct S22{
short a[7];
};
// case3. align as max size of member
// case3. struct as member
typedef struct S31{
S00 s[5];
};
typedef struct S32{
S12 s[5];
};

int main(int argc, char* argv[])
{
printf(”-:-. -:-. -:-. -:-. -:-. -:-. -:-. -:-. \n”);
printf(”sizeof(unsigned):\t%d\n”, sizeof(unsigned));
printf(”sizeof(int):\t%d\n”, sizeof(int));
printf(”sizeof(char):\t%d\n”, sizeof(char));
printf(”sizeof(short):\t%d\n”, sizeof(short));
printf(”sizeof(long):\t%d\n”, sizeof(long));
printf(”-:-. -:-. -:-. -:-. -:-. -:-. -:-. -:-. \n”);
printf(”sizeof(S00):\t%d\n”, sizeof(S00));
printf(”sizeof(S11):\t%d\n”, sizeof(S11));
printf(”sizeof(S12):\t%d\n”, sizeof(S12));
printf(”-:-. -:-. -:-. -:-. -:-. -:-. -:-. -:-. \n”);
printf(”sizeof(S21):\t%d\n”, sizeof(S21));
printf(”sizeof(S22):\t%d\n”, sizeof(S22));
printf(”-:-. -:-. -:-. -:-. -:-. -:-. -:-. -:-. \n”);
printf(”sizeof(S31):\t%d\n”, sizeof(S31));
printf(”sizeof(S32):\t%d\n”, sizeof(S32));
printf(”-:-. -:-. -:-. -:-. -:-. -:-. -:-. -:-. \n”);
return 0;
}

结果

-:-. -:-. -:-. -:-. -:-. -:-. -:-. -:-.
sizeof(unsigned): 4
sizeof(int): 4
sizeof(char): 1
sizeof(short): 2
sizeof(long): 4
-:-. -:-. -:-. -:-. -:-. -:-. -:-. -:-.
sizeof(S00): 3
sizeof(S11): 8
sizeof(S12): 12
-:-. -:-. -:-. -:-. -:-. -:-. -:-. -:-.
sizeof(S21): 4
sizeof(S22): 14
-:-. -:-. -:-. -:-. -:-. -:-. -:-. -:-.
sizeof(S31): 15
sizeof(S32): 60
-:-. -:-. -:-. -:-. -:-. -:-. -:-. -:-.
Press any key to continue

参考

1. 内存对齐 作者 Fang
2. 补课补课,关于C语言中的结构体对齐问题

解决在firefox中word-wrap, word-break的问题

word-wrap:break-word; 和 word-wrap:break-word; 這兩個指令,目前在Firefox瀏覽器裡都還不會有作用。这样长单词在div等容器中就不能强制换行。

发现一个近似的解决办法。就是在需要断行的长单词后面,加上一个汉字或者其他亚洲文字。

比如下面代码在firefox中就不起作用:

<div style=”word-wrap:break-word; word-break:break-all;border: 1px solid black; width:50%;”>
(2R,3R,4R,5S,6S)-2-[(2S,3R,4S,5S)-3,4-dihydroxy-2,5-bis(hydroxymethyl)oxolan-2-yl]oxy-6-(hydroxymethyl)oxane-3,4,5-triol
</div>

(2R,3R,4R,5S,6S)-2-[(2S,3R,4S,5S)-3,4-dihydroxy-2,5-bis(hydroxymethyl)oxolan-2-yl]oxy-6-(hydroxymethyl)oxane-3,4,5-triol

如果在末尾加上一个汉字的标点符号“。”,就没问题了。甚至word-wrap和word-break属性都不需要。

<div style=”border: 1px solid black; width:50%;”>
(2R,3R,4R,5S,6S)-2-[(2S,3R,4S,5S)-3,4-dihydroxy-2,5-bis(hydroxymethyl)oxolan-2-yl]oxy-6-(hydroxymethyl)oxane-3,4,5-triol。
</div>

(2R,3R,4R,5S,6S)-2-[(2S,3R,4S,5S)-3,4-dihydroxy-2,5-bis(hydroxymethyl)oxolan-2-yl]oxy-6-(hydroxymethyl)oxane-3,4,5-triol。

这个中文的句号,在不支持中文的电脑里恐怕不能正常显示。

另外一个属性,overflow: hidden; 会把超出范围的内容隐藏起来,达到保持界面的作用。好处是它是ie mozilla通用的。

Writely.com blogging error

Sorry! Your blog site returned this error:
The request was aborted: The connection was closed unexpectedly.

Mostly time:

405 Method Not Allowed

Writely forum traces on these[1][2], but not solved untile now.

They are part of Google now but not compatible to Blogger.

That’s bad.

富兰克林的13项美德

Blog on 27th Floor拷贝过来。
在此篇的评论中,找到这个pdf ,是一个“每周努力实习一项”用的表格。
然后到www.pocketmod.com下载PDF to PocketMod converter ,打印出来。按照pocketmod的指示,做成一个可以随身携带的小笔记本。

本杰明·富兰克林,美国科学家,政治家,外交家,美国独立宣言和宪法签署人,作家,出版家,成功的印刷厂主。据说这13条美德是他在20岁时自己制定的,每周努力实习一项,到13周后重来一遍。(本来想翻译,仔细看过却觉得不如放在这里学英文)

1. Temperance: Eat not to dullness and drink not to elevation.
节制:不要吃得像个傻子,也不要喝得飘飘然。

2. Silence: Speak not but what may benefit others or yourself. Avoid trifling conversation.
沉默:只说那些能让他人或自己受益的话。避免闲聊。

3. Order: Let all your things have their places. Let each part of your business have its time.
秩序:让东西各归其位。给自己的事务安排好时间。

4. Resolution: Resolve to perform what you ought. Perform without fail what you resolve.
决心:下定决心做你应该做的。把要解决的问题成功解决掉。

5. Frugality: Make no expense but to do good to others or yourself: i.e. Waste nothing.
节俭:只花对他人或自己有益处的钱,就是说不要浪费任何东西。

6. Industry: Lose no time. Be always employed in something useful. Cut off all unnecessary actions.
勤奋:不要浪费时间。总应该有些有用的事来做。取消一切不必要的活动。

7. Sincerity: Use no hurtful deceit. Think innocently and justly; and, if you speak, speak accordingly.
诚实:不要恶意骗人。以善意和公正为思考的出发点;而且说话也应如此。

8. Justice: Wrong none, by doing injuries or omitting the benefits that are your duty.
正当:不应当去伤害人或因失职而使利益受损。

9. Moderation: Avoid extremes. Forbear resenting injuries so much as you think they deserve.
适度:避免极端。克制怨恨会带来多大的伤害仅在自己一念之间。

10. Cleanliness: Tolerate no uncleanness in body, clothes or habitation.
整洁:不可容忍身体、衣服和住所的污秽。

11. Chastity: Rarely use venery but for health or offspring; Never to dullness, weakness, or the injury of your own or another’s peace or reputation.
贞洁:仅为健康和生育的目的行房;不要在此事上犯傻,也不要软弱,更不要有损于自己或他人的平静与名声。

12. Tranquility: Be not disturbed at trifles, or at accidents common or unavoidable.
冷静:不要让琐事,普通或不可避免的事故来扰乱自己。

13. Humility: Imitate Jesus and Socrates.
谦逊:向耶酥和苏格拉底学习。

Next Page »

Random posts

  • 有道理
  • windows search 4.0预览版发布
  • 我的1997和2007
  • 百度完犊子了
  • 票贩子是如何炼成的?