The Rock

a geek's secret garden

深入C++类库之cstring (string.h)—-memcpy

void * memcpy ( void * destination, const void * source, size_t num );

Copy block of memory

Copies the values of num bytes from the location pointed by source directly to the memory block pointed by destination.

The underlying type of the objects pointed by both the source and destination pointers are irrelevant for this function; The result is a binary copy of the data.

The function does not check for any terminating null character in source – it always copies exactly num bytes.

To avoid overflows, the size of the arrays pointed by both the destination and source parameters, shall be at least num bytes, and should not overlap (for overlapping memory blocks, memmove is a safer approach).

Parameters

destination
Pointer to the destination array where the content is to be copied, type-casted to a pointer of type void*.
source
Pointer to the source of data to be copied, type-casted to a pointer of type void*.
num
Number of bytes to copy.

Return Value

destination is returned.

Example

/* memcpy example */
#include <stdio.h>
#include <string.h>

int main ()
{
char str1[]="Sample string";
char str2[40];
char str3[40];
memcpy (str2,str1,strlen(str1)+1);
memcpy (str3,"copy successful",16);
printf ("str1: %s\nstr2: %s\nstr3: %s\n",str1,str2,str3);
return 0;
}

Output:

str1: Sample string
str2: Sample string
str3: copy successful

Look Inside

void * memcpy (void *destaddr, void *srcaddr, size_t num)
{
  void *dest = destaddr;

  while (num-- > 0)
    *destaddr++ = *srcaddr++;
  return dest;
}
14 一月 2010 at 14:07 - Comments

Pranav Mistry: The thrilling potential of Sixth Sense technology

11 一月 2010 at 17:04 - Comments

关于周二组会的Presentation的总结

做了一次有生以来最长的全英文的presentation,虽然对困难早有思想准备,但是会上的一些问题还是暴露了我对项目的理解不够深入,现总结如下:

1.需要了解wuala在做删除时所采取的策略,因为wuala是商业系统,无论出于安全考虑或者是商业秘密的考虑,很难获取它的技术细节,但我直觉上,我猜想,wuala的删除策略还是通过广播方式进行的。

2.要进一步深入了解wuala是如何统计节点的上线时间的,wuala号称是没有集中式服务器的,那么作为一个storage node,它因为会直接连接最近的super node,所以,统计他的上线时间是不困难的,但,问题是做为一个client node,如何统计他们的上线时间是否符合要求?我觉得完全不能通过分布式方法来实现,或者wuala会接受一个client node贡献自己的本地硬盘而成为storage node,然后,在成为storage node之后,通过super node来进行考察,是否其是一个合格的stoage node。需要进一步找资料去证实这种猜测

3.开始挑选核心模块进行实现,边做边理解系统可能是唯一的方法。资料实在是很有限。

6 一月 2010 at 21:25 - Comments

Virtual Box 上Gentoo的快速安装

令人窒息的考试周后,我终于迎来了我亲爱的圣诞假期,但是,我喜爱折腾的个性注定了要让我的假期生活过的更加折腾和拧巴。考试完,补充了两天睡眠,算是把这一学期来欠的睡眠帐给还上,然后就想着怎么折腾了。第一个目标,我盯上了Gentoo,为啥选Gentoo来折腾,其实也很简单,因为这学期给Windows折腾的够呛,准备在下学期将Windows给判个死缓,其实平时用Ubuntu也已经相当不错了,但是自从知道豆瓣的后台是用Gentoo架的,而且最近豆瓣也即将开源它的doubandb了,到时候哪里折腾个山寨豆瓣也是蛮好玩的一件事情。再者,Gentoo标榜高度定制化和它提供的高度自由性以及从源码编译内核的挑战也是我蠢蠢欲动的原因之一。好吧,闲言少叙,我们书归正传, Let’s Get Start!!

首先,要安装Gentoo,你有两种选择,一种你可以选择mini iso来安装,也可以通过下载Live CD来安装。其实两者的安装过程基本相同,最大的区别就在于,mini iso只有大约80M左右的大小,而Live CD接近2.6G的大小。如果你的网速不像中大IE的网络那么牛的话建议还是下mini iso比较靠谱,我安装是用Live CD进行的,下载也只用了大约10来分钟,这里不得不赞下IE的网速。顺便提句,我这边的安装是带网络的安装方法,如果是要进行不带网络的安装,请选择下载Live CD并且参考官方的Gentoo 2008.0无网络安装手册

关于怎样使用Virtual Box,如何在Virtual Box中加载iso镜像以及如何设置从虚拟光驱启动引导,我就略过不表了。如果你不会的话,Just Google It.

(1)启动完成之后,系统在Live CD或mini iso的引导下就进入启动界面了:

Gentoo Linux Installation LiveCD                     http://www.gentoo.org
Enter to Boot; F1 for kernels  F2 for options.
boot: gentoo nox

需要注意的是,用mini iso启动的话不需要加nox参数,如果是用LiveCD的话必须加上该参数,防止从CD启动之后进入XWindow。

正常情况下,Gentoo会自动检测所需要的模块,自动加载完成,就除去了手动添加模块的繁琐工作

(2)进行磁盘格式化,boot分区分32M,swap分区分512M,剩余的都分给root分区

livecd root # cfdisk /dev/sda
(有界面)

分成下面这样就行了
Disk /dev/sda: 599.9 GB, 599978409984 bytes
255 heads, 63 sectors/track, 72943 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device    Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          12       96358+  83  Linux
/dev/sda2              13         110      787185   82  Linux swap / Solaris
/dev/sda3             111       72943   585031072+  83  Linux

然后格式化
livecd ~ # mke2fs /dev/sda1
livecd ~ # mke2fs -j /dev/sda3
livecd ~ # mkswap /dev/sda2 && swapon /dev/sda2
这里值得一提的是,在VirtualBox中,使用fdisk命令进行分区后,在下面的挂载文件系统中不能成功挂载,mount命令找不到对应的分区。
我还不是很清楚这是由于虚拟机的问题还是其他什么问题导致的。如果有看官知道这是为什么,还望留言赐教。
(3)挂载文件系统
livecd ~ # mount /dev/sda3 /mnt/gentoo 
livecd ~ # mkdir /mnt/gentoo/boot 
livecd ~ # mount /dev/sda1 /mnt/gentoo/boot 
livecd ~ # cd /mnt/gentoo
(4)下载stage3压缩包,并解压说,这里建议使用wget进行下载
livecd gentoo # wget http://gentoo.aditsu.net/releases/x86/current-stage3/stage3-i686-20091222.tar.bz2
livecd gentoo # tar xjpf stage3-i686-20091222.tar.bz2
(5)下载最新的Portage快照并解压缩,这里同样建议使用wget进行下载
livecd gentoo # cd /mnt/gentoo/usr
livecd usr # wget http://gentoo.aditsu.net/snapshots/portage-latest.tar.bz2
livecd usr # tar xjf portage-latest.tar.bz2
(6)切换系统
livecd usr # cd /
livecd / # mount -t proc proc /mnt/gentoo/proc
livecd / # mount -o bind /dev /mnt/gentoo/dev 
livecd / # cp -L /etc/resolv.conf /mnt/gentoo/etc/ 
livecd / # chroot /mnt/gentoo /bin/bash 
livecd / # env-update && source /etc/profile 
>>> Regenerating /etc/ld.so.cache...
(7)设置时区
livecd / # ls /usr/share/zoneinfo 
(以上海为例) 
livecd / # cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 
livecd / # date 
Mon Dec 28 19:07:19 CST 2009
如时间不正确可以使用如下命令进行时间设置
livecd gentoo # date 122819072009 (格式为MMDDhhmmYYYY)
Mon Dec  28 19:07:00 CST 2009
(8)设置主机名和域名
在/etc/conf.d/hostname和/etc/hosts中设置主机名。
livecd / # cd /etc 
livecd etc # echo "127.0.0.1 Austen.geeksquare.net Austen localhost" > hosts 
livecd etc # sed -i -e 's/HOSTNAME.*/HOSTNAME="Austen"/' conf.d/hostname
(使用指定的主机名并检查) 
livecd etc # hostname Austen 
livecd etc # hostname -f
Austen.geeksquare.net
(9)内核配置
安装一个内核源码包(通常为gentoo-sources),配置、编译并拷贝arch/i386/boot/bzImage文件到/boot。
livecd etc # emerge gentoo-sources
livecd etc # cd /usr/src/linux 
livecd linux # make menuconfig 
(配置内核) 
livecd linux # make -j2
(所花的时间很大程度上决定于你所选的选项)
livecd linux # make modules_install 
livecd linux # cp arch/i386/boot/bzImage /boot/kernel
(10)配置系统
编辑/etc/fstab,用实际的分区名代替BOOTROOTSWAP。记得确认一下文件系统是否与所安装的相匹配。

livecd linux # cd /etc 

livecd etc # nano -w fstab 

/dev/sda1   /boot     ext2    noauto,noatime     1 2 

/dev/sda3   /         ext3    noatime            0 1 

/dev/sda2   none      swap    sw                 0 0

(11)配置网络

livecd etc # cd conf.d 

livecd conf.d # echo 'config_eth0=( "192.168.70.52/24" )' >> net 

livecd conf.d # echo 'routes_eth0=( "default via 192.168.70.254" )' >> net 

livecd conf.d # rc-update add net.eth0 default

(12)设置root密码

livecd conf.d # passwd 

New UNIX password: 输入密码 

Retype new UNIX password: 再输入密码 

passwd: password updated successfully

(13)编辑/etc/conf.d/clock以定义前面所使用的时区

livecd conf.d # nano -w /etc/conf.d/clock 

TIMEZONE="Asia/Shanghai"

(14)安装系统日志和cron守护进程

livecd conf.d # emerge syslog-ng vixie-cron

livecd conf.d # rc-update add syslog-ng default 

livecd conf.d # rc-update add vixie-cron default

(15)安装其他系统工具

livecd conf.d # emerge dhcpcd         (如果使用DHCP客户端) 

livecd conf.d # emerge ppp            (如果使用PPPoE ADSL连接)

(16)安装并配置grub

livecd conf.d # emerge grub

livecd conf.d # nano -w /boot/grub/grub.conf

default 0 

timeout 10  

title Gentoo 

root (hd0,0) 

kernel /boot/kernel root=/dev/sda3

livecd conf.d # grub 

Probing devices to guess BIOS drives. This may take a long time.  

grub> root (hd0,0)  

Filesystem type is ext2fs, partition type 0xfd  

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)"...  16 sectors are embedded. 

succeeded  

Running "install /boot/grub/stage1 (hd0) (hd0)1+16 p (hd0,0)/boot/grub/stage2 /boot/ grub/menu.lst"... succeeded Done.  

grub> quit

(17)重启

退出chroot环境,卸载所有文件系统并重启:

livecd conf.d # exit 

livecd / # umount /mnt/gentoo/dev /mnt/gentoo/proc /mnt/gentoo/boot /mnt/gentoo 

livecd / # reboot 

(别忘了取出光盘)
至此,Gentoo的安装已经完成,现在要做的就是进行一些最后的配置,具体可以参考Gentoo官网上的用户手册
稍后奉上Gentoo内核配置的详细说明.To be continued...
29 十二月 2009 at 15:51 - Comments

腾讯副总裁彭志坚:互联网企业国际化面临更大的挑战

在几周前收购Friendster的竞标中,腾讯并非是唯一出局的著名公司,谷歌也被排除在外。据路透社消息,一家还未公开名称的亚洲企业将是Friendster的新东家。

国际化对任何企业都非易事。但是对于因特网公司而言,国际化会更加困难,中国最大的互联网企业腾讯公司的副总裁彭志坚如是认为。正因为此,该公司在 向国外扩展的过程中采取了谨慎的渐进步伐,先向亚洲其他国家发展,然后再去西方市场,一步步来。彭志坚在与沃顿知识在线的一次专访中探讨了这个问题,以及 西方公司希望了解的中国因特网用户的特性。

以下是访谈的剪辑。

沃顿知识在线:全球金融危机对很多公司产生了影响,然而腾讯今年的发展势头仍然迅猛。最近腾讯公布的未经审计的第三季度财报显示,公 司毛利润在23亿人民币(3.43亿美元)左右,同比增长70%,总收入是34亿人民币(4.93亿美元),同比上涨66%。您能否给我们解释一下公司发 展的背景?

彭志坚:对,国际金融危机的确对全世界的经济有很大影响,但是很幸运的是,它对互联网企业的影响相对较小,尤其在中国。但是如美国的谷歌公司还是受到了不小的影响【谷歌今年第三季度财报显示总收入54亿美元,同比增长7%】。

中国的广告行业也受到影响,比如我们的广告增长幅度相对较慢。但是在互联网的主要服务对象,也就是消费者方面的增长还是非常强劲。

我认为这背后有几个原因。第一,中国互联网的渗透率在提高,意味着互联网用户数在提高;第二,消费者在互联网上的花费其实很小——比如我们的很多用 户一个月花8-10元——并没有受到经济危机很大影响。而付费用户的比例也在提高。第三,当经济危机导致失业率上升的时候,人们反而在网络上花费更多的时 间。这就导致了每个用户平均收入的提高。这三个因素,用户量增加,付费用户增加,单个用户消费增加,就使得腾讯能够保持原有的发展势头。

沃顿知识在线:对于中国的因特网行业的未来发展,您认为什么服务有最强的潜力?是游戏,广告,电子商务还是移动服务?

彭志坚:这几个领域都很有潜力。让我们一个个来谈。我认为游戏产业将在未来至少三到四年间继续保持高速增长。移动,现在是一个关键时 刻,因为前几年的发展非常迅猛,但近来减速许多。为什么说现在是关键时刻?因为中国正处于从2G换代到3G的过程中,联网的速度,用户体验和服务质量都将 得到提升。我预计在未来的几年中,我们将看到移动业务的爆炸式增长。

广告是因特网公司最初和最成熟的业务模式了,但是它的增长也较其他模式要缓慢。但是腾讯的广告业务起步很晚,目前广告在我们整个业务中所占比例可能还不到10%,所以我们预期腾讯的广告在未来会有很大的增长空间,因为我们的网站流量越来越大。

最后一个是互联网增值服务。你看美国的情况,虽然美国人不像亚洲人那样习惯于网络生活,但是他们对此已经越来越熟悉。你看美国的三大社交游戏网络Zynga, PlayFish和 Playdom,各自收入早已超过了5亿美元。

沃顿知识在线:腾讯的QQ在中国是最流行的在线聊天工具。从大城市到农村的男女老幼,甚至一些公司也拥有QQ账号,QQ为何能如此成功?

彭志坚:我可能不是一个最适合回答这个问题的人,但是我会尽我所知来分享我的想法。首先,QQ满足了很多用户的需要。多年以前,当通讯技术以及移动通讯网络都还未如此普及的时候,QQ的出现填补了这一空缺。

另一方面,腾讯的企业文化鼓励创新。在最初的成功之后,腾讯的管理者保持了那种谦逊、勤奋和专注的精神,不断提高产品质量和用户体验。当你的产品能够满足用户需求,并能提升用户体验,你就会得到好的结果。这就是为什么QQ获得了成功。

沃顿知识在线:你提到腾讯的工作环境造就了企业的快速发展,使其能更快地抓住每个商机,能否解释一下这对腾讯公司有何意义?

彭志坚:这是腾讯文化的一部分。我们有一个简单的工作环境,能够使得每个人专注于工作。另外,如果这个企业文化很注重沟通,大家愿意把创意和他人分享,这对于创新是一个重要的启动力。如果你不能有很开放的环境,那么你的企业就很难有创新的产品。

沃顿知识在线:西方公司应该了解中国因特网用户的哪些特点?

彭志坚:中国互联网用户非常年轻——近60%的网民大约在14到25岁之间。这是一件好事,因为年轻人有越来越多的机会接触越来越多的信息。这对中国整个经济的发展也是件好事,因为因特网帮助年轻人开阔视野,拥有更多的交流渠道。我认为这个年轻的趋势将会持续。

另外,与美国用户相比较,中国网络用户可能更偏重于网上的交流和娱乐,在获取知识方面的比例要少一些。在中国,在线聊天工具市场非常发达,而在美国,使用YAHOO或MSN的频率相对要低一些。

沃顿知识在线:能跟我们谈谈贵公司国际化的过程吗?

彭志坚:我们的国际化刚刚开始,还谈不上过程。我的观点是,互联网企业的国际化比其他传统行业要难得多。我们从两个角度来看,首先是 技术壁垒,其次是文化敏感度。如果你看微软OFFICE软件,它们在世界各地的产品基本相同,只是语言版本不同。而英特尔在各国销售的芯片都一摸一样。所 以说他们的产品要进入其他市场,其文化敏感度很低,但技术壁垒很高。

对于互联网企业而言,技术壁垒比较低,比如,eBay和淘宝、谷歌和百度的模式基本一致。但是同时,文化敏感度非常高。这使得互联网企业的国际化扩展非常困难。许多美国互联网公司在其他国家扩展业务时就遇到了挑战。

腾讯在尝试全球化的发展,但是我们非常谨慎,希望用合适的方式、计划和步调扩展国际市场,避免因为好大喜功而犯重大的错误。由于互联网企业的高文化 敏感度,我们先在文化上与中国更接近的亚洲国家,比如越南和东南亚其他国家尝试,当我们积累起一定经验时,将进一步考虑美国市场。

另一方面,当我们向其他市场迈进时,总是会寻找当地的合作伙伴。当你考虑到文化敏感度的因素时,当地合作伙伴对你了解当地的文化、市场、用户以及其他方面至关重要。

沃顿知识在线:贵司位于美国硅谷,波士顿和其他国家的办公室担负着什么职责?

彭志坚:我们在越南和印度的办事处都由当地的合作伙伴主导业务。我们在美国硅谷有一个很小的办公室,负责把小部分产品在美国市场实验,看怎样才能适合美国用户的口味。在波士顿,我们有一个小工作室为美国和中国用户开发游戏。

沃顿知识在线:最近参加招聘会的沃顿毕业生中,几乎所有人都尝试过QQ,但是实际使用的只有20%。这个比例对于你们意味着什么?

彭志坚:沃顿毕业生这个样本对于腾讯来说可能不是典型代表。在中国的在线聊天工具市场,腾讯有大约90%的市场,其余的市场参与者有MSN、淘宝旺旺以及51呱呱。

但是我们在大城市面临一个比较大的挑战,即在北京、上海、广州和深圳这些城市,许多大学毕业参加工作的白领倾向于使用MSN。这里面的逻辑可以理 解:他们加入外资企业之后,老板大多使用MSN;因此他们也开始转向,然后他们的新同事和老同学也开始转向MSN。这是我们面临的一个挑战。我们正在想办 法保留住这些高端用户。

在大城市之外,不管什么年龄的人都用QQ。另外,这些大城市用户在使用MSN的同时也在使用QQ,因为他要跟他的高中同学或家人保持联系。所以这取决于你的生活圈子在哪里。可能你有两个生活圈子,你就要用两个IM工具。

很重要的一点是,腾讯要随着用户的成长,提供更好的服务;我们要满足他们在成长中产生的新需求。当他们开始职业生涯之后,他们需要一个更加职业化的IM工具。如果我们能够很好地满足他们的成长需求,他们就可能会留在我们这里。

沃顿知识在线:说到竞争,作为新经济代表的因特网行业在争夺用户和广告资源方面对传统媒体形成了竞争。您怎么看这个问题?是纯粹的“达尔文学说”,还是并存而不冲突的格局?

彭志坚:互联网的出现的确取代了一些东西,就如汽车和火车的出现取代了马车,飞机出现后,大家很少乘帆船漂洋过海。但从更深入的角度来说,我觉得传统经济和新经济还是一个融合的过程,尤其是信息流和物流都将变得更有效率。

比如,当电子商务刚出现时,大家都说这是一个鼠标经济,但是从本质上说,电子商务其实是一个“鼠标加砖头”的经济,是把传统的生意和新经济相结合的 一个过程。如果你能够把物流和网络服务结合起来,你的业务将非常有竞争优势。互联网从根本上是传统经济的一种工具,它将会取代一些东西,让传统经济更加有 效率。

沃顿知识在线:您提到,腾讯员工的平均年龄是28岁,CEO马化腾也只有38岁,这是否会给人才管理带来一定的挑战?

彭志坚:最大的挑战是人才的不足。当然我们的员工非常优秀,管理团队也很优秀。但是随着公司的快速成长,需要更多优秀人才的加入。在 这方面我们也在积极应对。第一个措施就是加大招聘范围,今年我们在国内招聘了大约2000名大学生和许多有工作经验的人才。这次我们来美国也是首次到美国 一流的商学院招聘毕业生。

另一方面,或是说更重要的一方面是我们投入许多精力培养内部人才,我们建立了一个腾讯学院,为员工提供培训。比如,今年全公司的每个经理人都要为他的下属做培训。我们希望使培训变成一种公司文化,让每个人都能去帮助自己下属的成长。

沃顿知识在线:这是腾讯第一次到美国来招聘,您的体会如何?

彭志坚:我去了七所大学包括斯坦福,哈佛,麻省理工和沃顿等等,反响都非常热烈。来之前我们在有些学校收到的简历不是很多,但在介绍 会之后我收到很多简历。比如在我昨天【沃顿的介绍会】之后就收到十多份简历,这段时间我大约面试了70个学生。但是我们的招聘过程非常严谨。当我们找到一 些合适的候选人之后,会继续与这些候选人进行交流,也希望他们中的一部分能加入腾讯大家庭,一起为腾讯的长远发展,为中国互联网的长远发展而努力。

转载自:http://www.knowledgeatwharton.com.cn/index.cfm?fa=viewfeature&languageid=4&articleid=2153

我的评论:

其实一直觉得腾讯这个公司给人的印象都比较慢,这大致和他们企业的文化有关,毕竟做一个服务上亿活跃用户的互联网企业,确实需要对自己的每一步战略都进行反复斟酌,毕竟,一旦失误,损失将是无法挽回的。所以,慢点,但至少不会犯错误。很多企业死在了创业之后的多元化和国际化上,这些都是前车之鉴,至少目前看来,腾讯走的非常好。虽然慢,但却是实实在在的前进。不玩虚的,那么至少以腾讯目前用户群,平台整合的能力及发展势头,国际市场不好说,但起码在可预见的将来,中国13亿人口的市场都会是腾讯的。

10 十二月 2009 at 13:54 - Comments

程序员修炼之道,十年之后

概要
10 年之前,Andy Hunt和我合著了《程序员修炼之道》(The Pragmatic Programmer)。自那以后的10年间,软件行业发生了翻天覆地的变化:敏捷软件开发盛行,测试和测试驱动开发在很多开发人员的工作中扮演着重要的角色,而且软件也越来越趋向云计算和多核设备。那么以前的那些建议还是否适用?如果我们今天重写此书,需要做哪些改变?今天,一个讲求实效的程序员正在做些什么?本演讲视频录制于AgileChina 2009。

个人简介
Dave Thomas,敏捷开发权威人士,敏捷宣言的创始人之一,而且还是多本畅销书的作者,其书籍《The Pragmatic Programmer》(中文版《程序员修炼之道》)曾获第14届Jolt图书大奖。另外Dave Thomas在语言方面很有造诣,并和Andrew Hunt合作出版了Programming Ruby,和Rails on Ruby创始人DHH合作出版了 Agile Web Development with Rails等。

关于会议
敏捷中国大会是国内敏捷技术领域最高水平的大会。今年的敏捷中国大会(AgileChina 2009),以Pragmatic Agile为主题,参会者以高端开发者和技术管理者为主,融合管理和工程实践,推广全面敏捷之路。

视频地址:http://www.infoq.com/cn/presentations/dt-pragmatic-programmer

9 十二月 2009 at 13:35 - Comments

Google Wave Developer Preview at Google IO 2009

26 十一月 2009 at 23:16 - Comments

‘You’ve got to find what you love,’ Jobs says

 

This is the text of the Commencement address by Steve Jobs, CEO of Apple Computer and of Pixar Animation Studios, delivered on June 12, 2005.

I am honored to be with you today at your commencement from one of the finest universities in the world. I never graduated from college. Truth be told, this is the closest I’ve ever gotten to a college graduation. Today I want to tell you three stories from my life. That’s it. No big deal. Just three stories.

The first story is about connecting the dots.

I dropped out of Reed College after the first 6 months, but then stayed around as a drop-in for another 18 months or so before I really quit. So why did I drop out?

It started before I was born. My biological mother was a young, unwed college graduate student, and she decided to put me up for adoption. She felt very strongly that I should be adopted by college graduates, so everything was all set for me to be adopted at birth by a lawyer and his wife. Except that when I popped out they decided at the last minute that they really wanted a girl. So my parents, who were on a waiting list, got a call in the middle of the night asking: “We have an unexpected baby boy; do you want him?” They said: “Of course.” My biological mother later found out that my mother had never graduated from college and that my father had never graduated from high school. She refused to sign the final adoption papers. She only relented a few months later when my parents promised that I would someday go to college.

And 17 years later I did go to college. But I naively chose a college that was almost as expensive as Stanford, and all of my working-class parents’ savings were being spent on my college tuition. After six months, I couldn’t see the value in it. I had no idea what I wanted to do with my life and no idea how college was going to help me figure it out. And here I was spending all of the money my parents had saved their entire life. So I decided to drop out and trust that it would all work out OK. It was pretty scary at the time, but looking back it was one of the best decisions I ever made. The minute I dropped out I could stop taking the required classes that didn’t interest me, and begin dropping in on the ones that looked interesting.

It wasn’t all romantic. I didn’t have a dorm room, so I slept on the floor in friends’ rooms, I returned coke bottles for the 5¢ deposits to buy food with, and I would walk the 7 miles across town every Sunday night to get one good meal a week at the Hare Krishna temple. I loved it. And much of what I stumbled into by following my curiosity and intuition turned out to be priceless later on. Let me give you one example:

Reed College at that time offered perhaps the best calligraphy instruction in the country. Throughout the campus every poster, every label on every drawer, was beautifully hand calligraphed. Because I had dropped out and didn’t have to take the normal classes, I decided to take a calligraphy class to learn how to do this. I learned about serif and san serif typefaces, about varying the amount of space between different letter combinations, about what makes great typography great. It was beautiful, historical, artistically subtle in a way that science can’t capture, and I found it fascinating.

None of this had even a hope of any practical application in my life. But ten years later, when we were designing the first Macintosh computer, it all came back to me. And we designed it all into the Mac. It was the first computer with beautiful typography. If I had never dropped in on that single course in college, the Mac would have never had multiple typefaces or proportionally spaced fonts. And since Windows just copied the Mac, its likely that no personal computer would have them. If I had never dropped out, I would have never dropped in on this calligraphy class, and personal computers might not have the wonderful typography that they do. Of course it was impossible to connect the dots looking forward when I was in college. But it was very, very clear looking backwards ten years later.

Again, you can’t connect the dots looking forward; you can only connect them looking backwards. So you have to trust that the dots will somehow connect in your future. You have to trust in something — your gut, destiny, life, karma, whatever. This approach has never let me down, and it has made all the difference in my life.

My second story is about love and loss.

I was lucky — I found what I loved to do early in life. Woz and I started Apple in my parents garage when I was 20. We worked hard, and in 10 years Apple had grown from just the two of us in a garage into a $2 billion company with over 4000 employees. We had just released our finest creation — the Macintosh — a year earlier, and I had just turned 30. And then I got fired. How can you get fired from a company you started? Well, as Apple grew we hired someone who I thought was very talented to run the company with me, and for the first year or so things went well. But then our visions of the future began to diverge and eventually we had a falling out. When we did, our Board of Directors sided with him. So at 30 I was out. And very publicly out. What had been the focus of my entire adult life was gone, and it was devastating.

I really didn’t know what to do for a few months. I felt that I had let the previous generation of entrepreneurs down – that I had dropped the baton as it was being passed to me. I met with David Packard and Bob Noyce and tried to apologize for screwing up so badly. I was a very public failure, and I even thought about running away from the valley. But something slowly began to dawn on me — I still loved what I did. The turn of events at Apple had not changed that one bit. I had been rejected, but I was still in love. And so I decided to start over.

I didn’t see it then, but it turned out that getting fired from Apple was the best thing that could have ever happened to me. The heaviness of being successful was replaced by the lightness of being a beginner again, less sure about everything. It freed me to enter one of the most creative periods of my life.

During the next five years, I started a company named NeXT, another company named Pixar, and fell in love with an amazing woman who would become my wife. Pixar went on to create the worlds first computer animated feature film, Toy Story, and is now the most successful animation studio in the world. In a remarkable turn of events, Apple bought NeXT, I returned to Apple, and the technology we developed at NeXT is at the heart of Apple’s current renaissance. And Laurene and I have a wonderful family together.

I’m pretty sure none of this would have happened if I hadn’t been fired from Apple. It was awful tasting medicine, but I guess the patient needed it. Sometimes life hits you in the head with a brick. Don’t lose faith. I’m convinced that the only thing that kept me going was that I loved what I did. You’ve got to find what you love. And that is as true for your work as it is for your lovers. Your work is going to fill a large part of your life, and the only way to be truly satisfied is to do what you believe is great work. And the only way to do great work is to love what you do. If you haven’t found it yet, keep looking. Don’t settle. As with all matters of the heart, you’ll know when you find it. And, like any great relationship, it just gets better and better as the years roll on. So keep looking until you find it. Don’t settle.

My third story is about death.

When I was 17, I read a quote that went something like: “If you live each day as if it was your last, someday you’ll most certainly be right.” It made an impression on me, and since then, for the past 33 years, I have looked in the mirror every morning and asked myself: “If today were the last day of my life, would I want to do what I am about to do today?” And whenever the answer has been “No” for too many days in a row, I know I need to change something.

Remembering that I’ll be dead soon is the most important tool I’ve ever encountered to help me make the big choices in life. Because almost everything — all external expectations, all pride, all fear of embarrassment or failure – these things just fall away in the face of death, leaving only what is truly important. Remembering that you are going to die is the best way I know to avoid the trap of thinking you have something to lose. You are already naked. There is no reason not to follow your heart.

About a year ago I was diagnosed with cancer. I had a scan at 7:30 in the morning, and it clearly showed a tumor on my pancreas. I didn’t even know what a pancreas was. The doctors told me this was almost certainly a type of cancer that is incurable, and that I should expect to live no longer than three to six months. My doctor advised me to go home and get my affairs in order, which is doctor’s code for prepare to die. It means to try to tell your kids everything you thought you’d have the next 10 years to tell them in just a few months. It means to make sure everything is buttoned up so that it will be as easy as possible for your family. It means to say your goodbyes.

I lived with that diagnosis all day. Later that evening I had a biopsy, where they stuck an endoscope down my throat, through my stomach and into my intestines, put a needle into my pancreas and got a few cells from the tumor. I was sedated, but my wife, who was there, told me that when they viewed the cells under a microscope the doctors started crying because it turned out to be a very rare form of pancreatic cancer that is curable with surgery. I had the surgery and I’m fine now.

This was the closest I’ve been to facing death, and I hope its the closest I get for a few more decades. Having lived through it, I can now say this to you with a bit more certainty than when death was a useful but purely intellectual concept:

No one wants to die. Even people who want to go to heaven don’t want to die to get there. And yet death is the destination we all share. No one has ever escaped it. And that is as it should be, because Death is very likely the single best invention of Life. It is Life’s change agent. It clears out the old to make way for the new. Right now the new is you, but someday not too long from now, you will gradually become the old and be cleared away. Sorry to be so dramatic, but it is quite true.

Your time is limited, so don’t waste it living someone else’s life. Don’t be trapped by dogma — which is living with the results of other people’s thinking. Don’t let the noise of others’ opinions drown out your own inner voice. And most important, have the courage to follow your heart and intuition. They somehow already know what you truly want to become. Everything else is secondary.

When I was young, there was an amazing publication called The Whole Earth Catalog, which was one of the bibles of my generation. It was created by a fellow named Stewart Brand not far from here in Menlo Park, and he brought it to life with his poetic touch. This was in the late 1960′s, before personal computers and desktop publishing, so it was all made with typewriters, scissors, and polaroid cameras. It was sort of like Google in paperback form, 35 years before Google came along: it was idealistic, and overflowing with neat tools and great notions.

Stewart and his team put out several issues of The Whole Earth Catalog, and then when it had run its course, they put out a final issue. It was the mid-1970s, and I was your age. On the back cover of their final issue was a photograph of an early morning country road, the kind you might find yourself hitchhiking on if you were so adventurous. Beneath it were the words: “Stay Hungry. Stay Foolish.” It was their farewell message as they signed off. Stay Hungry. Stay Foolish. And I have always wished that for myself. And now, as you graduate to begin anew, I wish that for you.

Stay Hungry. Stay Foolish.

Thank you all very much.

 

今天,有荣幸来到各位从世界上最好的学校之一毕业的毕业典礼上。我从来没从大学毕业。说实话,这是我离大学毕业最近的一刻。今天,我只说三个故事,不谈大道理,三个故事就好。

第一个故事,是关于人生中的点点滴滴怎么串连在一起。

我在里德学院(Reed college)待了六个月就办休学了。到我退学前,一共休学了十八个月。那么,我为什么休学?

这得从我出生前讲起。我的亲生母亲当时是个研究生,年轻未婚妈妈,她决定让别人收养我。她强烈觉得应该让有大学毕业的人收养我,所以我出生时,她就 准备让我被一对律师夫妇收养。但是这对夫妻到了最后一刻反悔了,他们想收养女孩。所以在等待收养名单上的一对夫妻,我的养父母,在一天半夜里接到一通电 话,问他们「有一名意外出生的男孩,你们要认养他吗?」而他们的回答是「当然要」。后来,我的生母发现,我现在的妈妈从来没有大学毕业,我现在的爸爸则连 高中毕业也没有。她拒绝在认养文件上做最后签字。直到几个月后,我的养父母同意将来一定会让我上大学,她才软化态度。

十七年后,我上大学了。但是当时我无知选了一所学费几乎跟史丹佛一样贵的大学,我那工人阶级的父母所有积蓄都花在我的学费上。六个月后,我看不出念 这个书的价值何在。那时候,我不知道这辈子要干什么,也不知道念大学能对我有什么帮助,而且我为了念这个书,花光了我父母这辈子的所有积蓄,所以我决定休 学,相信船到桥头自然直。当时这个决定看来相当可怕,可是现在看来,那是我这辈子做过最好的决定之一。当我休学之后,我再也不用上我没兴趣的必修课,把时 间拿去听那些我有兴趣的课。

这一点也不浪漫。我没有宿舍,所以我睡在友人家里的地板上,靠着回收可乐空罐的五先令退费买吃的,每个星期天晚上得走七里的路绕过大半个镇去印度教 的 Hare Krishna神庙吃顿好料。我喜欢Hare Krishna神庙的好料。追寻我的好奇与直觉,我所驻足的大部分事物,后来看来都成了无价之宝。举例来说:

当时里德学院有着大概是全国最好的书法指导。在整个校园内的每一张海报上,每个抽屉的标签上,都是美丽的手写字。因为我休学了,可以不照正常选课程 序来,所以我跑去学书法。我学了serif与san serif字体,学到在不同字母组合间变更字间距,学到活版印刷伟大的地方。书法的美好、历史感与艺术感是科学所无法捕捉的,我觉得那很迷人。

我没预期过学的这些东西能在我生活中起些什么实际作用,不过十年后,当我在设计第一台麦金塔时,我想起了当时所学的东西,所以把这些东西都设计进了 麦金塔里,这是第一台能印刷出漂亮东西的计算机。如果我没沉溺于那样一门课里,麦金塔可能就不会有多重字体跟变间距字体了。又因为Windows抄袭了麦 金塔的使用方式,如果当年我没这样做,大概世界上所有的个人计算机都不会有这些东西,印不出现在我们看到的漂亮的字来了。当然,当我还在大学里时,不可能 把这些点点滴滴预先串在一起,但是这在十年后回顾,就显得非常清楚。

我再说一次,你不能预先把点点滴滴串在一起;唯有未来回顾时,你才会明白那些点点滴滴是如何串在一起的。所以你得相信,你现在所体会的东西,将来多 少会连接在一块。你得信任某个东西,直觉也好,命运也好,生命也好,或者业力。这种作法从来没让我失望,也让我的人生整个不同起来。

我的第二个故事,有关爱与失去。

我好运-年轻时就发现自己爱做什么事。我二十岁时,跟Steve Wozniak在我爸妈的车库里开始了苹果计算机的事业。我们拼命工作,苹果计算机在十年间从一间车库里的两个小伙子扩展成了一家员工超过四千人、市价二 十亿美金的公司,在那之前一年推出了我们最棒的作品-麦金塔,而我才刚迈入人生的第三十个年头,然后被炒鱿鱼。要怎么让自己创办的公司炒自己鱿鱼?好吧, 当苹果计算机成长后,我请了一个我以为他在经营公司上很有才干的家伙来,他在头几年也确实干得不错。可是我们对未来的愿景不同,最后只好分道扬镳,董事会 站在他那边,炒了我鱿鱼,公开把我请了出去。曾经是我整个成年生活重心的东西不见了,令我不知所措。

有几个月,我实在不知道要干什么好。我觉得我令企业界的前辈们失望-我把他们交给我的接力棒弄丢了。我见了创办HP的David Packard跟创办Intel的Bob Noyce,跟他们说我很抱歉把事情搞砸得很厉害了。我成了公众的非常负面示范,我甚至想要离开硅谷。但是渐渐的,我发现,我还是喜爱着我做过的事情,在 苹果的日子经历的事件没有丝毫改变我爱做的事。我被否定了,可是我还是爱做那些事情,所以我决定从头来过。

当时我没发现,但是现在看来,被苹果计算机开除,是我所经历过最好的事情。成功的沉重被从头来过的轻松所取代,每件事情都不那么确定,让我自由进入这辈子最有创意的年代。

接下来五年,我开了一家叫做NeXT的公司,又开一家叫做Pixar的公司,也跟后来的老婆谈起了恋爱。Pixar接着制作了世界上第一部全计算机 动画电影,玩具总动员,现在是世界上最成功的动画制作公司。然后,苹果计算机买下了NeXT,我回到了苹果,我们在NeXT发展的技术成了苹果计算机后来 复兴的核心。我也有了个美妙的家庭。

我很确定,如果当年苹果计算机没开除我,就不会发生这些事情。这帖药很苦口,可是我想苹果计算机这个病人需要这帖药。有时候,人生会用砖头打你的 头。不要丧失信心。我确信,我爱我所做的事情,这就是这些年来让我继续走下去的唯一理由。你得找出你爱的,工作上是如此,对情人也是如此。你的工作将填满 你的一大块人生,唯一获得真正满足的方法就是做你相信是伟大的工作,而唯一做伟大工作的方法是爱你所做的事。如果你还没找到这些事,继续找,别停顿。尽你 全心全力,你知道你一定会找到。而且,如同任何伟大的关系,事情只会随着时间愈来愈好。所以,在你找到之前,继续找,别停顿。

我的第三个故事,关于死亡。

当我十七岁时,我读到一则格言,好像是「把每一天都当成生命中的最后一天,你就会轻松自在。」这对我影响深远,在过去33年里,我每天早上都会照镜 子,自问:「如果今天是此生最后一日,我今天要干些什么?」每当我连续太多天都得到一个「没事做」的答案时,我就知道我必须有所变革了。

提醒自己快死了,是我在人生中下重大决定时,所用过最重要的工具。因为几乎每件事-所有外界期望、所有名誉、所有对困窘或失败的恐惧-在面对死亡 时,都消失了,只有最重要的东西才会留下。提醒自己快死了,是我所知避免掉入自己有东西要失去了的陷阱里最好的方法。人生不带来,死不带去,没什么道理不 顺心而为。

一年前,我被诊断出癌症。我在早上七点半作断层扫描,在胰脏清楚出现一个肿瘤,我连胰脏是什么都不知道。医生告诉我,那几乎可以确定是一种不治之 症,我大概活不到三到六个月了。医生建议我回家,好好跟亲人们聚一聚,这是医生对临终病人的标准建议。那代表你得试着在几个月内把你将来十年想跟小孩讲的 话讲完。那代表你得把每件事情搞定,家人才会尽量轻松。那代表你得跟人说再见了。

我整天想着那个诊断结果,那天晚上做了一次切片,从喉咙伸入一个内视镜,从胃进肠子,插了根针进胰脏,取了一些肿瘤细胞出来。我打了镇静剂,不醒人 事,但是我老婆在场。她后来跟我说,当医生们用显微镜看过那些细胞后,他们都哭了,因为那是非常少见的一种胰脏癌,可以用手术治好。所以我接受了手术,康复了。

这是我最接近死亡的时候,我希望那会继续是未来几十年内最接近的一次。经历此事后,我可以比之前死亡只是抽象概念时要更肯定告诉你们下面这些:

没有人想死。即使那些想上天堂的人,也想活着上天堂。但是死亡是我们共有的目的地,没有人逃得过。这是注定的,因为死亡简直就是生命中最棒的发明, 是生命变化的媒介,送走老人们,给新生代留下空间。现在你们是新生代,但是不久的将来,你们也会逐渐变老,被送出人生的舞台。抱歉讲得这么戏剧化,但是这 是真的。

你们的时间有限,所以不要浪费时间活在别人的生活里。不要被信条所惑-盲从信条就是活在别人思考结果里。不要让别人的意见淹没了你内在的心声。最重要的,拥有跟随内心与直觉的勇气,你的内心与直觉多少已经知道你真正想要成为什么样的人。任何其它事物都是次要的。

在我年轻时,有本神奇的杂志叫做Whole Earth Catalog,当年我们很迷这本杂志。那是一位住在离这不远的Menlo Park的Stewart Brand发行的,他把杂志办得很有诗意。那是1960年代末期,个人计算机跟桌上出版还没发明,所有内容都是打字机、剪刀跟拍立得相机做出来的。杂志内 容有点像印在纸上的Google,在Google出现之前35年就有了:理想化,充满新奇工具与神奇的注记。

Stewart跟他的出版团队出了好几期Whole Earth Catalog,然后出了停刊号。当时是1970年代中期,我正是你们现在这个年龄的时候。在停刊号的封底,有张早晨乡间小路的照片,那种你去爬山时会经过的乡间小路。在照片下有行小字:

求知若饥,虚心若愚。

那是他们亲笔写下的告别讯息,我总是以此自许。当你们毕业,展开新生活,我也以此期许你们。

求知若饥,虚心若愚。

非常谢谢大家。

原文地址:http://news.stanford.edu/news/2005/june15/jobs-061505.html

译文转自yeeyan.com: http://www.yeeyan.com/articles/view/dding/76

2 十一月 2009 at 01:39 - Comments

即使再忙也要每天坚持写博客

        今天师兄问了我几个Linux快捷键的问题。我最近一直在Windows下面做些开发,有段时间没有搞Linux了,我一时想不起。我说,这样吧。你去我以前的那个blog上看下吧,我记得我做了笔记的。师兄在我的博客上找到了他需要的内容,同时,他说了句,你做了那么多笔记的啊。这是我第一次因为我写博客而使别人受益,其实我当时在blogger上写博客,本没有打算有人会去看我写的这些东西。

        说起那个不幸的博客,如果要不是GFW的缘故我可能会从07年一直坚持下来,可惜中间中断了很久都没有写。实在是颇为遗憾的。而且,我一直以为我原先写的那些东西没有一点价值,只是自己的学习笔记,所以转到这个博客后,也实在没有啥动力去导入以前的文章。现在想想实在是很愚蠢,知识时代,最重要的就是知识发分享,两人交换idea,那就有两个idea了,如果不交换,那你就永远都只有一个。所以,我希望从今天起,就算自己再忙,也要每天写点东西记录自己每天所学,算不上是什么旷世奇文,但求有天有人能从我的这些只言片语中找到一点他想要的东西。那也不枉我每天辛苦写博了。

1 十一月 2009 at 02:24 - Comments

Linux虚拟化:10个让你不得不爱的理由

  对于很多云技术供应商、虚拟软件生产商以及大型IT公司来说,Linux是他们首选的虚拟化平台。的确,Linux虚拟化有很多非常诱人的优点,让你无法割舍。以下就列出了Linux虚拟化的10大优势。   

10.大厂商支持   

    VMware、思杰、红帽和Ubuntu等大型软件厂商都选用Linux作为各自虚拟化技术的平台。为什么呢?原因有很多,但是最主要的原因在于Linux的性能。   

9.价格   

     是的,我知道我是在白费口舌,但你必须承认,价格确实是一大卖点。物美价廉永远都是人们购买产品时的首要原则。尤其是在目前全球经济低迷,各大公司纷纷削减IT预算的条件下,价格是人们做出购买决策的一个重要因素。   

8.性能   

     对大多数人来说,阻碍他们从物理机过渡到虚拟机的头号障碍就是性能。不过,Hypervisor技术和Linux的完美组合使得虚拟技术的性能能够与本地物理机性能相媲美。此外。SAN存储以及磁盘I/O性能瓶颈等疑难问题的解决,使得大多数对Linux虚拟化持怀疑态度的人心服口服。   

7.稳定性   

    云供应商对于系统正常运行时间的要求是必须能够达到99.999 %。那么他们应该选择什么平台呢?答案就是Linux操作系统。为什么呢?因为Linux稳定性非常好。如果不更新内核,Linux不需要重新启动。   

6.商业支持   

    VMware、思杰、红帽和Canonical Ubuntu各自都有一套Linux虚拟化商业支持解决方案。这些大型厂商提供的一流的支持,卓越的产品再加上最优秀的技术人员,让你没有任何后顾之忧。   

5.硬件要求低   

    红帽,Ubuntu和Xen的虚拟化基础对于硬件的需求几乎低到了极点,它们能够安装在你使用的任何硬件设备上。关键在于使用Linux虚拟化技术你可以实现“梦寐以求”的少花钱多办事。廉价的硬件是人们选择虚拟化技术的主要原因之一,因为没有庞大的财政承担。   

4.管理   

    一旦安装,VMware和Citrix Xen就能通过远程应用进行管理,而不是通过命令行。你可以与底层操作系统直接打交道,但你几乎不需要这么做。   

3.Hypervisor技术   

    由于“体积”小,再加上能够作为并行操作系统运行,Linux成为了Hypervisor技术的首选平台。VMware和Xen都是按照这者方式运作的。Hypervisor没有所谓的操作系统层这一概念,而是使用并行虚拟Linux系统,你仍然可以与系统本身进行互动。   

2.社区支持   

    你不用担心遇到的任何问题,因为你拥有世界上最大的支持社区。类似DaniWeb这样的网站及其成员将会为你提供更方面的帮助。你无需为某个问题感到沮丧,你只需进行搜索或提问,那么一定会有热心人或遇到并解决过类似问题的人为你出谋划策。   

1.开放性   

    开放的Linux虚拟化解决方案能够让你省去很多许可方面的麻烦。私有虚拟化解决方案比如Hyper-V并不可怕,但是如果你使用它,你就不得不“听命”于某个厂商而任其摆布。

源于oschina

1 十一月 2009 at 01:58 - Comments