显示标签为“Books”的博文。显示所有博文
显示标签为“Books”的博文。显示所有博文

2008年6月29日星期日

人体使用手册 1、2 读书摘要

腾不出时间睡觉的人,迟早会腾出时间来生病。

今天不好好睡觉,明天好好睡长觉。

症现于四肢五官,病存于五脏六腑。

生气的实质意义是,用别人的过错惩罚自己。

-------------------------------------------

中国人是全世界最懂得养生理论的民族,也是全世界最不遵循养生理论的民族。

多数情形怒气的发作都是这种“零存整取”的模式。

2008年6月22日星期日

人体使用手册

很早以前就下过这本书的电子版了,当时看了一部分,观点比较新颖,其实也就是传统中医的理论++。昨天搜索发现《人体复原工程》(人体使用手册2)出版了,于是去卓越订了这两本,明后天应该就送到了。

以前还买过《身体使用手册》,也是1、2两本,一本红的一本蓝的,是美国医生写的,也很不错。

顺便提下,以后是不会在淘宝买书了。网购不是图便宜,而是图方便。但是快递一点也不会给你方便。至少卓越会提供“只周末送货”“只工作日送货”的选择(上次在淘宝买了《Restful Web Services 中文版》后,才发现该书的官网也提供这种选择),对于整天上班的人来说是很贴心的服务。淘宝的个体商户发快递就不会考虑到这一点,好像我们是不用做事整天呆在家里等快递一样。

《人体使用手册》的作者在blogspot的博客,在hexun的博客。估计也是体谅水生火热的大陆读者访问不了blogspot,所以开了两个博客。

再顺便提下,好像blogspot又解封了,没有设置hosts也能访问了。

《Python 核心编程》第二版 要出版了

是社区组织群体翻译的。社区翻译的好处是进度快,人多力量大嘛;坏处是:不容易组织,不容易保证翻译质量。尤其是这么大部头的一本,能够圆满完成实属不易。

然而,听说大家的劳动成果居然被窃取了?
http://nicholas-ding.javaeye.com/blog/206347

如果是真的,那大家就不要去买纸版的了吧。
这个是翻译项目的 SVN
http://openbookproject.googlecode.com/svn/trunk/CorePython_zh/
大家用 TortoiseSVN 把它 Export 出来就可以了。

不是教唆大家盗版,实在是没有必要便宜了那个窃取劳动果实的家伙。

2008年6月21日星期六

RESTful Web Services 中文版 读书摘要 第五章

P109
统一接口意味着,在面向对象设计里被视为动词的事务,在面向资源的设计里必须被视为对象。在面向资源的架构里,一个读者不能“订阅”一个栏目,因为“订阅”不属于统一接口里的方法。必须通过另一个订阅对象来代表读者与栏目之间的关系。
如果要给我的资源增添新方法,就要为此定义一个新资源。
----------------------------
The uniform interface means that a resource-oriented design must treat as objects what an object-oriented design might consider verbs. In the ROA, a Reader can’t subscribe to a regularly appearing Column, because “subscribe to” is not part of the uniform interface. here must be a third object, Subscription, representing that relationship between a Reader nd a Column.
Whenever I’m tempted to add a new method to one of my resource “classes,” I’ll resolve the problem by defining a new kind of resource.

P109
设计资源的步骤:
(注:这里中英文没有一一对应)
1. 规划数据集
2. 把数据集划分为资源
对于其中每种资源:
3. 用 URI 为该资源命名
4. 设计发给客户端的表示
5. 用超链接和表单把该资源与已有资源联系起来
6. 考虑有哪些典型的事件经过
7. 考虑可能出现哪些错误情况
----------------------------
1. Figure out the data set
2. Split the data set into resources
For each kind of resource:
3. Name the resources with URIs
4. Expose a subset of the uniform interface
5. Design the representation(s) accepted from the client
6. Design the representation(s) served to the client
7. Integrate this resource into existing resources, using hypermedia links and forms
8. Consider the typical course of events: what’s supposed to happen?
9. Consider error conditions: what might go wrong?

P112
一个资源就是任何值得作为超链接目标的事物
----------------------------
Remember that a resource is anything interesting enough to be the target of a hypertext link.

P113
服务暴露的资源可以分为三类:
为特别目的专门预定义的一次性资源
服务暴露的每一个对象所对应的资源
代表在数据集上执行算法的结果的资源
----------------------------
Web services commonly expose three kinds of resources:
Predefined one-off resources for especially important aspects of the application.
A resource for every object exposed through the service.
Resources representing the results of algorithms applied to the data set.

P117
要理解“把算法暴露为资源”这一方式,是需要一些时间的。你不要从动作(如“在地图上搜索地点”)方面来考虑,而要从该动作的结果方面来考虑(如“地图上符合搜索条件的地点”)。
----------------------------
It takes a while to get the hang of exposing an algorithm as a set of resources. Instead of thinking in terms of actions (“do a search for places on the map”), you need to think in terms of the results of that action (“the list of places on the map matching a search criteria”).

P117
根据集体经验,URI 设计有三条基本原则:
1. 用路径变量来表达层次结构: /parent/child
2. 在路径变量里加入标点符号,以消除误解: /parent/child1;child2
3. 用查询变量来表达算法的输入,例如: /search?q=jellyfish&start=20
----------------------------
There are three basic rules for URI design, born of collective experience:
1. Use path variables to encode hierarchy: /parent/child
2. Put punctuation characters in path variables to avoid implying hierarchy where none exists: /parent/child1;child2
3. Use query variables to imply inputs into an algorithm, for example: /search?q=jellyfish&start=20

P118
对于可按层次结构组织的作用域信息,采用路径变量是最好的方式。
----------------------------
Path variables are the best way to organize scoping information that can be arranged hierarchically.

P119
我建议:当作用域信息的次序有关紧要时,就用逗号,否则就用分号。
----------------------------
I recommend using commas when the order of the scoping information is important, and semicolons when the order doesn’t matter.

P129
表示传达资源状态,但它不必传达资源的全部状态,它只要传达部分状态就行了。
你可以通过跟随表示里的链接得到更多状态。
----------------------------
A representation conveys the state of its resource, but it doesn’t have to convey the entire state of the resource.
You can get as much of that state as you want by following its links to other resources.

P132
假如只能从本书得到一样东西,我希望那是你对“Web 服务就是为机器设计的网站”这一观念的理解(假若之前还没有的话)。
----------------------------
If you get only one thing out of this book, I hope it’s that this idea starts seeming natural to you (assuming it didn’t before).

P138
条件 HTTP GET 可以节省客户端和服务器的时间与带宽。它是通过两个响应报头(Last-Modified 和 ETag)和两个请求报头(IfModified-Since 和If-None-Match)实现的。
----------------------------
Conditional HTTP GET saves client and server time and bandwidth. It’s implemented with two response headers (Last-Modified and ETag), and two request headers (If- Modified-Since and If-None-Match).

P138
有些数据也许并不经常变化。
大部分时候,客户端对一个资源的第二次(及以后各次)HTTP 请求都是不必的。其实它们完全可以重用上一次请求时获得的表示。
----------------------------
This data is not constantly changing.
Most of the time, the client’s second and subsequent HTTP requests for a resource are wasted. They could have just reused the representation from their first request.

P138
每当服务器返回一个表示时,服务器应该为 Last-Modified 报头设置一个时间值,表示数据最后更新的时间。
客户端可以把这个最后更新时间保存下来,供以后使用。
当该客户端再次向同一个资源发送 GET 请求时,可以在 IfModified-Since 报头里提供那个最后更新时间。
假如资源的数据刚好在该客户端的两次请求之间发生了变化,服务器会返回响应代码 200(“OK”),并在实体主体里提供最新的表示——这就跟一次正常的 HTTP 请求一样。但是,假如数据没有变化,服务器将返回响应代码 304(“Not Modified”),并省去实体主体。这样,客户端就知道可以重用已缓存的表示了(因为数据没有改变)。
----------------------------
Whenever a server serves a representation, it should include a time value for the Last-Modified HTTP header. This is the last time the data underlying the representation was changed.
The client can store this value of Last-Modified and use it later.
The second time the client makes a GET request for that resource, it can provide that time in the If-Modified-Since header.
If the underlying data changed between the two requests, the server sends a response code of 200 (“OK”) and provides the new representation in the entity-body. That’s the same thing that happens during a normal HTTP request. But if the underlying data has not changed, the server sends a response code of 304 (“Not Modified”), and omits any entity-body. Then the client knows it’s okay to reuse its cached representation: the underlying data hasn’t changed since the first request.

P139
我还需要为不能处理的请求作考虑。假如遇到出错的情况,我会返回一个在 3xx、4xx、5xx 范围内的响应代码,并在 HTTP 报头里给出补充信息。假如响应包含实体主体,那肯定是一个描述错误状态的文档,而不是所请求资源的一个表示。
----------------------------
I also need to plan for requests I can’t fulfill. When I hit an error condition I’ll send a response code in the 3xx, 4xx, or 5xx range, and I may provide supplementary data in HTTP headers. If they provide an entity-body, it’ll be a document describing an error condition, not a representation of the requested resource (which, after all, couldn’t be served).

2008年6月15日星期日

RESTful Web Services 中文版 读书摘要 第四章

P81
任何事物,只要具有被引用的必要,它就是一个资源。
----------------------------
A resource is anything that’s important enough to be referenced as a thing in itself.

P81
是什么令资源称得上是一个资源?它必须至少有一个 URI。URI 既是资源的名称,也是资源的地址。如果一则信息没有 URI ,它就不能算是一个资源,也不能算真正在 Web 上,而只能算作描述另一个资源的一些数据。
----------------------------
What makes a resource a resource? It has to have at least one URI. The URI is the name and address of a resource. If a piece of information doesn’t have a URI, it’s not a resource and it’s not really on the Web, except as a bit of data describing some other resource.

P86
在最终用户看来,Gmail 的 URI 始终是 https://mail.google.com/。无论作什么操作,无论从 Gmail 获取什么信息或向 Gmail 上传什么信息,你不会看到别的 URI。
Gmail有一个可寻址的版本,位于 URI https://mail.google.com/mail/?ui=html。
Gmail Web 服务是可寻址的,不过调用该服务的 Gmail Web 应用不是可寻址的。
----------------------------
From the end-user perspective, there is only one Gmail URI: https://mail.google.com/. Whatever you do, whatever pieces of information you retrieve from or upload to Gmail, you’ll never see a different URI.
Compare the Ajax interface against the more addressable version of Gmail you get by starting off at the URI https://mail.google.com/mail/?ui=html.
The Gmail web service is addressable, but the Gmail web application that uses it is not.

P90
无状态性意味着:有一种状态,是服务器不应该保存的。实际上,状态分为两种。从现在开始,我将区分应用状态与资源状态:前者应该保存在客户端,后者应该保存在服务端。
----------------------------
Statelessness implies there’s only one kind of state and that the server should go without it. Actually, there are two kinds of state. From this point on in the book I’m going to distinguish between application state, which ought to live on the client, and resource state, which ought to live on the server.

P90
每当客户端向服务器发请求时,请求里必须包含服务器处理该请求所需的所有应用状态。
各个客户端应当管理自己的应用状态。
----------------------------
This means that whenever a client makes a request, it must include all the application states the server will need to process it.
The client should be in charge of managing its own path through the application.

P95
将超媒体作为应用状态的引擎。
客户端应用状态在服务器提供的超媒体(即超文本表示里的链接和表单)的指引下发生变迁。
----------------------------
Hypermedia as the engine of application state.
The server guides the client’s path by serving “hypermedia”: links and forms inside hypertext representations.

P97
HTTP四种基本方法:
获取资源的一个表示:HTTP GET
创建一个新资源:向一个新 URI 发送 HTTP PUT,或者向一个已有 URI 发送 HTTP POST
修改已有资源:向已有 URI 发送 HTTP PUT
删除已有资源:HTTP DELETE
----------------------------
Retrieve a representation of a resource: HTTP GET
Create a new resource: HTTP PUT to a new URI, or HTTP POST to an existing URI
Modify an existing resource: HTTP PUT to an existing URI
Delete an existing resource: HTTP DELETE

P98
HEAD 请求就是比 GET 请求少返回实体主体而已。
----------------------------
HEAD gives you exactly what a GET request would give you, but without the entity-body.

P99
在一个 REST 式设计中,POST 通常被用于创建从属资源——即从属于“父”资源(另一个资源)而存在的资源。
----------------------------
In a RESTful design, POST is commonly used to create subordinate resources: resources that exist in relation to some other “parent” resource.

P99
PUT 与 POST 的区别就在于:假如是客户端负责决定新资源采用什么 URI,那就用 PUT;假如是服务器负责新资源采用什么 URI,那就用 POST。
----------------------------
The difference between PUT and POST is this: the client uses PUT when it’s in charge of deciding which URI the new resource should have. The client uses POST when the server is in charge of deciding which URI the new resource should have.

P100
给一个资源发 POST 请求,未必总是创建一个全新的从属资源。有时,当向一个资源 POST 数据时,它把你发来的信息附加到它自身的状态上,而不是用该信息新建一个资源。
----------------------------
The information conveyed in a POST to a resource doesn’t have to result in a whole new subordinate resource. Sometimes when you POST data to a resource, it appends the information you POSTed to its own state, instead of putting it in a new resource.

P102
假如对一个资源做某操作是幂等的,那么无论对该资源做多少次这种操作,结果总是一样的;对该资源的第二次及其后各次操作,不会令该资源的状态产生比第一次操作更多的影响。
----------------------------
an operation on a resource is idempotent if making one request is the same as making a series of identical requests. The second and subsequent requests leave the resource state in exactly the same state as the first request did.

P103
幂等性对实践提出的要求是:不要允许客户端对资源状态做相对的改动。比如一个资源把某个数值作为其部分资源状态来保存,客户端可以通过 PUT 操作把该数值设为 4、0 或 -50,但是它不应通过 PUT 操作对该值作“加一”操作。
----------------------------
The practical upshot of this is that you shouldn’t allow your clients to PUT representations that change a resource’s state in relative terms. If a resource keeps a numeric value as part of its resource state, a client might use PUT to set that value to 4, or 0, or -50, but not to increment that value by 1.

P103
POST 既不是安全的,也不是幂等的。
----------------------------
POST is neither safe nor idempotent.

RESTful Web Services 中文版 读书摘要 第二章

P28
服务器应该是理想主义的;客户端必须是实用主义的——这是 Postel 法则“严以律己,宽以待人”的一个变形。
----------------------------
Servers should be idealistic; clients must be pragmatic. This is a variant of Postel’s Law: “Be conservative in what you do; be liberal in which you accept from others.”

P47
JSON 适用于表达数据结构;而 Web 提供的主要是文档——一种不规则的、自描述的、相互链接的数据结构。XML 和 HTML 专门用于表达文档。
----------------------------
JSON is good for representing data structures in general, and the Web mainly serves documents: irregular, self-describing data structures that link to each other. XML and HTML are specialized for representing documents.

RESTful Web Services 中文版 读书摘要 第一章

P13
REST式架构意味着,方法信息都在HTTP方法里;面向资源的架构意味着,作用域信息都在URI里。
----------------------------
In RESTful architectures, the method information goes into the HTTP method. In Resource-Oriented Architectures, the scoping information goes into the URI.

P17
Flickr web API 是一种 REST-RPC 混合架构:当客户端通过GET方法获取数据时,它是REST式的;当客户端通过GET方法修改数据时,它是RPC式的。
----------------------------
The Flickr web API is a REST-RPC hybrid: RESTful when the client is retrieving data through GET, RPC-style when the client is modifying the data set.

P18
一个 REST 式面向资源的服务为客户端可能操作的每一则数据暴露一个 URI;一个 REST-RPC 混合服务,为客户端可能进行的每一个操作暴露一个 URI(比如获取数据用一个 URI,删除数据用另一个 URI);一个 RPC 式服务,为每个处理远程调用的进程暴露一个URI,一般来说这样的URI只有一个,即服务的“端点”。
----------------------------
A RESTful, resource-oriented service exposes a URI for every piece of data the client might want to operate on. A REST-RPC hybrid exposes a URI for every operation the client might perform: one URI to fetch a piece of data, a different URI to delete that same data. An RPC-style service exposes one URI for every processes capable of handling Remote Procedure Calls (RPC). There’s usually only one such URI: the service “endpoint.”

P20
REST 式架构的主要竞争对手是 RPC 式架构,而不是 SOAP 这样特定的技术。没错,几乎所有现有的基于 SOAP 的服务都属于 RPC 式架构,但 SOAP 跟 HTTP 一样,只是一种把文档放在信封里的方式。
----------------------------
The primary competitors to RESTful architectures are RPC architectures, not specific technologies like SOAP. It is true that basically every SOAP service that now exists has an RPC architecture, but SOAP is just a way of putting a document in an envelope with stickers on it, like HTTP.

2008年6月12日星期四

flazx

http://www.flazx.com/
一个可以下载电子书的网站,纯链接式备忘。

2008年6月4日星期三

RESTful Web Services 中文版 - Preface

读完了样章的前言,发现了这样一段有趣的文字:

除非为了示范特定的框架或语言,否则我们将采用Ruby(http://www.ruby-lang.org)语言来描述。
我们选用Ruby是因为:即使对于不懂Ruby的程序员来说,它也是简洁易读的。(因为这是一门很好的语言,而且它的名字跟Sam的姓有着令人困惑的联系。)Ruby的标准Web框架——Ruby on Rails——也是最主要的一种REST式Web服务实现平台之一。如果你不懂Ruby也没关系,我们在代码中嵌入了许多有助于理解Ruby语法的注释。
----------------------------
But whenever we’re not demonstrating a specific framework or language, we use Ruby (http://www.ruby-lang.org/) as our implementation language.
We chose Ruby because it’s concise and easy to read, even for programmers who don’t know the language. (And because it’s nice and confusing in conjunction with Sam’s last name.) Ruby’s standard web framework, Ruby on Rails, is also one of the leading implementation platforms for RESTful web services. If you don’t know Ruby, don’t worry: we include lots of comments explaining Ruby-specific idioms.

这个Sam应该就是Agile Web Development with Rails, Third Edition新加入的作者,当时我就在想怎么会有这么巧的事呢,呵呵。

RESTful Web Services中文版

最先是从InfoQ中文站(here)上看到的介绍。
这是中文版的官网:http://www.restfulwebservices.cn/
去china-pub(here)上看了下,标的是5月出版,貌似刚刚上架。
样章读了一点,翻译得还不错。去淘宝订了一本,居然50都不到(原价70),真便宜啊,都不知道他从什么渠道进的货(盗版无论如何是出不了这么快的),能赚多少钱。
订完后又去官网上看了看,结果发现官网上订是免运费的,算下来和在淘宝上订花的钱是一样多。
本来还想订一本Everyday Scripting with Ruby 中文版(也是最近新出的,以前看过一点英文版的),终于还是忍住了,拒绝当收藏狂。
从china-pub和w3china.org下的样章,打开后顶上赫然挺立着“Microsoft Word - xx.doc”的字样,而从InfoQ中文站下的样章就没有,我想这就是InfoQ更细心一点点,更专业一点点的体现吧。
---------------------------------
找了个英文版的下载。
来源:http://www.matrix.org.cn/thread.shtml?topicId=a5f22fb0-61a6-11dc-acc8-0fa2717adfd4&forumId=29&fid=29

2008年4月21日星期一

Getting started with jQuery

jQuery是一个轻量级的JS库,使用很方便,功能很强大。

API速查

这是目前出的两本书:
jQuery in Action (download)
Learning jQuery (download)

some resource:
15 Days of jQuery
Getting started with Aptana and jQuery

从今天开始学习jQuery了,一定要把jQuery学好。

2008年4月19日星期六

Slash自传

Slash出自传了,书名就叫Slash
本来已经下了个PDF版的,不过是图片扫描的,看起来不爽,就删了。
节选翻译版,请点here

有些写得挺有意思的:
  • (GNR与Aerosmith一起去巡演,Axl总是迟迟不出现)Steven Tyler找到我,问:“你们主唱呢?”。自打我们第一次巡演之后,每次我们相遇他都用这句话和我打招呼。
  • “哼,看来你最近没少练琴啊?”Joe Perry就这么问Jeff,我站在一边感觉巨尴尬,那TM可是Jeff Beck呀!(呵呵,每个人都有自己的偶像)
  • 组建天鹅绒手枪之前我们尝试过和他(Sebastian Bach,Skid Row的主唱)合作当主唱,但不合适。那个组合的结果怎么说呢,听起来就像Skid Roses(穷街 + 枪花 = 穷花?)
  • November Rain中的弦乐伴奏,我们根本没有雇交响乐团,全是Axl的合声器(Axl太牛了)。
  • “我们住进了下榻的酒店,为滚石的演出做准备。第一场演出前的一早,我接到一电话说Axl不打算参加这几场演出。他的理由是我和Steven吸毒太深。。。我们是,但那根本不重要。我们是去给滚石暖场,滚石乐队啊,哥们儿!(哈哈,太搞笑了)

2008年4月9日星期三

非常男女、非常心理

结不结婚无所谓,但是一定要谈个恋爱。

恋爱中要完成的心理任务:
  • 更了解自己。
  • 培养爱别人的能力。

如果你真的爱过一个人的话,你会希望他过得好,即使自己必须离开。
如果你动了伤害一个人的念头,那么你根本就没爱过这个人,你爱的只是被爱的感觉。

谈恋爱的过程就是在“捞好处”

男人的恋爱情绪需求:
  • 能力要能被肯定。
  • 才华要能被欣赏。
  • 努力要能被感激。

女人的恋爱情绪需求:
  • 时常被关怀。
  • 需要再三的被肯定。“你到底爱不爱我嘛!”
  • 想法要能被尊重。

分手难过的原因:
  • 以前我是个受某某某喜欢的人,现在分手了,我再也不知道我是谁了,自我形象受到很大冲击,自尊受到伤害。
  • 以前那么多人你就选中了我,说明我是很特别的,现在我不再是独一无二的了。
  • 原来的稳定感被打碎了,计划全都无法实现了。

感情的成功与否,要看感情的品质,要看那两项心理任务是否达成了。
牵手不代表成功,分手不代表失败。

爱情保鲜计划:
  • 每天三次,每次三分钟。
  • 全神贯注,不受外界打扰,如关掉手机。
  • 浓情蜜意,毛手毛脚(肢体语言的沟通)。
  • 欣赏,感激。

每个女人心里的小问号:“我有没有讨人喜欢?”
每个男人心里的小问号:“我有没有让人瞧得起?”

有沟一定通

沟通出问题的原因:很多时候,我们急着跟别人沟通,是把精力都花在解决问题上面,而忽略了别人的情绪。
沟通的真正对象,是对方的心情。沟通完了后,双方的情绪都应该变得更好。
沟通的过程:开始,爽——中间,懂——结束,更爽。

真正重要的不是说了些什么,而是怎么说(肢体语言,表情,语气语调)。

跟一般人沟通有两个很重要的情绪需求:要被尊重被重视,被关爱。

学会说之前先学会听。

听的三个层次:我在,我在听,我在用心听。

常常问自己,我如果是他,我会有怎么样的感觉。

暂时避免去评论对方所说的。

EQ沟通的基本功:
  • 模仿对方的情绪状态。
  • 模仿对方说话的速度。

不应该说的十句话:
  • 你在骗人。
  • 你真是白痴,连这个都搞不懂。
  • 我才不管你怎么想呢。
  • 你根本就是胡言乱语嘛。
  • 跟你说那么多也没有用。
  • 你不喜欢也得照做。
  • 谁有时间听你说啊。
  • 我从来没见过你这么笨的人。
  • 你每次都这样。
  • 我懒得跟你啰嗦。

正确的做法:
  • 映:在沟通过程中,把自己当成镜子一样。把别人说的话,说话的内容,情绪状态都反映回去。
    • 别人:“我的男朋友跟我冷战了”。
    • 自己:“你的意思是说,你的男朋友都不理你了”。
  • 破唱片法:用跟对方不同的说话速度,重复播放(对方很大声,很激烈。而自己很小声,很缓和。直到对方的情绪也缓和下来)。
    • 小孩:“我要吃麦当劳,我就是要吃,我现在就要吃”。
    • 父母:“来,慢慢跟我说,为什么你要吃麦当劳”。

吵架三部曲:
  • 意见不和。
  • 态度之争(“你什么态度啊”)。
  • 面子之争。

在进入态度之争的时候,就要使用破唱片法。

接受批评:
  • 负责,承认:别人的批评有道理,就“闻过则喜”,勇于承认。
  • 模糊焦点:别人批评的不见得有理,但有不喜欢跟他吵。
    • 同意部分:同意别人讲得有理的那一部分。
    • 同意机率:同意这个状况会发生的可能性。“你说的也许对”。
    • 同意原则:把主词拿掉,换成一般性的。“你每次听到不中听的话,马上掉头就走,一点耐心都没有”。“的确,如果有人说着说着掉头就走的话,感觉很没有耐心”。
  • 推敲情绪:不去回答他表面的问题,而是回答他内心的情绪。

询问式:
  • 我想听听你有什么想法。
  • 我这样做会不会带给你什么困扰。
  • 那你希望我怎么做呢?
体谅式:
  • 我知道你很忙。
  • 我知道你不太同意这个做法。
提醒差异:
  • 我记得你上一次说……,你这一次又说……,你的真正意思到底是什么啊?
  • 不说但是:no but
  • 如果怎么样,会更好。

说服别人:
  • 用选择题代替是非题。
    “你要不要薯条?”
    “你的薯条是要大的还是中的?”
  • 加上“为了”
    “为了不耽误你明天的工作,请你赶快把这个东西做好交给我。”
称赞对方:从对方的外显行为来称赞他的内在。
  “你的报告写得很棒,看得出来你是个很有能力很专业的人”。

超级EQ超级销售

销售的定义:想办法去影响别人,达成共识的过程。

普通销售卖的是产品,EQ销售卖的是情绪。

一个产品有工具价值(使用价值),有情绪价值。

普通销售想的是如何赚别人的钱,EQ销售想的是如何服务别人的心。

两种重要的情绪:尊重,信任。

EQ销售前的准备:
  • 充实内在力量:传达热情,建立对产品的信仰,建立对工作的信仰(要喜欢所从事的工作,觉得工作有意义),不要害怕拒绝(别人说不,真正意思是“你还没有告诉我,为什么我值得花时间跟你聊一聊”)。

我们喜欢跟我们类似的人。
怎样让别人喜欢我:想办法让自己跟对方越接近越好。模仿对方的行为,配合对方的说话速度,了解对方的沟通习性。

人在沟通时,有三个不同的类型:
  • 视觉型,说话速度快,呼吸急促。“我看不出来这个事对我有什么好处”。
  • 听觉型,说话速度中等,呼吸速度中等。“听起来不错啊”。
  • 触觉型(感觉型),说话速度慢,呼吸慢。“我老是抓不住感觉”。

不要去假设别人需要什么,而是去问出对方的情绪需求。
从他过去使用的产品中,找出他的需求点来。

十大常见消费情绪:
快乐,安心,健康,关爱与浪漫,荣誉与骄傲,舒适,自由,接纳,有价值的感觉(物超所值),公平

EQ谈判的心理建设:
  • EQ谈判的对手是同志,不是敌人。
  • EQ谈判的对象是情绪,不是道理。
  • (谈完之后)双方皆high。

一开始的时候,提出较多的要求,以预留让步的空间。
避免造成对抗性的谈判。说“我们”而不要说“我”。
把对方的愤怒要视为是谈判的技巧,而不是一个情绪反应。
要让对方觉得他是胜利的一方,要让他觉得是赚到了:让步的空间要越来越小,速度要越来越慢。要让对方做最后的决定。
不要威胁对方他没有退路,而要告诉他我有退路。
当对方说不时,找出其真正的情绪需求。如对方说没有钱,其情绪需求可能是安心(因为没有钱,所以无法对未来安心)。如对方说没有空,其情绪需求可能是健康、自由、接纳。

人的两个相度:理性/感性,决断/深思

四种不同的人:
  • 务实型(理性,决断):个性严谨,做事一丝不苟,组织力很强,穿着正式,不喜欢不实在的包装,自信,独立,生活节奏快,喜欢接受挑战。
    • 情绪需求:希望做事有效率,需要别人的掌声,需要知道事实的真相。
    • 谈判技巧:跟他说话时速度要快,要清楚,言简意赅,要尊重对方的判断,强调自己已经被对方逼到了墙角。

  • 热情型(感性,决断):友善,喜欢寒暄,跟着感觉走。
    • 情绪需求:需要有感觉、需要被感动,需要受人喜欢(会委婉地说不),希望事情有效率。
    • 谈判技巧:跟他说话时速度要快,要带出热情,要动之以情,最好跟他问“你以前用什么样的产品”等等(跟务实性的人不要这样问)。

  • 和蔼型(感性,深思):有耐心,仁慈,体贴,办事速度会比较慢,重视人际互动,不喜欢说“不”,也不喜欢说“是”,花很多时间在思考,很重感情,不喜欢被迫做决定,不喜欢冒险。
    • 情绪需求:需要能够信任对方,希望被对方喜欢,不喜欢被逼到墙角。
    • 谈判技巧:建立信任关系,不要强迫他做任何决定,可以用一个问题来回答他的一个问题,比如:买家问:“小姐,有黑色的鞋子吗?”,卖家答:“你想要买黑色的鞋子吗?”(这招对别的类型的人不见得管用)。

  • 分析型(理性,深思):观察缜密,逻辑思考很强,对数字和时间非常敏锐精准,有完美主义倾向,做决定时凭证据说话,不会冲动
    • 情绪需求:买证据,买原则。
    • 谈判技巧:说话速度要慢,要提供详细的、按部就班的步骤来介绍,要强调佩服他的一丝不苟的精神,有事没事寄一些产品咨询给他。

积极乐观,面对挑战

这次要发的四篇文章,是张怡筠的有声书《EQ全方位成功系列》的摘抄。因为比较简练,单独看这个可能会看不太明白,最好结合听有声书。
--------------------------------------------------------------------------------------

摔跤不一定是坏事,关键是摔了后要赶快爬起来。

如果遇到挫败就一蹶不振,那么这次挫败很可能就会变成你一生中最大的失败,因为你再也爬不起来了。

挫折症候群:
  1. 有负面情绪,如:生气、沮丧、焦虑不安。
  2. 否定自我价值,觉得自己一无是处。
  3. 对未来产生绝望的感觉。

怎样处理生气的情绪:
  • 情绪的主宰是自己(错误的观念:我有权力生气)。
  • 身体是不“讲理”的,而是“讲情”的(无论自己有没有理,生气时身体的变化都是一样的。即使自己有理,一生气也同样会伤身)。
  • 愤怒就是利用别人的过错来惩罚自己(愤怒就是利用别人的愚蠢来惩罚自己)。
  • 要处理愤怒,重要的两个词:放下、原谅。
  • 怎么样原谅别人:写信法。
    • 发泄。把自己对他人的想法原原本本地写下来,要写真实的想法。
    • 原谅。站在对方的角度考虑问题,他冒犯我的原因是什么,帮他想想原因。写完了这些,再写“但是我决定原谅你,因为原谅你才能饶了自己”。

怎样处理沮丧(忧郁)的情绪:

小忧郁是心理上的感冒。

该怎么去检查是否有忧郁症:
  • 过去两个星期情绪持续低迷,对什么事情都提不起精神来。
  • 连续两个星期睡眠、食欲不正常。
  • 原来有兴趣的人事物,现在都没有兴趣了。

快乐心相法:
  • 心情不好的时候,先暂停生活的影片,自己在心里面大喊:“停——!”(把自己想象成导演,生活演得不好的时候,就喊停)。
  • 闭上眼睛,把注意力焦点集中在心脏,深呼吸,停十秒,让情绪停在那里。
  • 在大脑里幻想一些景象。幻想生活中很愉快、很兴奋、很温暖的经验。
  • 一次只会有一种情绪出现,所以用积极的情绪去替换消极的情绪。
  • 用心去思考,重新客观的看原来的问题。

挫折症候群的情绪长时间不处理的话,就会累积成压力。
压力就是长时间的身心失去平衡的状态。

真正决定我们压力感觉的,是我们怎么去定义这个事件。

面对重大改变时,抗变五部曲:
  1. 否定(不可能吧)。
  2. 愤怒(怎么会是我,为什么不是别人)。
  3. 讨价还价(如果事情还有转还的空间,我就怎么怎么样)。
  4. 沮丧(好像不幸真的发生了)。
  5. 接受(接受事实)。

打心理地基:
  1. 要乐于接受无常。
  2. 保持生活的弹性(不要太有原则)。
  3. 喜欢改变,拥抱变化。

积极乐观的做法:
  1. 为什么想法非常重要,态度在大脑里已经形成回路了,形成习惯了。
  2. 先看优点,再看缺点。
  3. 有自我掌控的能力(掌控自己的心情),不要把情绪浪费在自己无法控制的事情上。
  4. 承担责任。
  5. 控制问题范围。
  6. 生活中没有危机,只有状况。

悲观的因素:
  1. 全面化,以点概面。一件事情不好就认为所有的事都不好。
  2. 永久化,一辈子都会这样,没有终止。
  3. 个人化,认为都是自己的错。

Some books about JS

jQuery

Pro JavaScript Techniques

ppk on JavaScript

纯备忘,上面是传说中比较有名的JS方面的书,不知道什么时候才有空看。

2008年4月8日星期二

基督山伯爵

  • 假如你想发现那做坏事的人,第一就先得去发现谁能从那件坏事中取利。
  • 上帝限制了人的力量,但却给他以无穷欲望。
  • 世界是一个客厅,我们必须客客气气地退出。
  • 凡是思想清楚的头脑,晚上临睡前的最后一个念头和早上醒来时的第一个念头便是最主要的念头。

(很久没有更新Blog了,一是懒,二是前段时间事情不少心情不好,其实还是写了些,不过没有贴上来罢了。写的大部分不是计算机方面的技术。我想本Blog的定位不仅仅是程序技术吧,所有的广义上的技术都可以,只要是理性分析的。慢慢的我会整理好了贴上来。本篇是前段时间看的小说,摘抄了几句,摘抄的也应该是理性的,讲道理或者讲真理的)

2008年1月23日星期三

Rails Environments and Configuration

Whenever you start a process to handle requests with Rails (such as a Webrick server), one of the first things that happens is that config/environment.rb is loaded. For instance, take a look at the top of public/dispatch.rb:
require File.dirname(__FILE__) + “/../config/environment”

A word of caution: If you were to set the RAILS_ENV environment variable to production here, or the constant variable RAILS_ENV for that matter, it would cause everything you did in Rails to run in production mode. For instance, your test suite would not work correctly, since test_helper.rb sets RAILS_ENV to test right before loading the environment.

因为在test/test_helper.rb中,先是:
ENV["RAILS_ENV"] = "test"
再是:
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
而在加载environment.rb时,又将RAILS_ENV覆写为prodoction。

项目中使用的Rails的版本:
# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.0.1' unless defined? RAILS_GEM_VERSION

定义项目根目录:
RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)

RAILS_ROOT is used all over the place in the Rails codebase for finding files


read the config/environment.rb file as text (minus the commented lines) and parse out the RAILS_GEM_VERSION setting with a regexp.


parse_gem_version(read_environment_rb)

def parse_gem_version(text)
$1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*'([!~<>=]*\s*[\d.]+)'/
end

def read_environment_rb
File.read("#{RAILS_ROOT}/config/environment.rb")
end

Default Load Paths:

def default_frameworks
[ :active_record, :action_controller, :action_view, :action_mailer, :active_resource ]
end

def default_load_paths
paths = ["#{root_path}/test/mocks/#{environment}"]

# Add the app's controller directory
paths.concat(Dir["#{root_path}/app/controllers/"])

# Then components subdirectories.
paths.concat(Dir["#{root_path}/components/[_a-z]*"])

# Followed by the standard includes.
paths.concat %w(
app
app/models
app/controllers
app/helpers
app/services
components
config
lib
vendor
).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) }

paths.concat builtin_directories
end

def builtin_directories
# Include builtins only in the development environment.
(environment == 'development') ? Dir["#{RAILTIES_PATH}/builtin/*/"] : []
end

def default_plugin_paths
["#{root_path}/vendor/plugins"]
end

上面这个builtin_directories指的是:

It is the place for Rails to include application behavior (meaning models, helpers, and controllers). You can think about it as kind of like a framework-provided plugin mechanism.


http://localhost:3000/rails/info/properties
和在命令行下用script/about是一样的

在Rails项目里,绝大多数情况下,都不需要手动去load一个class或module,Rails有默认的规则去自动load需要的文件,其规则如下:
• If the class or module is not nested, insert an underscore between the constant’s names and require a file of this name. For example:
EstimationCalculator becomes require ‘estimation_calculator’
• If the class or module is nested, Rails inserts an underscore between each of the containing modules and requires a file in the corresponding set of subdirectories.For example:
MacGyver::SwissArmyKnife becomes require ‘mac_gyver/swiss_army_knife’

you should rarely need to explicitly load Ruby code in your Rails applications (using require) if you follow the naming conventions.

哈哈,顺我者昌

Rails::Initializer.run do |config|
...
end
里面的代码是关于Configuration的

# Settings in config/environments/* take precedence over those specified here.

The comment reminds you that the settings in the mode-specific environment files will take precedence over settings in environment.rb, which is essentially because they are loaded afterward and will overwrite your settings.


# Skip frameworks you're not going to use (only works if using vendor/rails).
# To use Rails without a database, you must remove the Active Record framework
# config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
如果项目中不用数据库,就去掉Active Record,如果不用Web service或Email,也去掉相应的模块
为什么要去掉呢:

Ruby is, of course, interpreted, and if you can get away with a smallersized codebase for the interpreter to parse, you should do so, simply for performance reasons.


# Only load the plugins named here, in the order given. By default, all plugins
# in vendor/plugins are loaded in alphabetical order.
# :all can be used as a placeholder for all plugins not explicitly named
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
plugins默认是按照字母顺序load的,也可以指定先load哪些plugin,再load剩下的(:all)

Rails takes advantage of the fact that Ruby provides a callback mechanism for missing constants. When Rails encounters an undefined constant in the code, it uses a classloader routine based on file-naming conventions to find and require the needed Ruby script.

利用Ruby提供的"missing constants"回调机制,Rails根据命名惯例去找对应的文件来load。

Want to see the contents of your project’s load path? Just fire up the console and type $:

想看项目里的load path的话,就script/console,然后敲$:(注意加上后面的冒号),然后load path就打出来了,一长串。$:是一个数组。

除了Rails提供的三种environment外,还可以自定义environment,比如:

Use the normal environment settings for development mode, but point its database connection to a production database server. It’s a potentially life-saving combination when you need to quickly diagnose issues in production.

可以用来快速诊断生产环境的问题。

使用log的方法:在irb里敲入:

require ‘logger’

logger = Logger.new STDOUT

logger.warn “do not want!!!”


log的级别(按严重程度由低到高):
debug -> info -> warn -> error -> fatal
debug是开发时方便调试程序的,生产环境中用不到。
info是一些不常发生的事件,但仍然属于正常行为范围内。
warn表示正常范畴之外的事件发生了,需要注意,值得去研究研究问题,例如:
def create
begin
@group.add_member(current_user)
flash[:notice] = “Successfully joined #{@scene.display_name}”
rescue ActiveRecord::RecordInvalid
flash[:error] = “You are already a member of #{@group.name}”
logger.warn “A user tried to join a group twice. UI should not have allowed it.”
end

redirect_to :back
end
error表示还不需要重启服务器的错误。
fatal是指能想到的最坏的情况已经发生了,你的应用现在已经挂了,需要重启服务器了。

清空log/目录下的所有.log文件

rake log:clear


development.log里包含的信息:

• The controller and action that were invoked
• The remote IP address of the computer making the request
• A timestamp indicating when the request happened
• The session ID associated with the request
• The hash of parameters associated with the request
• Database request information including the time and the SQL statement executed
• Query cache hit info including time and the SQL statement triggering results from the cache instead of a roundtrip to the database
• Rendering information for each template involved in rendering the view output and time consumed by each
• Total time used in completing the request with corresponding request-per-second figures
• Analysis of the time spent in database operations versus rendering
• The HTTP status code and URL of the response sent back to the client


资源/链接:
Rails Plugins: Extending Rails Beyond the Core
http://weblog.jamisbuck.org/2007/1/31/more-on-watchingactiverecord
http://seattlerb.rubyforge.org/SyslogLogger/

CSS定位

假定元素A有绝对定位(position: absolute),其参照物规则(即它相对于什么元素进行定位):
  • 如果A没有被包含在任何其他 position: absolute || relative || fixed 的标签里,则A是相对于浏览器窗口进行定位的。
  • 如果A被包含在了 position: absolute || relative || fixed 的标签(假设标签名为B)里,则A是相对于B的边沿来进行定位的。

常常用relative定位来给嵌套标签建立一个新的定位上下文。即外层标签是relative定位,内层被包含的标签是absolute定位。
relative的意思可以理解为“相对于我”,即“我内部的所有定位元素,都应该以我为参照物来定位”。

使用z-index可以产生元素堆叠的效果,即某些元素覆盖在另一些元素上方。
网页默认的z-index是0,数字越大,就越堆在上方,即z-index:3的元素会盖住z-index:1的元素。

假设元素D包含了两个元素A和B,D的z-index为100,A的z-index为2,B的z-index为3。堆叠的效果是:A和B都堆在D的上方,而B又堆在A的上方。
D元素变成了它内部元素堆叠的起点,A和B的z-index值都是相对于D来说的,而D在其内部的z-index默认值为0,所以A和B都能盖住D。

z-index的值最好有一些间隙。10、20、30与1、2、3的效果一样,但是前者可以在原有堆叠序列的基础上,更方便地插入其他元素。
如果想要永远置顶一个元素(即永远使它显示在最上方,盖住其他所有元素),就给它一个很大的z-index值,如10000。

隐藏元素,display:none是不占据空间的,而visibility:hidden虽然隐藏了,但仍然占据空间。
如果把visibility:hidden应用到一个绝对定位(position:absolute)的元素上,则效果和display:none一样,不占据空间。因为使用了绝对定位的元素,其本身就已经从正常页面流上消失了,本身即使显示出来,也不占据空间,而是堆叠到其他元素上方。

与绝对定位不同,固定定位(position:fixed)始终相对于浏览器窗口而言。