8 Daily Habits Of The Happiest People In The World

If only there was a machine that could measure the level of happiness and distinguish what affects it… Oh wait, there isn’t. And yet, in most cases, we can tell a happy person from an unhappy one. Why is that so? We’ll look at some of the happy people and explore their routines. As these are different people, their habits may seem to contradict each other, but that’s just a surface of things. Needless to say, these habits won’t necessarily make you happy; still, they may be a great source of inspiration for another joyful day. What do happy people do?

1. They value family and company

Indonesians are a well-known proof of a popular axiom ‘wealth is not everything’. Living in slums, not having enough fresh water, facing tsunamis and the discomforts of overpopulation, they rejoice in their families and friends. In the country where different ethnicities and religions coexist, there is a special sense of tolerance. The national survey reports that it’s family matters that make Indonesians so happy.

2. They try to fulfill their basic needs

In many respects, especially those connected with climate, we can’t change our comfort zone, but this is not the reason to deprive yourself of those basic needs that can be fulfilled. What about the joys of sleep? Richard Shane, a scientist who once suffered through insomnia, has dedicated an entire series of articles to sleeping well. They feature the matters that are not covered in the literature of this kind too often, for example, about relaxing your tongue. The scientist says that sleep deprivation can really make you unhappy, and on the contrary, healthy sleep has enormous positive impact.

3. They help other people

This works simply and surely: when you help others, you are not alone in this world, and happiness of others makes you happy, too.

Mahatma Gandhi was reported to say, “The best way to find yourself is to lose yourself in the service of others.”

Working with pets often helps overcome depression.

4. They can stand up and say no

There is a chance you can be lost in volunteering and helping others – in a bad sense. As every worker, volunteers may get a burnout, which has already become a popular research subject.

Sonya Derian says, “If you say yes to everything, never discerning the right yes for you, what difference does it make what you’re saying yes to? Your yes loses its authority”.

5. They stop living for the future

Alan Watts, a philosopher and writer who used to popularize Eastern philosophy in Britain, particularly in his book ‘The Wisdom of Insecurity: A Message for an Age of Anxiety’, argues that we live in the future too much. Craving to live better, people hurry, work too hard, and struggle emotionally for the sake of abstract future. But it is possible to live happily in the present without the assurance that the future will also be good.

6. They have a dream

Another Eastern concept of happiest people gaining popularity in the West is ikigai, “the reason you wake up in the morning”, and some happy people definitely have one. The legend has it that one woman was returned to life after a lethal disease when to the ancestors’ question ‘Who are you?’ she answered: “I am the one who wakes up each day to care for my family, and nurture the young minds of the children at my school”. A dream is something about the future, and yet it can shape your happy present.

7. They make things happen

They don’t cry for the moon and don’t complain. Despite of his ASL, Stephen Hawking has made prominent scientific discoveries. What is more, he found vivid words to tell the world about his findings.

8. They can wait

Sophie Fontanel is a writer who spent many years in deliberate celibacy. Not that she didn’t want sex at all and not that she was against it. She only insisted that people can wait. They don’t need to force themselves info relationships just for the reason that everyone does it. This waiting is not at all like waiting for a prince.

“I think it’s a mistake to think that women are always expecting love. We are expecting to be in good hands, even if these good hands are just for two nights or one week”.

This doesn’t mean that you have to live in celibacy but it means that sometimes you have to wait for what you desire. Happy people can be passionate about other cravings just like this.

基于jquery插件编写

对于Jquery插件的使用,已经司空见惯:如下:

<html>

<body>
<script type="text/javascript" src="jquery-1.10.2.min.js"></script> 
<script type="text/javascript">
    $(function() {
    //1. 初始化
    $("#name").write({
        color: "white",
        "background-color": "blue"
    });
    //2. 设置属性
    $("#name").write('setColor', 'red');
    //获取属性
    alert($("#name").write("color"));
}); 
<body>
<label id="name">required</label>
</html>

这个简单的插件主要是设置控件的样式,做演示效果,那如何去编写这样的插件呢?

(function($) {
    var Writer = function(element, options) {
        this.$element = $(element);
        this.options = $.extend({},
        $.fn.write.defaults, options); //合并参数
        this.init();
    };

    Writer.prototype = {
        constructor: Writer,
        init: function() {
            this.$element.css(this.options);
        },
        setColor: function(args) {

            this.$element.css("color", args);
            this.options.color = args;
        },
    }

    $.fn.write = function(options) {
        options = options || {}
        var args = arguments;
        var value;
        var chain = this.each(function() {
            data = $(this).data("write");
            if (!data) {
                if (options && typeof options == 'object') { //初始化
                    return $(this).data("write", data = new Writer(this, options));
                }
            } else {
                if (typeof options == 'string') {
                    if (data[options] instanceof Function) { //调用方法
                        var property = options; [].shift.apply(args);
                        value = data[property].apply(data, args);
                    } else { //获取属性
                        return value = data.options[options];
                    }
                }
            }

        });

        if (value !== undefined) {
            return value;
        } else {
            return chain;
        }

    };

    $.fn.write.defaults = { //设置默认属性 color:"yellow",
        "background-color": "yellow"
    };
})(jQuery);

在编写插件之前需要弄清楚几个javascript常见的几个难点:

1. this

2. prototype

3. apply

4. 内置对象arguments

http://www.ruanyifeng.com/blog/2010/04/using_this_keyword_in_javascript.html

http://www.cnblogs.com/dolphinX/p/3286177.html

http://www.zhihu.com/question/20289071

Linux部署javaee环境

1. jdk

a.下载linux版本的jdk:    jdk-7u71-linux-x64.tar.gz

b.拷贝到linux:/usr/local,解压文件 tar -xvf jdk-7u71-linux-x64.tar.gz

c.配置环境变量

vim /etc/profile

JAVA_HOME=/usr/local/jdk1.7.0_71
JAVA_BIN=/usr/local/jdk1.7.0_71/bin
PATH=$PATH:$JAVA_BIN
CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME JAVA_BIN PATH CLASSPATH

d.查看java安装

[root@iZ28t57xzbcZ ROOT]# java -version
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

2.tomcat

a.下载linux版本的tomcat:apache-tomcat-7.0.62.tar.gz

b.拷贝到linux: /usr/local,解压tar -xvf apache-tomcat-7.0.62.tar.gz

c.配置环境变量 

vim /etc/profile

export CATALINA_HOME=/usr/local/apache-tomcat-7.0.62
export CLASSPATH=.:$JAVA_HOME/lib:$CATALINA_HOME/lib
export PATH=$PATH:$CATALINA_HOME/bin

d.启动tomcat

[root@iZ28t57xzbcZ bin]# sh startup.sh
Using CATALINA_BASE:   /usr/local/apache-tomcat-7.0.62/
Using CATALINA_HOME:   /usr/local/apache-tomcat-7.0.62/
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-7.0.62//temp
Using JRE_HOME:        /usr/local/jdk1.7.0_71
Using CLASSPATH:       /usr/local/apache-tomcat-7.0.62//bin/bootstrap.jar:/usr/local/apache-tomcat-7.0.62//bin/tomcat-juli.jar
Tomcat started.

关闭tomcat

[root@iZ28t57xzbcZ ROOT]# sh /usr/local/apache-tomcat-7.0.62/bin/shutdown.sh
Using CATALINA_BASE:   /usr/local/apache-tomcat-7.0.62/
Using CATALINA_HOME:   /usr/local/apache-tomcat-7.0.62/
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-7.0.62//temp
Using JRE_HOME:        /usr/local/jdk1.7.0_71
Using CLASSPATH:       /usr/local/apache-tomcat-7.0.62//bin/bootstrap.jar:/usr/local/apache-tomcat-7.0.62//bin/tomcat-juli.jar

    

如何不用 eval 的方式通过字符串调用 JavaScript 的方法

原文链接http://wenzhixin.net.cn/2014/10/03/call_string_function


由于 bootstrap-table 插件需要支持data-name="functionName"的方式,所以在实现的过程中使用了eval的方法。我们知道,在 JavaScript 中,eval是丑陋的,在MDN中提到:

Obsolete

This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

我们通过eval执行字符串代码,例如:

eval("var x = 'Hello from eval!';");
console.log(x); 

然而,eval会带来一些意想不到的问题:

  1. 安全性问题:你的字符串可能会被注入其他的命令或者第三方脚本。
  2. 可调试问题:很难去调试错误信息。
  3. 压缩问题:程序不会对字符串进行最小化压缩。

不幸的是,在实际的开发中,eval经常会被滥用,例如解析 JSON 字符串,虽然使用eval可以正常工作,但是我们应该尽量避免使用它,例如使用JSON.parse方法。

那么,我们如何才能不用 eval 的方式通过字符串调用 JavaScript 的方法呢?

首先,假如我们有一个字符串名称的方法:

// function we want to run var func = 'runMe'; function runMe() { // do something } 

一个好的解决方法那就是我们可以通过window对象,在调用方法之前我们对其进行检查:

// find function var fn = window[func]; // runMe // is a function? if (typeof fn === 'function') {
    fn();
} 

更多的时候,我们的方法是有一系列的参数的,例如我们存放到数组中,这个我们只需要简单的执行apply方法即可:

// function name and parameters to pass var func = 'runMe'; var args = [1, 2, 3]; // find function var fn = window[func]; // runMe // is a function? if (typeof fn === 'function') {
    fn.apply(null, args);
} 

到此,我们知道了不用 eval 的方式通过字符串调用 JavaScript 的方法,是更安全、容易进行调试、运行更快的方法。

最后,将其封装成了一个工具函数:

var calculateFunctionValue = function (func, args, defaultValue) { if (typeof func === 'string') { // support obj.func1.func2 var fs = func.split('.'); if (fs.length > 1) {
            func = window;
            $.each(fs, function (i, f) { func = func[f];
            });
        } else {
            func = window[func];
        }
    } if (typeof func === 'function') { return func.apply(null, args);
    } return defaultValue;
}; 

扩展:

对字符串对象,也同样的方法处理。而对于字符串数组,则使用类似:

'[5, 10, 20, 50, 100, 200]'.replace(/, /g, ',').slice(1, -1).split(','); 

A Dad’s Letter to His Son (About the Only Good Reason to Get Married)

Dear Son,

It seems like yesterday you were blowing poop out of your diaper onto your mother’s lap. Yet here we are, on the verge of the birds-and-the-bees conversation. The poop was way easier.

Before we talk about sex, though, I want to talk about marriage. Not because I’ll shun you or shame you if you don’t put them in that order—although I hope you will—but because I believe the only good reason to get married will bring clarity to every other aspect of your life, including sex.

marriage masculinity ego

Photo Credit: bengrey via Compfight cc

Buddy, you’re probably going to want to get married for all the wrong reasons. We all do. In fact, the most common reason to get married also happens to be the most dangerous: we get married because we think it will make us happy. Getting married in order to be happy is the surest way to get divorced.

There are beautiful marriages. But marriages don’t become beautiful by seeking happiness; they become beautiful by seeking something elseMarriages become beautiful when two people embrace the only good reason to get married: to practice the daily sacrifice of their egos. 

Ego. You may be hearing that word for the first time. It probably sounds foreign and confusing to you. This is what it means to me:

Your ego is the part of you that protects your heart. You were born with a good and beautiful heart, and it will never leave you. But when I was too harsh toward you, or your friends began to make fun of your extracurricular choices, you started to doubt if your heart was good enough. Don’t worry, it happens to all of us at some point.

And so your mind began to build a wall around your heart. That happens to all of us, too. It’s like a big castle wall with a huge moat—it keeps us safe from invaders who might want to get in and attack our heart. And thank goodness for your ego-wall! Your heart is worthy of protection, buddy.

At first, we only use the ego-wall to keep people out. But eventually, as we grow up, we get tired of hiding fearfully and we decide the best defense is a good offense. We put cannons on our ego-wall and we start firing. For some people that looks like anger. For other people, it looks like gossip and judgment and divisiveness. One of my favorite ego-cannons is to pretend everyone on the outside of my wall is wrong. It makes me feel right and righteous, but really it just keeps me safe inside of my ideas. I know I’ve fired my ego-cannons at you from time to time, and for that I’m truly sorry.

Sometimes we need our cannons to survive. Most of the time we don’t.

Both men and women have ego-walls with cannons. But you’re going to be a man soon, so it’s important to tell you what men tend do with their ego walls—we justify them by pretending they are essential to being a “real” man. Really, most of us are just afraid our hearts won’t be good enough for the people we love, so we choose to stay safe and protected behind high walls with lots of cannons.

Can you see how that might be a problem for marriage?

If you fall into the trap of thinking your ego-wall is essential to being a man, it will destroy any chance of having an enduringly joyful marriage. Because, in the end, the entire purpose of marriage is to dismantle your ego-wall, brick by brick, until you are fully available to the person you love. Open. Vulnerable. Dangerously united.

Buddy, people have sex because for a moment at the climax of it, their mind is without walls, the ego goes away, and they feel free and fully connected. With sex, the feeling lasts for only a moment.But if you commit yourself to marriage, you commit yourself to the long, painful, joyous work of dismantling your ego-walls for good. Then, the moment can last a lifetime.

Many people are going tell you the key to a happy marriage is to put God at the center of it, but I think it depends upon what your experience of God does for your ego. Because if your God is one of strength and power and domination, a God who proves you’re always right and creates dividing lines by which you judge everyone else, a God who keeps you safe and secure, I think you should keep that God as far from the center of your marriage as you can. He’ll only build your ego-wall taller and stronger.

But if the God you experience is a vulnerable one, the kind of God that turns the world upside down and dwells in the midst of brokenness and embraces everyone on the margins and will sacrifice anything for peace and reconciliation and wants to trade safety and security for a dangerous and risky love, then I agree, put him right at the center of your marriage. If your God is in the ego dismantling business, he will transform your marriage into sacred ground.

What’s the secret to a happy marriage? Marry someone who has also embraced the only good reason to get married.

Someone who will commit to dying alongside you—not in fifty years, but daily, as they dismantle the walls of their ego with you.

Someone who will be more faithful to you than they are to their own safety.

Someone willing to embrace the beauty of sacrifice, the surrender of their strength, and the peril of vulnerability.

In other words, someone who wants to spend their one life stepping into a crazy, dangerous love with you and only you.

With my walls down,

Dad

From  http://drkellyflanagan.com/2014/01/29/a-dads-letter-to-his-son-about-the-only-good-reason-to-get-married/