jquery加Ajax读取xml及查找节点

读取XML如果用DOM的话,代码量多,更何况就算我们做出来了还有可能出现兼容问题.所以,在做这次的XML交互时我决定用jQuery代码量少,运行质量也高.

步骤入下:

首先建立一个XML文档,名字随便取就可以了.这里我就用test.xml给大家做示范了.

XML内容为:

<?xml version="1.0" encoding="utf-8" ?>
<stulist>
<man>
   <name>爱的色放</name>
   <age>36</age>
</man>
<man>
   <name>X特警</name>
   <age>24</age>
</man>
<man>
   <name>大头儿子小头爸爸</name>
   <age>12</age>
</man>
</stulist>

好了这样就算是一个比较完整的XML文档了.

下面就看我们要写的JS.

既然是jQuery最重要的就是要将jQuery库引入进来.

没有 jQuery的朋友可去jquery.com下载最新版本.这里就以我本机的路径为例.

<script language="javascript" type="text/javascript" src="../JavaScript/jquery-1.3.2.min.js"></script>

接下来就是读取XML文件了.前面我们已经说过了要用ajax所以这里代码就应该是这样:

    <script>
$(document).ready(function(){
    $.ajax({url:"test.xml",dataType:"xml",success:function(xml){
      $(xml).find("stulist>man").each(function(){
   document.getElementById("acc").innerHTML+="<br>姓名:"+$(this).find("name").text()+"<br/>年龄:"+$(this).find("age").text();
      });
    }});
    })

</script>

第一句就不用跟大家解释了,意思就是页面加载执行.我们也可以写在一个函数里.

$ajax()有很多参数,这里就只给大家介绍我写的这几个参数是什么意思.

参数1 url:要请求的文档路径.

参数2 dataType:请求的文档类型.有 XML HTML script json等等.

参数3 success:请求成功后的回调函数。也就是说,当你发送的请求成功之后你要做什么.

接下来我给大家解释一下这段代码

function(xml)   function相信大家都知道是干什么的,这里的xml指的是你请求文件完成后返回的所有数据.

$(xml).find("stulist>man").each这句的意思就是查找返回的xml里的stulist节点下的man标签.然后根据查找到的结果,每一个跟查找结果匹配的元素都执行下文的函数.

下边就更好理解了,然后在你查找到的结果里,继续查找你想要的元素,然后将你得到的值,一个个inner到需要显示的元素里.OK就这样,我们读取XML就成功了.

Posted in javascript, 未分类 | Tagged | Leave a comment

不错的jquery自动完成插件

不错的jquery自动完成插件

http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/

demo:

http://jquery.bassistance.de/autocomplete/demo/

Posted in 未分类 | Tagged | Leave a comment

迅雷亲历面经:笔试+上机+面试(完整JAVA面试题求解大讨论)

转另一个论坛的帖子:

迅雷面试回来,用了整整一下午(不知道怎么说了,其中等待时间都快2小时了),自己感觉笔试和上机还可以,但技术面谈这一关答得不太好,现在再次感觉互联网公司与一般软件公司的区别了,其中一点就是互联网应用在性能上要求很高,谈了一个小时大部分题目感觉都在谈论性能问题,自己在方面一直是弱项,汗啊:(

仔细回忆了一下整个面试过程的题目,记录下来,希望大家多多给点意见讨论下啊

一、笔试题:
A)JAVA基础多项选择题,比较简单,略

B)问答:
1)ajax原理、如何实现刷新数据及优点?
2)门面模式的解释、适用场合?
3)写6个linux常用命令?
4)SQL语句题,较简单

C)编程:
1)有三个线程ID分别是A、B、C,请有多线编程实现,在屏幕上循环打印10次ABCABC…
2)假如有字符串“6sabcsssfsfs33” ,用最有快速的方法去掉字符“ab3”,不能用java内置字符串方法(indeOf,substring,replaceAll等)?

二、上机题:
Java上机实现统计某一目录下每个文件中出现的字母个数、数字个数、空格个数及行数?

三、面试题:
1、说说JVM原理?内存泄露与溢出区别,何时产生内存泄露?
2、用java怎么实现有每天有1亿条记录的DB存储?mysql上亿记录数据量的数据库如何设计?
3、mysql支持事务吗?DB存储引擎有哪些?
4、mvc原理,mvc模式的优缺点,如果让你设计你会怎么改造MVC?
5、hibernate支持集群吗?如何实现集群?
6、tomcat 最多支持并发多少用户?
7、map原理,它是如何快速查找key的?map与set区别?
8、描术算法,如何有效合并两个文件:一个是1亿条的用户基本信息,另一个是用户每天看电影连续剧等的记录,5000万条。内存只有1G???
9、在1亿条用户记录里,如何快速查询统计出看了5个电影以上的用户?
10、Spring如何实现IOC与AOP的,说出实现原理?

期待大家的探讨,共同提高,多谢

Posted in 未分类 | Tagged | Leave a comment

使用PDT + Zend Debugger 单步调试php

下载ZendDebugger-20100729-cygwin_nt-i386.zip , 下载zend debugger插件,下载地址:

http://www.zend.com/en/products/studio/downloads

 

Studio Web Debugger 20100729 (32 bit)

,php使用官网的版本,不要使用xampp。配置好之后即可进行单步调试。

Posted in PHP, 未分类 | Tagged | 1 Comment

Zend Server 5.0.1 安装记录

www.php.net 上下载了 Zend Server 社区版:ZendServer-CE-php-5.3.2-5.0.1-Windows_x86.exe。在 Windows 下使用的,for PHP 5.3.2,其本身版本是 5.0.1。

Zend Server 是一个企业级的应用服务器,集成了 PHP、Zend Framework、MySQL、Apache、PHPMyAdmin 等工具,看看 Zend 公司宣布的功能:

Bytecode accelerator (Optimizer+)
Zend Data Cache
A certified PHP distribution
Zend Framework
Apache (or IIS integration)
MySQL (on Windows and Mac OS X)
Out-of-the-box connectivity to all common databases
Java code connectivity
Web-based PHP administrator console

安装比较简单,双击运行,根据安装向导走,安装于 C:\Program Files\Zend 路径下,很顺利的装完。选择了与 Apache 服务器集成(80端口),而 Zend Server 则选择了默认的 10081 端口。
Zend Server 被配置成虚拟路径 ZendServer,指向实际物理路径 C:\Program Files\Zend\ZendServer。Zend Server 的有关配置文件是 C:\Program Files\Zend\Apache2\conf\zend.conf,被该路径下的 httpd.conf 文件包含。

但在运行 ZendServer 时,出错了:在打开网址 http://localhost:10081/ZendServer 时,报告:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.

打开 Apache 日志, 发现下面的提示:

Zend Enabler cannot load because of a problem in its configuration file: XML parse error on line 1 column 1 – invalid byte ‘?’ at position 3 of a 3-byte sequence

难道是 XML 文件有错吗?打开 Zend Enabler 的 XML 配置文件(路径 %your_install_dir%ZendServer\etc\ZendEnablerConf.xml), 居然看到首行第一个字符是乱码(一个“口”字),改成“<”字符保存,重启 Apache 服务器(Windows 服务名:Apache2.2-Zend),OK 了。

但奇怪的是,文件是从 Zend 的服务器上下载的,那个 XML 文件也是安装过程自动生成的,怎会出现乱码?只能说,是 Zend 公司自己出错了。

但问题还没完……

打开 http://localhost:10081/ZendServer 时,又报告:

For optimal stability and performance, only run Zend Server Community Edition on a supported browser. For a complete list of supported browsers see the Zend Server Community Edition documentation resources on zend.com

我用的是 Windows Server 2003 里带的 IE6.0 3790 浏览器,竟然不被支持。在 http://www.zend.com/en/products/server/system-requirements 里找到了支持的浏览器:

Supported Browsers:

MS Internet Explorer 7 and above
Mozilla Firefox 2.0 and above
Apple Safari 3.0

看来微软的 IE6.0 真的是穷途末路,如过街老鼠般被围追堵截、人人喊打了(最近的 Flash 似乎也遭此命运,陷入水深火热之中了)。

再装 Firefox3.6.3,终于打开了 http://localhost:10081/ZendServer。信息显示:

Welcome to Zend Server Community Edition
Please define your Administration Interface password.

设置了密码后,进入 PHP 管理界面。

zendserver5.gif

由于集成安装了 Zend Debugger,所以可以与 Zend Studio 7.0 IDE 配合进行 PHP 代码的远程调试。

Posted in 未分类 | Leave a comment

史蒂夫 乔布斯(Steve Jobs)在 Stanford 2005毕业典礼上的演讲

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

http://news-service.stanford.edu/news/2005/june15/jobs-061505.html

翻译:

史蒂夫 乔布斯(Steve Jobs)在斯坦福大学2005年毕业典礼上的演讲

我今天很荣幸能和你们一起参加毕业典礼,斯坦福大学是世界上最好的大学之一。我从来没有从大学中毕业。说实话,今天也许是在我的生命中离大学毕业最近的一 天了。今天我想向你们讲述我生活中的三个故事。不是什么大不了的事情,只是三个故事而已。

第一个故事是关于如何把生命中的点点滴滴串连起来。

我在Reed大学读了六个月之后就退学了,但是在十八个月以后——我真正的作出退学决定之前,我还经常去学校。我为什么要退学呢?

故事从我出生的时候讲起。我的亲生母亲是一个年轻的,没有结婚的大学毕业生。她决定让别人收养我, 她十分想让我被大学毕业生收养。所以在我出生的时候,她已经做好了一切的准备工作,能使得我被一个律师和他的妻子所收养。但是她没有料到,当我出生之后, 律师夫妇突然决定他们想要一个女孩。所以我的生养父母(他们在待选名单上)突然在半夜接到了一个电话:“我们现在这儿有一个不小心生出来的男婴,你们想要 他吗?”他们回答道: “当然!”但是我亲生母亲随后发现,我的养母从来没有上过大学,我的养父 甚至从没有读过高中。她拒绝签这个收养合同。只是在几个月以后,我的父母答应她一定要让我上大学,那个时候她才软化同意。

在十七岁那年,我真的上了大学。但是我很愚蠢的选择了一个几乎和你们斯坦福大学一样贵的学校, 我父母还处于蓝领阶层,他们几乎把所有积蓄都花在了我的学费上面。在六个月后, 我已经看不到其中的价值所在。我不知道我真正想要做什么,我也不知道大学能怎样帮助我找到答案。但是在这里,我几乎花光了我父母这一辈子的 全部积蓄。所以我决定要退学,我觉得这是个正确的决定。不能否认,我当时确实非常的害怕, 但是现在回头看看,那的确是我这一生中最棒的一个决定。在我做出退学决定的那一刻, 我终于可以不必去读那些令我提不起丝毫兴趣的课程了。然后我可以开始去修那些看起来有点意思的课程。

但是这并不是那么罗曼蒂克。我失去了我的宿舍,所以我只能在朋友房间的地板上面睡觉,我去捡可以换5美分的可乐罐,仅仅为了填饱肚子, 在星期天的晚上,我需要走七英里的路程,穿过这个城市到Hare Krishna神庙(注:位于纽约Brooklyn下城),只是为了能吃上好饭——这个星期唯一一顿好一点的饭,我喜欢那里的饭菜。

我跟着我的直觉和好奇心走, 遇到的很多东西,此后被证明是无价之宝。让我给你们举一个例子吧:

Reed大学在那时提供也许是全美最好的美术字课程。在这个大学里面的每个海报, 每个抽屉的标签上面全都是漂亮的美术字。因为我退学了, 不必去上正规的课程, 所以我决定去参加这个课程,去学学怎样写出漂亮的美术字。我学到了san serif 和serif字体, 我学会了怎么样在不同的字母组合之中改变空白间距, 还有怎么样才能作出最棒的印刷式样。那种美好、历史感和艺术精妙,是科学永远不能捕捉到的, 我发现那实在是太迷人了。

当时看起来这些东西在我的生命中,好像都没有什么实际应用的可能。但是十年之后,当我们在设计第一台Macintosh电脑的时候,就不是那样了。我 把当时我学的那些 东西全都设计进了Mac。那是第一台使用了漂亮的印刷字体的电脑。如果我当时没有退学, 就不会有机会去参加这个我感兴趣的美术字课程, Mac就不会有这么多丰富的字体,以及赏心悦目的字体间距。因为Windows只是抄袭了Mac,所以现在个人电脑就不会有现在这么美妙的字型了。

当然我在大学的时候,还不可能把从前的点点滴滴串连起来,但是当我十年后回顾这一切的时候,真的豁然开朗了。

再次说明的是,你在向前展望的时候不可能将这些片断串连起来;你只能在回顾的时候将点点滴滴串连起来。所以你必须相信这些片断会在你未来的某一天串连 起来。你必须要相信某些东西:你的勇气、目的、生命、因缘……这个过程从来没有令我失望,只是让我的生命更加地与众不同。

我的第二个故事是关于爱和失去。

我非常幸运, 因为我在很早的时候就找到了我钟爱的东西。Woz和我在二十岁的时候就在父母的车库里面开创了苹果公司。我们工作得很努力, 十年之后, 这个公司从那两个车库中的穷小子发展到了超过四千名的雇员、价值超过二十亿的大公司。在公司成立的第九年,我们刚刚发布了最好的产品,那就是 Macintosh。我也快要到三十岁了。在那一年, 我被炒了鱿鱼。你怎么可能被你自己创立的公司炒了鱿鱼呢? 嗯,在苹果快速成长的时候,我们雇用了一个很有天分的家伙和我一起管理这个公司, 在最初的几年,公司运转的很好。但是后来我们对未来的看法发生了分歧, 最终我们吵了起来。当争吵不可开交的时候, 董事会站在了他的那一边。所以在三十岁的时候, 我被炒了。在这么多人目光下我被炒了。在而立之年,我生命的全部支柱离自己远去, 这真是毁灭性的打击。

在最初的几个月里,我真是不知道该做些什么。我觉得我很令上一代的创业家们很失望,我把他们交给我的接力棒弄丢了。我和创办惠普的David Pack、创办Intel的Bob Noyce见面,并试图向他们道歉。我把事情弄得糟糕透顶了。但是我渐渐发现了曙光, 我仍然喜爱我从事的这些东西。苹果公司发生的这些事情丝毫的没有改变这些, 一点也没有。我被驱逐了,但是我仍然钟爱我所做的事情。所以我决定从头再来。

我当时没有觉察, 但是事后证明, 从苹果公司被炒是我这辈子发生的最棒的事情。因为,作为一个成功者的负重感被作为一个创业者的轻松感觉所重新代替, 没有比这更确定的事情了。这让我觉得如此自由, 进入了我生命中最有创造力的一个阶段。

在接下来的五年里, 我创立了一个名叫NeXT的公司, 还有一个叫Pixar的公司, 然后和一个后来成为我妻子的优雅女人相识。Pixar 制作了世界上第一个用电脑制作的动画电影——“玩具总动员”,Pixar现在也是世界上最成功的电脑制作工作室。在后来的一系列运转中,Apple收购了 NeXT, 然后我又回到了Apple公司。我们在NeXT发展的技术在Apple的今天的复兴之中发挥了关键的作用。而且,我还和Laurence 一起建立了一个幸福完美的家庭。

我可以非常肯定,如果我不被Apple开除的话, 这其中一件事情也不会发生的。这个良药的味道实在是太苦了,但是我想病人需要这个药。有些时候, 生活会拿起一块砖头向你的脑袋上猛拍一下。不要失去信仰。我很清楚唯一使我一直走下去的,就是我做的事情令我无比钟爱。你需要去找到你所爱的东西。对于工 作是如此, 对于你的爱人也是如此。你的工作将会占据生活中很大的一部分。你只有相信自己所做的是伟大的工作, 你才能怡然自得。如果你现在还没有找到, 那么继续找、不要停下来,只要全心全意的去找, 在你找到的时候,你的心会告诉你的。就像任何真诚的关系, 随着岁月的流逝只会越来越紧密。所以继续找,直到你找到它,不要停下来!

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

当我十七岁的时候, 我读到了一句话:“如果你把每一天都当作生命中最后一天去生活的话,那么有一天你会发现你是正确的。”这句话给我留下了一个印象。从那时开始,过了33 年,我在每天早晨都会对着镜子问自己:“如果今天是我生命中的最后一天, 你会不会完成你今天想做的事情呢?”当答案连续多天是“No”的时候, 我知道自己需要改变某些事情了。

“记住你即将死去”是我一生中遇到的最重要箴言。它帮我指明了生命中重要的选择。因为几乎所有的事情, 包括所有的荣誉、所有的骄傲、所有对难堪和失败的恐惧,这些在死亡面前都会消失。我看到的是留下的真正重要的东西。你有时候会思考你将会失去某些东西, “记住你即将死去”是我知道的避免这些想法的最好办法。你已经赤身裸体了, 你没有理由不去跟随自己内心的声音。

大概一年以前, 我被诊断出癌症。我在早晨七点半做了一个检查, 检查清楚的显示在我的胰腺有一个肿瘤。我当时都不知道胰腺是什么东西。医生告诉我那很可能是一种无法治愈的癌症, 我还有三到六个月的时间活在这个世界上。我的医生叫我回家, 然后整理好我的一切, 那是医生对临终病人的标准程序。那意味着你将要把未来十年对你小孩说的话在几个月里面说完.;那意味着把每件事情都安排好, 让你的家人会尽可能轻松的生活;那意味着你要说“再见了”。

我拿着那个诊断书过了一整天,那天晚上我作了一个活切片检查,医生将一个内窥镜从我的喉咙伸进去,通过我的胃, 然后进入我的肠子, 用一根针在我的胰腺上的肿瘤上取了几个细胞。我当时是被麻醉的,但是我的妻子在那里, 后来告诉我,当医生在显微镜下观察这些细胞的时候他们开始尖叫, 因为这些细胞最后竟然是一种非常罕见的可以用手术治愈的胰腺癌症细胞。我做了这个手术, 现在我痊愈了。

那是我最接近死亡的时候, 我希望这也是以后的几十年最接近的一次。从死亡线上又活了过来, 我可以比以前把死亡只当成一 种想象中的概念的时候,更肯定一点地对你们说:

没有人愿意死, 即使人们想上天堂, 也不会为了去那里而死。但是死亡是我们每个人共同的终点。从来没有人能够逃脱它。也应该如此。因为死亡就是生命中最好的一个发明。它将旧的清除以便给新的 让路。你们现在是新的, 但是从现在开始不久以后, 你们将会逐渐的变成旧的然后被送离人生舞台。我很抱歉这很戏剧性, 但是这十分的真实。

你们的时间很有限, 所以不要将他们浪费在重复其他人的生活上。不要被教条束缚,那意味着你和其他人思考的结果一起生活。不要被其他人喧嚣的观点掩盖你真正的内心的声音。还有最重要的是, 你要有勇气去听从你直觉和心灵的指示——它们在某种程度上知道你想要成为什么样子,所有其他的事情都是次要的。

当我年轻的时候, 有一本叫做“整个地球的目录”振聋发聩的杂志,它是我们那一代人的圣经之一。它是一个叫Stewart Brand的家伙在离这里不远的Menlo Park编辑的, 他象诗一般神奇地将这本书带到了这个世界。那是六十年代后期, 在个人电脑出现之前, 所以这本书全部是用打字机,、剪刀还有偏光镜制造的。有点像用软皮包装的google, 在google出现三十五年之前:这是理想主义的,其中有许多灵巧的工具和伟大的想法。

Stewart和他的伙伴出版了几期的“整个地球的目录”,当它完成了自己使命的时候, 他们做出了最后一期的目录。那是在七十年代的中期, 我正是你们的年纪。在最后一期的封底上是清晨乡村公路的照片(如果你有冒险精神的话,你可以自己找到这条路的),在照片之下有这样一段话:“求知若饥,虚 心若愚。”这是他们停止了发刊的告别语。“求知若饥,虚心若愚。”我总是希望自己能够那样,现在, 在你们即将毕业,开始新的旅程的时候, 我也希望你们能这样:

求知若饥,虚心若愚。

非常感谢你们

以上为史蒂夫.乔布斯在斯坦福大学2005年毕业典礼上的演讲

Posted in 未分类 | Leave a comment

Resizing images with PHP

The code

<?php
/*
* File: SimpleImage.php
* Author: Simon Jarvis
* Copyright: 2006 Simon Jarvis
* Date: 08/11/06
* Link: http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details:
* http://www.gnu.org/licenses/gpl.html
*
*/

class SimpleImage {

   var $image;
   var $image_type;

   function load($filename) {
      $image_info = getimagesize($filename);
      $this->image_type = $image_info[2];
      if( $this->image_type == IMAGETYPE_JPEG ) {
         $this->image = imagecreatefromjpeg($filename);
      } elseif( $this->image_type == IMAGETYPE_GIF ) {
         $this->image = imagecreatefromgif($filename);
      } elseif( $this->image_type == IMAGETYPE_PNG ) {
         $this->image = imagecreatefrompng($filename);
      }
   }
   function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) {
      if( $image_type == IMAGETYPE_JPEG ) {
         imagejpeg($this->image,$filename,$compression);
      } elseif( $image_type == IMAGETYPE_GIF ) {
         imagegif($this->image,$filename);
      } elseif( $image_type == IMAGETYPE_PNG ) {
         imagepng($this->image,$filename);
      }
      if( $permissions != null) {
         chmod($filename,$permissions);
      }
   }
   function output($image_type=IMAGETYPE_JPEG) {
      if( $image_type == IMAGETYPE_JPEG ) {
         imagejpeg($this->image);
      } elseif( $image_type == IMAGETYPE_GIF ) {
         imagegif($this->image);
      } elseif( $image_type == IMAGETYPE_PNG ) {
         imagepng($this->image);
      }
   }
   function getWidth() {
      return imagesx($this->image);
   }
   function getHeight() {
      return imagesy($this->image);
   }
   function resizeToHeight($height) {
      $ratio = $height / $this->getHeight();
      $width = $this->getWidth() * $ratio;
      $this->resize($width,$height);
   }
   function resizeToWidth($width) {
      $ratio = $width / $this->getWidth();
      $height = $this->getheight() * $ratio;
      $this->resize($width,$height);
   }
   function scale($scale) {
      $width = $this->getWidth() * $scale/100;
      $height = $this->getheight() * $scale/100;
      $this->resize($width,$height);
   }
   function resize($width,$height) {
      $new_image = imagecreatetruecolor($width, $height);
      imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
      $this->image = $new_image;
   }
}
?>

Usage

Save the above file as SimpleImage.php and take a look at the following examples of how to use the script.

The first example below will load a file named picture.jpg resize it to 250 pixels wide and 400 pixels high and resave it as picture2.jpg

<?php
   include('SimpleImage.php');
   $image = new SimpleImage();
   $image->load('picture.jpg');
   $image->resize(250,400);
   $image->save('picture2.jpg');
?>

If you want to resize to a specifed width but keep the dimensions ratio the same then the script can work out the required height for you, just use the resizeToWidth function.

<?php
   include('SimpleImage.php');
   $image = new SimpleImage();
   $image->load('picture.jpg');
   $image->resizeToWidth(250);
   $image->save('picture2.jpg');
?>

You may wish to scale an image to a specified percentage like the following which will resize the image to 50% of its original width and height

<?php
   include('SimpleImage.php');
   $image = new SimpleImage();
   $image->load('picture.jpg');
   $image->scale(50);
   $image->save('picture2.jpg');
?>

You can of course do more than one thing at once. The following example will create two new images with heights of 200 pixels and 500 pixels

<?php
   include('SimpleImage.php');
   $image = new SimpleImage();
   $image->load('picture.jpg');
   $image->resizeToHeight(500);
   $image->save('picture2.jpg');
   $image->resizeToHeight(200);
   $image->save('picture3.jpg');
?>

The output function lets you output the image straight to the browser without having to save the file. Its useful for on the fly thumbnail generation

<?php
   header('Content-Type: image/jpeg');
   include('SimpleImage.php');
   $image = new SimpleImage();
   $image->load('picture.jpg');
   $image->resizeToWidth(150);
   $image->output();
?>

The following example will resize and save an image which has been uploaded via a form

<?php
   if( isset($_POST['submit']) ) {
      include('SimpleImage.php');
      $image = new SimpleImage();
      $image->load($_FILES['uploaded_image']['tmp_name']);
      $image->resizeToWidth(150);
      $image->output();
   } else {
?>
   <form action="upload.php" method="post" enctype="multipart/form-data">
      <input type="file" name="uploaded_image" />
      <input type="submit" name="submit" value="Upload" />
   </form>
<?php
   }
?>
Posted in 未分类 | Tagged | Leave a comment

修改MYSQL最大连接数的方法

MYSQL数据库安装完成后,默认最大连接数是100,一般流量稍微大一点的论 坛或网站这个连接数是远远不够的,增加默认MYSQL连接数的方法有两个

方法一:进入MYSQL安装目录 打开MYSQL配置文件 my.ini 或 my.cnf查找 max_connections=100   修改为 max_connections=1000 服务里重起MYSQL即可

方法二:MySQL的最大连接数默认是100客户端登录:mysql -uusername -ppassword

设置新的最大连接数为200:mysql> set GLOBAL max_connections=200

显示当前运行的Query:mysql> show processlist

显示当前状态:mysql> show status

退出客户端:mysql> exit

查看当前最大连接数:mysqladmin -uusername -ppassword variables

Posted in 未分类 | Leave a comment

十条不错的编程观点

在Stack Overflow上有这样的一个贴子《What’s your most controversial programming opinion?》,翻译成中文就是“你认为最有争议的编程观点是什么?”,不过,在400多个主回贴,以及千把个子回贴中,好像并不是很有争议,而是令人相当的茅塞顿开,下面罗列一些,并通过我自己的经历和理解发挥了一些,希望对你有帮助。

1) The only “best practice” you should be using all the time is “Use Your Brain”.

唯一的“Best Practice”并不是使用各种各样被前人总结过的各种设计方法、模式,框架,那些著名的方法、模式、框架只代码赞同他们的人多,并不代表他们适合你,你应该更多的去使用你的大脑,独立地思考那些方法、模式、框架出现的原因和其背后的想法和思想,那才是“best practice”。事实上来说,那些所谓的“Best Practice”只不过是限制那些糟糕的程序员们的破坏力。

2)Programmers who don’t code in their spare time for fun will never become as good as those that do.

如果你对编程没有感到一种快乐,没有在你空闲的时候去以一种的娱乐方式去生活,无论是编程,还是运动,还是去旅游,那么你只不过是在应付你的工作,无时无刻不扎在程序堆中,这样下来,就算是你是一个非常聪明,非常有才华的人,你也不会成为一个优秀的编程员,要么只会平平凡凡,要么只会整天扎在技术中成为书呆子。当然,这个观点是有争议,热情和能力的差距也是很大的。不过我们可以从中汲取其正面的观点。

3)Most comments in code are in fact a pernicious form of code duplication.

注释应该是注释Why,而不是How和What,参看《惹恼程序员的十件事》,代码告诉你 How,而注释应该告诉你Why。但大多数的程序并不知道什么是好的注释,那些注释其实和code是重复的,毫无意义。

4)XML is highly overrated

XML可能被高估了。XML对于Web上的应用是不错的,但是我们把其用到了各种地方,好像没有XML,我们都不会编程了。

5)Not all programmers are created equal

这是那些junior经理或是流程爱犯的错,他们总是认为,DeveloperA == DeveloperB,只要他们的title一样,他们以为他们的能力、工作速度、解决问题的方法,掌握的技能等等都是一样的。呵呵。更扯的是,在某些时候,就算是最差的程序员,他们也会认为其比别人强十倍,这就是现代的SB管理。

6)”Googling it” is okay!

Google只会给你知识,并不会教给你技能。那里只有“鱼”,没有“渔”,过度的使用 Google,只会让你越来越离不开他,你越来越去要去立马告诉你答案,而你越来越不会自己去思考,自己去探索,去专研。如果KFC快餐是垃圾食品对我们的身体没有好处,那么使用Google也一种快餐文化对我们的智力发展大大的没有好处。

7)If you only know one language, no matter how well you know it, you’re not a great programmer.

如果你只懂一种语言,准确的说,如果你只懂一类语类,如:Java和C#,PHP和 Perl,那么,你将会被局限起来,只有了解了各种各样的语言,了解了不同语言的不同方法 ,你才会有比较,只有了比较,你才会明白各种语言的长处和短处,才会让你有更为成熟的观点,而且不整天和别的程序在网上斗嘴争论是Windows好还是 Unix好,是C好还是C++好,有这点工夫能干好多事了。世界因为不同而精彩,只知道事物的一面是有害的。

8)Your job is to put yourself out of work.

你的工作不是保守,那种教会徒弟,饿死师父的想法,不但是相当短浅的,而且还是相当脑残的。因为,在计算机世界里,你掌握的老技术越多,你就越没用,因为技术更新的太快。你对工作越保守,这个工作就越来越离不开你,你就越不越不能抽身去学新的东西,你也就越来越OUT了。记住:If you can’t be replaced then you can’t be promoted!

9)Design patterns are hurting good design more than they’re helping it.

很多程序员把设计模式奉为天神,他们过度的追求设计模式以至都都忘了需求是什么,结果整个系统设计被设计模式搞得乱七八糟,我们叫这种编程为“设计模式驱动编程”,正如第一点所说,如果你不懂得用自己的大脑思考的话,知其然,不知所以然的话,那么你不但得不到其好处,反而受其所累。

10)Unit Testing won’t help you write good code

其实,unit test 的主要目的是,为了防止你不会因为一个改动而引入Bug,但这并不会让你能写出更好的代码。这只会让你写出不会出错的代码。同第一点,这样的方法,只不过是防止糟糕的程序员,而并不是让程序员或代码质量更有长进。反而,通过Unit Test会成为程序员为自己代码做辩解的一种托辞。

最后,顺便说一下,以前去那个敏捷的公司面试,发现那个公司的某些技术人员中毒不浅,具体表现在上述的1)9)10)观点上。

原文链接:http://blog.csdn.net/haoel/archive/2010/07/21/5752106.aspx

Posted in 未分类 | Leave a comment

smarty section 用法

参考了smarty的官方文档,不过是翻译了部分,也加了点注释,个人感觉是比较有用的。欢迎交流。

1、循环一个简单的一维数组:
Example 7-30. Looping a simple array with {section}

$data = array(1000,1001,1002);
$smarty->assign(‘custid’,$data);
?>

//customer 和下面的foo可以随便命名,作用其实仅仅是一个index下标,用来引用数组中的元素
{section name=customer loop=$custid}
id: {$custid[customer]}

{/section}

{section name=foo loop=$custid step=-1}
{$custid[foo]}

{/section}

// 输出
id: 1000

id: 1001

id: 1002

id: 1002

id: 1001

id: 1000

2、不用assign数组直接在smarty中循环:
Example 7-31. {section} without an assigned array

//特别地设置了start,step属性用来控制循环
//$smarty.section.section的名字.index是一个特殊变量,用来显示当前循环的位置
{section name=foo start=10 loop=20 step=2}
{$smarty.section.foo.index}
{/section}

{section name=bar loop=21 max=6 step=-2}
{$smarty.section.bar.index}
{/section}

// 输出:
10 12 14 16 18

20 18 16 14 12 10

3、section的name 的值是随你定的
Example 7-32. Naming a {section}

{section name=anything loop=$myArray}
{$myArray[anything].foo}
{$name[anything]} //这种用法目前还没怎么用过,也不太清楚
{$address[anything].bar} //这种也是
{/section}

4、遍历一个关联数组,嵌套的数组

$data = array(
array(‘name’ => ‘John Smith’, ‘home’ => ’555-555-5555′,
‘cell’ => ’666-555-5555′, ‘email’ => ‘john@myexample.com’),
array(‘name’ => ‘Jack Jones’, ‘home’ => ’777-555-5555′,
‘cell’ => ’888-555-5555′, ‘email’ => ‘jack@myexample.com’),
array(‘name’ => ‘Jane Munson’, ‘home’ => ’000-555-5555′,
‘cell’ => ’123456′, ‘email’ => ‘jane@myexample.com’)
);
$smarty->assign(‘contacts’,$data);
?>

//section 不用嵌套,因为只有一个数组,数组内部用$contacts[customer]得到
//每个数组,再用.键名来得到键值
{section name=customer loop=$contacts}

name: {$contacts[customer].name}

home: {$contacts[customer].home}

cell: {$contacts[customer].cell}

e-mail: {$contacts[customer].email}

{/section}

The above example will output:

name: John Smith

home: 555-555-5555

cell: 666-555-5555

e-mail: john@myexample.com

name: Jack Jones

home phone: 777-555-5555

cell phone: 888-555-5555

e-mail: jack@myexample.com

name: Jane Munson

home phone: 000-555-5555

cell phone: 123456

e-mail: jane@myexample.com

5、从数据库查询记录显示,实际上是显示二维数组,其实同上例一样
$sql = ‘select id, name, home, cell, email from contacts ‘
.”where name like ‘$foo%’ “;
$smarty->assign(‘contacts’, $db->getAll($sql));
?>

// 结果:

{section name=co loop=$contacts} //第一维

//第二维用.号来引用

{sectionelse}

{/section}

Name> Home Cell Email
view {$contacts[co].name} {$contacts[co].home} {$contacts[co].cell} {$contacts[co].email}
No items found

6、嵌套的section

$id = array(1001,1002,1003);
$smarty->assign(‘custid’,$id);

$fullnames = array(‘John Smith’,'Jack Jones’,'Jane Munson’);
$smarty->assign(‘name’,$fullnames);

$addr = array(’253 N 45th’, ’417 Mulberry ln’, ’5605 apple st’);
$smarty->assign(‘address’,$addr);

$types = array(
array( ‘home phone’, ‘cell phone’, ‘e-mail’),
array( ‘home phone’, ‘web’),
array( ‘cell phone’)
);
$smarty->assign(‘contact_type’, $types);

$info = array(
array(’555-555-5555′, ’666-555-5555′, ‘john@myexample.com’),
array( ’123-456-4′, ‘www.example.com’),
array( ’0457878′)
);
$smarty->assign(‘contact_info’, $info);

?>

{section name=customer loop=$custid}

id: {$custid[customer]}

name: {$name[customer]}

address: {$address[customer]}

{section name=contact loop=$contact_type[customer]}
{$contact_type[customer][contact]}: {$contact_info[customer][contact]}

{/section}
{/section}

The above example will output:

id: 1000

name: John Smith

address: 253 N 45th

home phone: 555-555-5555

cell phone: 666-555-5555

e-mail: john@myexample.com

id: 1001

name: Jack Jones

address: 417 Mulberry ln

home phone: 123-456-4

web: www.example.com

id: 1002

name: Jane Munson

address: 5605 apple st

cell phone: 0457878

Posted in 未分类 | Leave a comment