eslint + HTML/CSS/JS Prettify 使用经验(js格式修改)

公司质量部整了一套自己的前端代码规范,部门要求6月底前改完,因为月初和月末会统计代码质量。

虽然规范里面罗列了较多的条款,但是通过Jenkins上扫出来的highnormal级别的问题,基本集中在:
1. 缩进问题,以及tab和空格混用(公司规范要求一次缩进为4个空格)
2. 一行限制120个字符,超过需要跨行显示
3. js中使用单引号
4. 变量定义或者赋值了却没有使用,需要去除,函数传参也同理。

起初是无脑式的重复劳动,sublime里面安装了HTML/CSS/JS Prettify,但未进行深入的配置只是改了缩进配置。针对上面问题期初是这么做的:
1. HTML/CSS/JS Prettify
2. 根据扫出来的错误提示,手动去换行。
3. 无脑式的手动把双引号替换成单引号,由于js中存在dom元素的拼接,不能一键替换需要挨个检查。
4. 根据扫出来的结果手动去除,每次需要上传一遍svn,在jenkins上跑一边才能检验一遍,每次扫都是整个项目,比较费时。

手头有两个项目,第一个项目花费了很多天才改完,通过eslint + HTML/CSS/JS Prettify,另外一个项目大半天就改完了。下面是eslintHTML/CSS/JS Prettify 的使用经验,仅留作备忘。

1.安装eslint

npm install -g eslint

2.初始化配置文件,生成默认的配置文件

eslint --init

3.检测文件

eslint 你的文件(可以拖拽文件到命令行窗口)

当然也可以在项目中安装eslint,在项目中进行个性化配置。

4.根据规范配置eslintHTML/CSS/JS Prettify
找到初始化的配置文件

module.exports = {
        "env": {
            "browser": true,
            "node": true
        },
        "globals": {
            "$": true,//设置全局变量,防止报no-undef错,未定义true代表可以覆盖,false代表不可以
            "alert": false,
            "setTimeout": false,
            "location": true
        },
        "extends": "eslint:recommended",
        "rules": {
            "quotes": [
                "error",
                "single"//使用单引号,两种情况,双引号里面包含单引号,被包含的单引号被转义
                     //另外一种,单引号里面包含双引号保持原样。
            ],
            "semi": [
                "error",
                "always"//分号补全
            ],
            "no-use-before-define": [
                "error", { 
                    "functions": true, 
                    "classes": true //函数或者类须定义在使用前
                }
            ]
            //no-unused-vars 变量定义或赋值之后未使用
        }
    };

HTML/CSS/JS Prettify的配置,打开配置文件(js文件中右键--->HTML/CSS/JS Prettify --->set Prettify Preferences)

//仅展示结构和修改项
"js": {
  "allowed_file_extensions": ["js", "json", "jshintrc", "jsbeautifyrc"],
  "indent_size": 4, // Indentation size
  "indent_with_tabs": false, // Indent with tabs, overrides `indent_size` and `indent_char`
  "wrap_line_length": 120 //超过120字符数换行
}

配置好后,可以先通过HTML/CSS/JS Prettify格式化文件,然后再通过eslint 文件来扫描文件

可以通过eslint --fix 文件修复双引号、分号补全等无须手动处理的问题,剩下需要手动修改的就是no-unused-vars错误以及未定义前使用的问题了。

注意:可以单独给每个文件标注全局变量,避免no-undef错误。
示例如下:

$(function() {
    //定义全局变量
    /*global $, alert, html, location, senddataforTable, window, moment, init_select2, changeContentVm*/
});

eslint 参考链接
sublime安装package control组件教程
sublime安装插件: Preferences--> Package Control -->输入需要安装的插件名称
sublime使用插件: Ctrl + shift + P --> 输入需要调用的插件名称

Eclipse build 排除特定文件夹的校验

使用Eclipse版本

Eclipse Luna

背景

项目引进了一些前端模块node_modules,使得build需要耗费很长的时间。

方法

  1. Window --> Navigator --> Show View
  2. 在Navigator窗口,鼠标右键点击先要排除的文件夹,选择properties --> Resouurce,在Attributes区域选中Derived。

其他版本Eclipse

  1. Right-click on your project and select Properties.
  2. Choose Validation from the left-nav menu.
  3. If it is not already selected choose "Enable project specific settings".
  4. Find the validator that is relevant for what you want to exclude and click the "..." in the Settings column.
  5. Highlight the Exclude Group and click Add Rule. (If you don't have any existing exclusions you may have to add an Exclude Group.)
  6. Select Folder or file name as the Filter Type.
  7. Click Next.
  8. Select Browse Folder and find the folder you want to exclude.

Reference

Exclude directories & subdirectories from validation in Eclipse

源文件名长度大于系统支持的长度

有时候会遇到删除一个文件夹,报“源文件名长度大于文件系统支持的长度。请尝试将其移动到具有较短路径名称的位置,或者在执行此操作前尝试将其重命名为较短的名字”。
我遇到的情形是需要删除项目中的node_modules

可以安装

nmp install -g rimraf

到需要删除的文件的父级目录,运行如下命令。

//rimraf 文件名
rimraf node_modules

网站跟踪-----页面停留时间(Time on Page)

页面停留时间

停留时间 = 用户离开页面时间-用户进入页面时间

用户进入页面时间:页面载入时间

离开具体指代的事件

  • PC端浏览器

    • 页面消失
      • 点击某个离开页面的链接
      • 在地址栏中键入了新的URL
      • 使用前进或后退按钮
      • 关闭浏览器
      • 重新加载页面
    • 页面不消失

      • 最小化浏览器
      • 切换到别的tab页
  • 移动端浏览器/APP(ios/android)

    • 页面消失

      • 点击某个离开页面的链接
      • 在地址栏中键入了新的URL
      • 使用前进或后退按钮
      • 关闭浏览器/APP   * 重新加载页面(ios/android表现不同)
    • 页面不消失

      • 浏览器/APP切换到后台
      • 切换到别的tab页

难点

1. 捕捉离开页面的瞬间  
2. 在离开页面的瞬间发送数据

一、捕捉离开页面的瞬间

浏览器提供了很多接口(如事件)供js调用

我们只需给对应的离开事件绑上回调函数就可在响应的事件发生时执行对应的程序。

  • 各个浏览器事件不一定相同
  • 相同的事件不一定不支持
  • 绑定事件的方法不一定相同 -->常说的浏览器兼容分cssjs方面的,这个就是js兼容性中一些情况
找到对应的事件
PC端

浏览器unload相关事件

  1. unload 在页面变化的一瞬间,时间极短,这时候发送请求发很容易丢包
  2. beforeunload 在unload事件发生前调用,但是也不保证完全不会丢包
  3. visibilitychange 切换tab页时,如果是离开时间-进入页面时间,停留时间就会不准确,因此监听切换tab页的事件(visibilitychange)来刨去中间的时间

问题:可能存在丢包

2.谷歌分析(Google Analytics)的方案
在谷歌分析中,一般只有网站停留时间,就算是页面停留时间,第一张页面也是默认放弃的。
谷歌的做法是利用cookie存下本次的时间信息,下次进入页面再将上一次的时间发送给后台
举例:
_utma (用来识别唯一身份访客)
_utma = 127635166.1360367272.1264374807.1264374807.1264374807.1

  • 第一组数字被叫做“域哈希”,是GA表示这个域的唯一代码。同一域中每个cookie的第一组数据都是“域哈希”,并且值都是一样的。
  • 第二组数字是一个随机产生的唯一ID。
  • 第三,四,五组数字是时间戳,其中第三组数字表示初次访问的时间。第四组数字表示上一次访问的时间,第五组数字表示本次访问开始的时间。
  • 第六组数字是访问次数计数器。这个数字随着访问次数的增加而增加。 如果是第一次访问,第三四五组时间戳都是相同的。

问题:损失了只访问一次的用户,这些用户还是具有价值的

手机端
手机浏览器(Android/iOS)
  • beforeunload不再支持--->pageshow,pagehide
    window.addEventListener("pageshow", pageShown, false);
    window.addEventListener("pagehide", pageHidden, false);
    
    
    

    function pageShown(evt){
    if (evt.persisted){
    //The page was just restored from the Page Cache
    //应用切换到前台,再次记录时间
    params.entrytime = Date.parse(new Date())/1000;
    }
    else{
    //initial load
    if(localStorage.time){
    sendData();
    localStorage.time = '';
    }
    }
    }

    function pageHidden(evt){
    if (evt.persisted){
    //The page was suspended and placed into the Page Cache
    params.exittime = Date.parse(new Date())/1000;
    setLocal();
    } else {
    //page destruction
    params.exittime = Date.parse(new Date())/1000;
    setLocal();
    sendData();
    }
    }
    function setLocal(){
    localStorage.time = localStorage.time || '';
    localStorage.time += (params.entrytime + '' + params.exittime + '^');
    }
    function sendData(){
    var arg = '';
    var timeOnPage = localStorage.time.split('^');
    var difftime = 0;
    for(var i = 0; i < timeOnPage.length && timeOnPage[i]; i++){
    var time_arr = timeOnPage[i].split('
    ');
    difftime += (parseInt(time_arr[1]) - parseInt(time_arr[0]));
    }
    arg += ('difftime=' + difftime + '&');
    arg += ('serialId=' + document.getElementById('serialId').value + '&');
    arg += ('isCliked=true' + '&');
    var img = new Image(1, 1);
    img.src = 'http://218.205.115.243:10092/1.gif?' + arg;
    }


    Hybrid APP

    优点:使用Hybrid开发方法,就能集Native 和web两者之所长。一方面,Native 让开发者可以充分利用现代移动设备所提供的全部不同的特性和功能。另一方面,使用 Web 语言编写的所有代码都可以在不同的移动平台之间共享,使得开发和日常维护过程变得集中式、更简短、更经济高效。

    缺点:还不成熟,支持程度并不理想

    ios和android支持pageshow,但是完全不支持pagehide,导致没法探知应用被关闭/切换到后台的状态。正常的做法是,写好app隐藏或者关闭的回调函数,当native层探知事件发生,去调用JS回调函数。

    更改方案:
    定时向后台发送字段,后面的覆盖前面的。

    • 试验的时候是每秒向服务器请求一次,但是各个平台下机制不同,IOS下应用切换到后台,js会立即停止运行,但是android的机制是如果应用大概30s左右还不切换到前台,js就会停止运行,这样导致计时的不准确。

    • 也有人说实践过用裴波那契数列(1、1、2、3、5、8、13、21、34、……)的形式向后台发请求,这样对后台压力相对小一些。假设上一次用户在页面上待了2s,那他继续待3s的概率就更大,以此类推。

    此方案在用户基数很大的时候对服务器造成的压力太大,因此也放弃了。

    二、在离开页面的瞬间发送数据

    尽量减缓刷新这个过程

    • 动态新建img,通过src属性向后台请求一张1*1的gif图片,请求的同时把收集到的数据带过去。
    • for循环 + ajax
    • navigator.sendBeacon

Highmaps 经纬度转换为svg图上坐标

最近做后台报表展示系统,用到Highcharts。Highcharts兼容所有现代浏览器及低版本的IE浏览器(IE6+),可配置性高,包括颜色、线条,点,点的形状、背景图等等。

地域上展示需要Highmaps。遇到一个需求,需要根据某个城市的经纬度,在地图上实时显示这个点。这就需要将经纬度通过一定的转换,转化为图上的坐标点。实际上这是一件很简单的事情,生成地图的时候肯定是根据某种计算规则转换出来的,所以只要根据这个规则来转换就可以了。

但是现实往往没有想象的那么简单。


Highcharts Error #22是说地图不支持经纬度转换成图上坐标,但是我的地图数据确实是从官方下来的,且是1.1.0版本以上的。
后来找了好多地方,终于在stackoverflow上找到了答案。

首先,要进行经纬度转换需要用到Proj4js,Proj4js通过某种规则将一个坐标系上的点向另一个坐标系做投影,在这里就是将实际的地理位置投影成平面上的点。所以需要引入Proj4js,注意,引入的位置在highcharts之前

其次,既然是从官方下的数据,为什么它识别不了是自己的数据呢?原因在于对原始地理数据的处理上不妥。

var data = Highcharts.geojson(Highcharts.maps['countries/cn/custom/cn-all-china']);

$.each(data, function (i) {
    this.drilldown = this.properties['drill-key'];
    this.value = i; 
});

$('#container').highcharts('Map', {
    // ...
    series : [{
        data : data,
        name: '中国'
    }]
});

这样会导致highmap无法识别这是从它库里荡下来的数据。因此,不允许你使用经纬度转换。解决这个问题需要保留原始数据不变,另外备一份数据,调用highmap自身的方法joinBy,让它自己去拼合数据。

var mapData = Highcharts.maps['countries/cn/custom/cn-all-china'],
    myData = Highcharts.geojson(Highcharts.maps['countries/cn/custom/cn-all-china']);

$.each(myData, function (i) {
    this['hc-key'] = this.properties['hc-key'];
    this.drilldown = this.properties['drill-key'];
    this.value = i;
});

$('#container').highcharts('Map', {
    // ...
    series : [{
        data : myData,
        mapData : mapData,
        joinBy: 'hc-key',
        name: '中国'
    }]
});

看着万事俱备,其实前面还有坑。为了方便调试,引入的Proj4js、map都是src.js未压缩的。

Highcharts.maps["countries/cn/custom/cn-all-china"]={
"title":"China with Hong Kong, Macau, and Taiwan","version":"1.1.1","type":"FeatureCollection","copyright":"Copyright (c) 2014 Highsoft AS, Based on data from Natural Earth","copyrightShort":"Natural Earth","copyrightUrl":"http://www.naturalearthdata.com",
"crs":{
    "type":"name",
  "properties":{"name":"urn:ogc:def:crs:EPSG:3415"}},
  "hc-transform":{
    "hc-transform":{"default":{"crs":"+proj=lcc +lat_1=18 +lat_2=24 +lat_0=21 +lon_0=114 +x_0=500000 +y_0=500000 +ellps=WGS72 +towgs84=0,0,1.9,0,0,0.814,-0.38 +units=m +no_defs","scale":0.000129831107685,"jsonres":15.5,"jsonmarginX":-999,"jsonmarginY":9851.0,"xoffset":-3139937.49309,"yoffset":4358972.7486}
},...}}

"lcc","18","24","21",..."WGS72"这几个参数的后面都有空格,而proj4js都没有做trim处理,导致报错。
可以将空格去掉或者proj4s添加trim操作。
最后就圆满完成任务了。
下图是效果图。

参考链接:
HIGHMAPS - MAP COLLECTION
STACKOVERFLOW

怎样跟谁都能说上话

How to Start a Conversation with Absolutely Anyone

Did you know that public speaking is often rated the number one thing people are afraid of? But while getting up on a stage in front of an audience can definitely be nerve wracking, many people find striking up a conversation one-on-one just as intimidating.
你知道吗,人们最害怕的事往往是公众演讲?站在台上在众人之前演讲的确让人紧张万分,但有些人甚至害怕发起一对一的对话。

Maybe it’s the CEO of your company, a new colleague, the guy in the mail room, the girl from IT, or a stranger in the street. Whomever you want to talk to, there’s a way to strike up a conversation. And the best news is that it gets easier with practice.
他也许是你公司的CEO,一个新同事,收发室里的工作人员或者来自IT行业的女士。不管你想和谁交谈,总有一个方法能让你搭上讪。最好的意见是熟能生巧。

Try these conversation starters to talk to absolutely anybody:
试着用下面的话和任何人搭讪:

  • Skip the small talk.
    不要再用这些衰招了。
    “What’s up with this weather?” and “How ‘bout them [insert local sports team]?” are as bad as cheesy pick-up lines when it comes to starting a conversation. Avoid tired topics. Every situation is unique, so you should be able to find a unique conversation starter.
    搭讪时,“今天天气怎样?”以及“【当地球队】打得怎么样?”已经是陈芝麻烂豆了。避免乏味的话题。不同的情景需要不同的话来搭讪。

  • Ask for their opinion.
    征求意见。
    Everyone has one! For someone you don’t know well, start with light subjects like the food, the music, the atmosphere, etc. “Do you like your Margaritas with salt or without? Do you watch horror movies? Do you like this song?” It’s probably best to stay away from really sticky subjects like politics unless you already know the person very well.
    每个人都有自己的喜好。对于你不了解的人,你可以从一些轻松的话题切入,比如音乐,氛围等。“你的玛格丽特酒要加点盐吗?你看恐怖电影吗?你喜欢这首歌吗?”最好远离艰涩的话题如政治,除非你很了解你谈话的人。

  • Ask for their advice or recommendations.
    征求建议。
    This works very well when commenting on someone’s outfit or accessories, as in “What a great tie! Where did you get it?” or on the food, as in, “Everything looks good. What are you having?”
    当谈论某人的服装或配饰是这一招很受用,如“你的领结真好看!你在哪儿买的?”或者关于食物,“所有的看起来都很好吃,你要吃什么?”

  • Ask them a question — that’s easy to answer.
    提问题——问题要容易回答。
    This is great when you know or find out that a person has expertise in a particular field. If you’re talking to your company’s IT guy, for example, you could ask him whether he’s the guy who installs hardware or software. But avoid asking anyone to explain something super complex or involved; if that’s where the conversation leads, great, but asking a really complicated question up front can feel demanding.
    这一招很适合在你知道或发现某人在某个领域有专长的时候用。例如,如果你和公司的IT男/女交谈,你可以问他擅长软件还是硬件。但不要问特别复杂的问题,如果实在避免不了,那就这能这样了。但记住,问复杂的问题会让人觉得被命令回答一样。

  • Comment on the environment.
    评价一下环境。
    No matter where you are, there are things to comment on: the music, the food, the lights, the guests, and so on. Even if you are stuck in an elevator with someone, you can comment on the music, the speed, the crowdedness, etc.
    不管你在哪儿,总有东西能让你评价:音乐、食物、灯饰和宾客等。即使你和别人挤在一个电梯里,你也可以评价音乐,电梯的速度和电梯的拥挤等。

  • Ask for an update.
    询问进展。
    If you know someone a little or know them by reputation, ask for an update on something you know they’ve been doing, for example, “Oh, Mary mentioned you were taking swing dance classes. How’s that going?”
    如果你对某人略知一二或只是听说过他,问一下他正在做的事,有什么进展。比如,“Mary说你报了班学摇摆舞,学的怎么样了?”

  • Ask open-ended questions whenever possible.
    什么时候都要问发散式的问题。
    If your question can be answered with a simple yes or no, don’t be surprised if that’s what you get. Having follow-up questions ready can also help the conversation flow. If you are asking what kind of food they’re having, for example, you might follow up with, “That sounds good. Do you know what kind of wine would go well with that?” Almost everything can be followed up with, “Why?” (Just don’t ask it too many times and end up sounding like a three-year-old!)
    如果你的问题可以用简单的是或否来回答,得到这样的回答你也不要觉得奇怪了。想好接下来要问什么也能让对话持续下去。比如,你问人家在吃什么,可能会接着问,“好像很不错。你知道吃这个该搭配什么样的酒吗?”几乎所有的对话都可以用“为什么”来承接(只是不要问太多次,这样会让人觉得你是三岁毛孩)。

  • Ask a hypothetical question.
    问假设性的问题。
    These can be great conversation starters, but try to tie them into something happening at the event or in current events to avoid seeming too random. You might say something like, “I just saw this movie where all the laws were revoked for one day. What would you do if there were no laws for a day?”
    这可以作为很好的搭讪方式,尽量与当下发生的事联系起来,这样不会显得很随意。你可以这样说,“我刚看了一部电影,讲述的是有一天,所有的法律都不存在了。如果是你,这一天你会做什么?”

  • Ask about their kids, pets, or hobbies.
    询问孩子,宠物或爱好。
    People love to talk about the things that are important to them. If you know that your boss loves to sail, asking him about his latest trip is a surefire way to get him talking.
    人们喜欢谈论对他们重要的事物。如果你知道你的老板喜欢航行,问他最近的旅行他肯定会和你侃侃而谈的。

阅读全文

十年后,你会是怎样的女子?

二十几岁的女孩,可曾想过,十年后,你会是怎样的女子?

和姐姐聊天时,看到她的签名改成了“时间是把杀猪刀”,问她为何作此感慨,她发照片给我看。图片上是一个抱小孩的女人,很随便的短发,身材胖胖的,很明显的双下巴,牛仔裤紧紧地贴在肉肉的腿和鼓鼓的小腹上,浅米色的上衣极其普通,但笑容很幸福,是你走在街上随意看到一个带小孩的女人脸上都洋溢着的那种母亲的笑容。姐姐问我你还记得婷婷吗?我骇然,给姐姐发了四个字,判若两人。婷婷是姐姐的高中同学,记忆中的她高高瘦瘦的,皮肤有点黑,那时也是短发,但干净利落,青春逼人。而照片上的她足有当年两倍胖,甚至不止。姐姐又发给我一张照片,还是个女人,烫着很平庸的卷发,微胖的身材,坐在床上抱着毛绒玩具温和的笑着。不能说不美,但真的是走在人群中我不会丝毫留意的那种青春已过的女子。姐姐说,她是海鸥。我更加惊讶。姐姐大我四岁,我上初中时她上高中,但我和她的同学极为相熟。那时候觉得海鸥是姐姐身边同学中最漂亮的一个,她留着很长很长的头发,有时候会扎成两个马尾,身材纤细玲珑,穿着裙子的样子像极了美少女战士,很有灵气。多年过去,姐姐的这些同学我再没见过,只是没想到,若干年后,还未及三十岁,她们已再不是当年的模样。

姐姐说,这回明白我签名的含义了吧。我微笑感慨,女人的青春真短暂。又开玩笑说,怪不得现在很流行女人对小三说,谁没有年轻过。


What kind of girl will you be ten years later?
You girls who are in your twenties, have you ever think about what kind of girl you'll be ten years later?

While chatting with my sister, I notice that her status has changed. It goes, 'Time is the knife of a butcher’. I ask her why. She doesn't answer but sends me a picture. It is a woman with a baby in her arms. The woman is fat and jowly with casually short hair. Her jeans go tightly with her fleshly legs and bulging belly. Her light beige coat is a common one, but her smile, which would appear on the face of any mother, tells her happiness. 'Do you still remember Tingting?’ my sister asked. I'm shocked. How can I forget? Tingting is my sister's schoolmate in high school. In my memory, she was thin and tall with dark skin and short hair, too. But she looked cool and shiny then. Now she is twice or more fatter than she was. Sister sends me another picture. This time, it is a woman with plain curl hair, a little fat body, sitting on the bed with a plush toy in arms and smiling. You can't deny her beauty. However, it is true that she is the kind of woman who has lost her bloom and would not catch any attention in crowd. 'She is Seagull.' my sister surprises me again. My sister is four years older than me. I was in middle school when she was in high school. But I was quite familiar with her classmates. At that time, I think Seagull was the most beautiful one of my sister's friends. She kept long hair and sometimes bound it up into two. She was thin and looked pretty in dress, just like Sailor Moon. Years passed away. I didn't meet my sister's classmates any more. But beyond my expectation, they've changed so much even when they're younger than 30. 'Now you can understand the meaning of my status.' said my sister. Yes! I smiled to accept the shortness of women's youth. Now I understand why nowadays more and more women would like to say to The Third Woman that we all had youth and charm before.

面试必须说谎的原因以及必须说的谎

All of the characteristics HR looks for in a job candidate are the polar opposite of what enlightened leaders seek in new talent. While HR is tediously focused on making certain that candidates "play well in the sandbox," strong managers want those who don't venture near the proverbial box. Which creates a conundrum and a paradox:to get to the latter you need to lie to the former. As well you should. Why be held hostage to a broken system?
HR看重的应聘者特质和有眼光的领导需要的特质有着天壤之别。HR一味得关注“良好的团队合作精神”,领导需要的却是不走寻常路。这就带来了一个难题和悖论:要想一面到底就必须对HR说谎。你也应该说谎,我们没必要跟败坏的系统作对。

Case in point: the HR person will likely ask you if you work well with others? Well, many of the smartest and most innovative people on the planet simply don't. Not that they are trouble makers or in any way venal but they simply prefer to work alone, creating marvels of software, mathematical formulas or extraordinary feats of creativity. But can they tell HR:
举个例子来说:HR很有可能会问你的团队合作情况。很多高智商和有想法的人往往不会和人合作得太愉快。并不是因为他们想惹麻烦或者独享劳动成果,他们只是喜欢独自工作,私人的空间激发他们创造超赞的软件,数学程式或者极具创意的成果。但是他们能对HR说:

"No. I don't really like working with others. I guess you can say I do my best work by myself. My professors at MIT used to call me a 'loner.'"
“不,我不喜欢和别人合作。我想我独自一人工作时表现最好。我在MIT时,我的导师叫我独行侠。”

HR's universal reaction to this honest response would be "Next." Einstein and Newton would have failed their test.
对这种诚实的回答,HR的普遍反应是“下一位。”如果爱因斯坦和牛顿去面试,应该会通不过。

For years, my firm worked with a hedge fund that invests capital based on quantitative strategies, developed by their team of math and physics brainiacs. None even pretend to enjoy the social aspects of the work environment. For them, it is all about hibernation, concentration and introspection. They never stepped into a a sandbox as kids and they aren't about to start now.
多年来,我的公司基于量化的工具管理用于投资的对冲基金。这些工具是由一支在数学和物理方面极具造诣的团队开发的。他们没有一人会假装自己喜欢工作环境中的任何社交。对他们来说,他们眼里只有蛰伏、专注和自省。他们从未融入团队,他们也不打算这样做。

Over the course of an intense year when we examined and adjusted many of the practices of the fund, management came to recognize that the caliber of the candidates coming to them for second-stage interviews was way down below the quality hierarchy. On closer examination, we discovered the HR filter was turning the best and the brightest away before they could be seen by senior fund managers -- all geeks and loners in their own right. The solution was simple: HR was limited to managing the fund's employee benefits and policies and completely removed from the hiring process.
经过紧张的一年,当我们检查和调整了公司的运作,但是管理层在第二阶段的面试时发现应聘者的才智远比要求的素质等级低。经过仔细的检查,我们发现在最好的人才在见到高级管理层之前早就被HR筛除了。所有的极客和独行侠都这么错失了机会。解决方法很简单:要知道HR的职能只局限于管理公司的员工福利和政策以及初步筛选。

Another HR question that demands a lie goes like this:
另一个HR会问而你必须说谎的问题是:

"So tell me why you want to work for our company."
“谈一谈为什么你想加入我们公司。”

In many cases, the honest answer would be:
很多情况下,诚实的回答是:

"I think this is the best place to make a fortune before I'm 35. I really want a chunk of those stock options."
”我觉得这是我35岁之前赚大钱最好的去处。我真的很想要股票和期权。”

But to the HR paint-by-numbers gang, that would lead to a fast dismissal out the fire exit. To get to the next-stage interview you have to lie, waxing poetic about the company's innovative culture or lionizing it's irreverent founder (who, by the way, is eager to have brilliant wealth-seeking hot shots on the team).
但对于墨守成规的HR,你很可能就被刷了。为了进入下一轮面试,你必须说谎,对公司的创新型文化润润色或者吹捧一下创始人(他如何在团队中脱颖而出,创造了巨大的财富)。

The old adage "Just be yourself," is a fool's game when it comes to the hiring process. Instead, at the outset, you need to be what HR wants you to be. And in most cases, you need to (and very well should) lie to win a pass to see the real players in the company. The ones with a 180 degree different (from HR) perspective on life/business/success and how to get what you want in your career.
招聘时,愚蠢的人才会照古话说的“展现真我”。相反,你需要成为HR喜欢的那种人。大多数情况下,如果你对生活/工作/成功的看法和HR南辕北辙,你需要(而且很有必要)通过说谎来进入下轮面试。

Look, I don't believe in making lying a way of life--in fact, I appreciate blunt and honest people and think of myself in this way. But when a system is stacked against the truth, dance around it.
我并不认同将说谎作为一种生活方式---事实上,我欣赏直率和诚实的人,我自己也朝着这方面发展。但是当一个体系有悖于事实得运转时,请配合它。

阅读原文:

When you are old

---by William Butler Yeats

When you are old and grey and full of sleep,

And nodding by the fire, take down this book,

And slowly read, and dream of the soft look,

Your eyes had once, and of their shadows deep;

How many loved your moments of glad grace,

And loved your beauty with love false or true,

But one man loved the pilgrim Soul in you,

And loved the sorrows of your changing face;

And bending down beside the glowing bars,

Murmur, a little sadly, how Love fled,

And paced upon the mountains overhead,

And hid his face amid a crowd of stars.

当你老了冰心译)

当你老了,头发花白,睡意沉沉,

倦坐在炉边,取下这本书来,

慢慢读着,追梦当年的眼神

那柔美的神采与深幽的晕影。

多少人爱过你青春的片影,

爱过你的美貌,以虚伪或是真情,

惟独一人爱你那朝圣者的心,

爱你哀戚的脸上岁月的留痕。

在炉栅边,你弯下了腰,

低语着,带着浅浅的伤感,

爱情是怎样逝去,又怎样步上群山,

怎样在繁星之间藏住了脸。


威廉·巴特勒·叶芝(William Butler Yeats),是爱尔兰诗人、剧作家和散文家,著名的神秘主义者,也是“爱尔兰文艺复兴运动”的领袖,艾比剧院(Abbey Theatre)的创建者之一。叶芝的诗受浪漫主义、唯美主义、神秘主义、象征主义和玄学诗的影响,演变出其独特的风格。叶芝的艺术代表着英语诗从传统到现代过渡的缩影。

14种人格让你人见人爱

Personal branding through social media may help you build your professional network, but there will never be a replacement for a charismatic personality.
社交媒体能塑造你的人脉,但永远不能和人格魅力相媲美。

Napoleon Hill, author of "Think and Grow Rich" — one of the top-selling books of all time — wrote about the habits of the most likable people in his essay "Develop A Pleasing Personality," published in the forthcoming collection "The Science of Success."
畅销书《思考致富》的作者,拿破仑·希尔在其论文《培养令人愉悦的人格》一文中提出了最受欢迎的人所具有的人格。该论文即将和《胜利的科学》文集一起出版。

He introduced his steps to having a "million-dollar personality" by explaining it was steel magnate Charles M. Schwab's charming demeanor that in the late 19th century elevated him from day laborer to an executive with a $75,000 salary and a frequent million-dollar bonus (astronomical numbers for the time).
他通过解释19世纪末,钢铁巨头查尔斯·施瓦布如何凭借其人格魅力从一个普通劳工晋升为年薪7.5万美元,并时不时有百万奖金的经理,来介绍价值百万美元的人格是如何养成的。

Schwab's boss, the legendary industrialist Andrew Carnegie said "the yearly salary was for the work Schwab performed, but the bonus was for what Schwab, with his pleasing personality, could get others to do," Hill writes.
施瓦布的老板,传奇实业家安德鲁·卡内基曾说过:“工资是施瓦布工作所得,但奖金是因为他的人格魅力。”

Here are Hill's 14 habits of people who are so likable that others go out of their way to help them:
以下是希尔所述14种人格,拥有这些人格的人格外受人喜爱,因此而“得道多助”。

  1. They develop a positive mental attitude and let it be seen and felt by others.
    他们总是积极向上,并让他人看到和感受到。
    It's often easier to give into cynicism, but those who choose to be positive set themselves up for success and have better reputations.
    通常,一个人变得愤世嫉俗很容易,但有些人却选择了积极追求成功,并且获得了更好的声望。

  2. They always speak in a carefully disciplined, friendly tone.
    他们说话总是严谨并且友好
    The best communicators speak deliberately and confidently, which gives their voice a pleasing sound.
    最善于沟通的人说话总是经过深思熟虑并且很有自信,给人以愉悦的感觉。

  3. They pay close attention to someone speaking to them.
    他们密切关注跟他们交谈的人
    Using a conversation as an opportunity to lecture someone "may feed the ego, but it never attracts people or makes friends," Hill says.
    希尔说:“通过对话来教育他人可能会满足一下你的自尊心,但是绝不会吸引人或是成为朋友。”

  4. They are able to maintain their composure in all circumstances.
    他们总能够在任何场合保持冷静
    An overreaction to something either positive or negative can give people a poor impression. In the latter case, says Hill, "Remember that silence may be much more effective than your angry words."
    积极抑或是消极的过度反应会给人留下坏印象。如果是后者,希尔说:“记得沉默比愤怒的言辞更有效。”

  5. They are patient.
    他们都是有耐心的人。
    "Remember that proper timing of your words and acts may give you a big advantage over impatient people," Hill writes.
    希尔写到:“记得,和没耐心的人比等待合适的时机说话或行动将会是你的一大优势。”

  6. They keep an open mind.
    他们态度开明
    Those who close themselves off from certain ideas and associate only with like-minded people are missing out on not only personal growth but also opportunities for advancing their careers.
    思想闭塞和只凭自己喜好结交朋友的人不仅错失了个人的成长,更错失了事业前进的大好机会。

  7. They smile when speaking with others.
    和别人交谈时,他们总是面带微笑
    Hill says that president Franklin D. Roosevelt's greatest asset was his "million-dollar smile," which allowed people to lower their guards during conversation.
    希尔说罗斯福总统最大的遗赠是他价值百万的微笑,微笑使人在对话中放松警惕。

  8. They know that not all their thoughts need to be expressed.
    他们深知不是所有的想法都需要表达出来
    The most likable people know that it's not worth offending people by expressing all their thoughts, even if they happen to be true.
    人见人爱者知道,为了表达自己所有的想法而去得罪一个人是不值得的,即使你的想法是正确的。

  9. They don't procrastinate.
    他们办事从不拖沓
    Procrastination communicates to people that you're afraid of taking action, Hill says, and are therefore ineffective.
    拖延让人觉得你畏惧采取行动,希尔说,从而让人觉得你办事没效率。

  10. They engage in at least one good deed a day.
    他们坚持每天至少做一件好事
    The best networkers help other people out without expecting anything in return.
    最擅长社交的人总会不计回报的帮助他人。

  11. They find a lesson in failure rather than brood over it.
    面对失败他们吸取教训而不是一味懊丧
    People admire those who grow from failure rather than wallow in it. "Express your gratitude for having gained a measure of wisdom, which would not have come without defeat," Hill says.
    面对失败迎难而上而不是一蹶不振的人令人敬佩。“吃一堑,长一智,我们应该感谢失败”,希尔说。

  12. They act as if the person they are speaking to is the most important person in the world.
    谈话时,他们表现得好像在跟世界上最重要的人讲话。
    The most likable people use conversations as an opportunity to learn about another person and give them time to talk.
    人见人爱者总是把谈话当作了解一个人的机会并细细聆听。

  13. They praise others in a genuine way without being excessive.
    他们真诚且毫不夸张的赞美他人
    "Praise the good traits of others, but don't rub it on where it is not deserved or spread it too thickly," Hill says.
    “赞美别人的优点和值得赞美之处,切忌过分赞美,”希尔说。

  14. They have someone they trust point out their flaws.
    他们有信任的人为他们指出错误
    Successful people don't pretend to be likable; they are likable because they care about their conduct and reputation. Having a confidant who can be completely honest with them allows them to continue growing
    成功的人不会刻意去让人喜欢;受人喜欢是因为他们注意自己的行为和名声。他们有绝对诚实的密友敦促他们进步。

阅读原文14 habits make you extrordinately likeable