Python简介(一)

Python WiKi:

Python是一种面向对象、直译式的计算机程序语言,具有近二十年的发展历史。它包含了一组功能完备的标准库,能够轻松完成很多常见的任务。它的语法简单,与其它大多数程序设计语言使用大括号不一样,它使用缩进来定义语句块。与Scheme、Ruby、Perl、Tcl等动态语言一样,Python具备垃圾回收功能,能够自动管理内存使用。Python是解释型语言,Python的官方解释器是CPython,该解释器用C语言编写,是一个由社区驱动的自由软件,目前由Python软件基金会管理。

优势

而不同的编程语言,干同一个活,编写的代码量,差距也很大。
比如,完成同一个任务,C语言要写1000行代码,Java只需要写100行,而Python可能只要20行。

所以Python是一种相当高级的语言。Python可以做很多的事情,比如自动备份你的MP3;可以做网站,很多著名的网站包括YouTube就是Python写的;可以做网络游戏的后台,很多在线游戏的后台都是Python开发的。

劣势

相比C,运行速度较慢。不适合做移动应用。iPhone(swift/object-c)Android(java andriod)

10 Excellent Pictures To Show What’s Wrong With Our Society

Jean Jullien is a French artist currently living in London. He is up for all sorts of graphics. Here are 10 of his powerful and honest illustrations to show what’s wrong about modern society:

1.Apple watch

People are so preoccupied with technology. Many of us spend large amount of time and energy consumed usually on smartphones, laptops, and/or Apple products. But do we really get freedom with these things, or we get more attached than ever? Moderation is the key.

2.Tinder

Do you think this is a relationship goal? I think not. This is an honest scenario where two people, supposed to be a couple, are so engaged with internet-connected gadgets which may be powering down the relationship.

3.Time

Everything we do requires time. But sadly, we can’t manage time. We can only manage ourselves. We set priorities because we can’t do everything all at once. It is hard to avoid the fact that we are running out of time. The problem with some people is they depend on “tomorrow”, but “tomorrow” will always have the same amount of time as “today”.

4.Fashion

One ultimate misconception about fashion is people need to be always up to date. But frankly, people are not necessarily responsible to always follow the latest trends. Dress what works for you and what makes you feel comfortable about yourself.

5.Fat or fit

FIT, NOT FAT!

Admit it, some people used to judge others based on the looks alone. Stop judging and start realizing: fat people are not always in bad health, same as healthy people are not always in ideal body shape.

6.Racism

Racism is prevalent. It has claimed too many lives. Everybody must be aware: humanity, not skin color, defines us.

7.Violence

Violence is never the answer! You don’t answer violence with violence. There’s no way we could get justice through it.

8.Warfare

It’s a shame how people can be this insensitive. People, who prioritize taking pictures or such selfish acts instead of helping other people, are seriously terrifying!

9.Selfie

Selfies are everywhere. But hey, what’s wrong with selfie–it’s just a picture?! Actually, there’s nothing wrong with selfies. Not until it happens to some people in social media, and as a part of common social issues, that selfies affect their self esteem and make them feel superior or inferior depending on how society judge them.

10.Listen

Blessed are those who are able to hear; gifted are those who are able to understand. People who do not listen are those you don’t need to share your life with.

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