wuztooo

点点点


  • 首页

  • 标签

  • 分类

  • 归档

tomcat监听多个端品对应多个应用

发表于 2018-04-19 | 分类于 工作笔记

java不是我的主要开发语言,所以对tomcat了解甚少。但是最近对接的第三方接口需要本地布属一个java项目,而且测试环境和正式环境还不能共用同一个项目(好坑的服务)。所以我把正式和测试项目分成两个端口对应两份项目。

贴上server.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?xml version='1.0' encoding='utf-8'?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- Note: A "Server" is not itself a "Container", so you may not
define subcomponents such as "Valves" at this level.
Documentation at /docs/config/server.html
-->
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<!-- Security listener. Documentation at /docs/config/listeners.html
<Listener className="org.apache.catalina.security.SecurityListener" />
-->
<!--APR library loader. Documentation at /docs/apr.html -->
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
<Listener className="org.apache.catalina.core.JasperListener" />
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

<!-- Global JNDI resources
Documentation at /docs/jndi-resources-howto.html
-->
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>

<!-- A "Service" is a collection of one or more "Connectors" that share
a single "Container" Note: A "Service" is not itself a "Container",
so you may not define subcomponents such as "Valves" at this level.
Documentation at /docs/config/service.html
-->
<Service name="Catalina">

<!--The connectors can use a shared executor, you can define one or more named thread pools-->
<!--
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="150" minSpareThreads="4"/>
-->


<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
Java AJP Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL HTTP/1.1 Connector on port 8080
-->
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<!-- A "Connector" using the shared thread pool-->
<!--
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
-->
<!-- Define a SSL HTTP/1.1 Connector on port 8443
This connector uses the BIO implementation that requires the JSSE
style configuration. When using the APR/native implementation, the
OpenSSL style configuration is required as described in the APR/native
documentation -->
<!--
<Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
-->

<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />


<!-- An Engine represents the entry point (within Catalina) that processes
every request. The Engine implementation for Tomcat stand alone
analyzes the HTTP headers included with the request, and passes them
on to the appropriate Host (virtual host).
Documentation at /docs/config/engine.html -->

<!-- You should set jvmRoute to support load-balancing via AJP ie :
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
-->
<Engine name="Catalina" defaultHost="localhost">

<!--For clustering, please take a look at documentation at:
/docs/cluster-howto.html (simple how to)
/docs/config/cluster.html (reference documentation) -->
<!--
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
-->

<!-- Use the LockOutRealm to prevent attempts to guess user passwords
via a brute-force attack -->
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>

<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">

<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->

<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t &quot;%r&quot; %s %b" />

</Host>
</Engine>
</Service>
<Service name="Catalina2">
<Connector port="8090" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8445" />
<Connector port="8010" protocol="AJP/1.3" redirectPort="8445" />
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>

<Host name="localhost" appBase="/var/lib/tomcat/webapps2"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log2." suffix=".txt"
pattern="%h %l %u %t &quot;%r&quot; %s %b" />

</Host>
</Engine>
</Service>
</Server>

可能因为我的tomcat是用yum安装的所以CATALINA_HOME或是TOMCAT_HOME配置有问题,所以我第二个weapps2用了绝对路径

ssh上传文件命令 scp

发表于 2018-04-12 | 分类于 工作笔记

今天拿到一个空的服务器准备布属一个java服务,感觉安装ftp太麻烦了,百度了一下发现有个命令很方便scp:

1.上传本地文件到服务器

1
scp /path/filename username@servername:/path/

2.从服务器上下载文件

1
scp username@servername:/path/filename local_dir

3.从服务器下载整个目录

1
scp -r username@servername:/var/www/remote_dir/ local_dir

4.上传目录到服务器

1
scp -r local_dir username@servername:/var/www/remote_dir

yum安装java环境

发表于 2018-04-12 | 分类于 工作笔记

安装java tomcat 相关组件

1
2
3
4
5
6
7
8
yum list installed|grep java  #检查是否已有安装java
#若已安装可删除旧的java
yum -y remove java-1.8.0-openjdk*
yum -y remove tzdata-java.noarch
#重新安装
yum -y install java-1.8.0-openjdk*
yum install tomcat
yum install tomcat-webapps tomcat-admin-webapps

安装后的webapps目录默认在/var/lib/tomcat/webapps 我们可以把它放在home目录下

Vue绑定scroll事件

发表于 2018-03-28 | 分类于 js学习笔记

vue组件里注册不了scrollg事件,百度了好久发现也有相关问题:vue组件注册的touchmove事件handler里读取到的scrollTop一直为0

我的解决办法是在created里注册:

1
window.addEventListener("scroll",this.loadMore)

但是这有个问题,就是每次加载都会绑定一个loadMore。所以我在beforeDestroy把当前的事件取消:

1
window.removeEventListener("scroll",this.loadMore)

Learn ES2015

发表于 2018-03-14 | 分类于 js学习笔记

参考(https://segmentfault.com/a/1190000003818502)

毕业到现在都没正经学过js,最近在看vue发现我的js就是土著啊。什么时候冒出这种写发

  1. 箭头函数

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    // 使用表达式(Expression bodies)
    var odds = evens.map(v => v + 1);
    var nums = evens.map((v, i) => v + i);

    // 使用函数体(Statement bodies)
    nums.forEach(v => {
    if (v % 5 === 0)
    fives.push(v);
    });

    // this 对象
    var bob = {
    _name: "Bob",
    _friends: [],
    printFriends() {
    this._friends.forEach(f =>
    console.log(this._name + " knows " + f)
    );
    },
    // _printFriend 为译者添加 是使用function时的等价写法
    _printFriends() {
    this._friends.forEach(function(f){
    console.log(this._name + " knows " + f)
    }.bind(this))
    }
    };
  2. 类

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    class SkinnedMesh extends THREE.Mesh {
    constructor(geometry, materials) {
    // 调用父类的构造函数 super是父类的实例
    super(geometry, materials);

    this.idMatrix = SkinnedMesh.defaultMatrix();
    this.bones = [];
    this.boneMatrices = [];
    //...
    }
    update(camera) {
    //...
    super.update();
    }
    // 静态方法
    static defaultMatrix() {
    return new THREE.Matrix4();
    }
    }
  3. ==增强的对象字面量==(这里我先打个问号,不知道他增强了什么。因为我之前也不知道他干了什么,有待后期!!)

  4. 模板字符串

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    // 创建基本的模板字符串
    `This is a pretty little template string.`

    // 多行字符串
    `In ES5 this is
    not legal.`

    // 插入变量
    var name = "Bob", time = "today";
    `Hello ${name}, how are you ${time}?`

    // 在模板字符串中不使用转义
    String.raw`In ES5 "\n" is a line-feed.`

    // 创建一个HTTP请求头的模板字符串,通过替换内容来构建请求
    GET`http://foo.org/bar?a=${a}&b=${b}
    Content-Type: application/json
    X-Credentials: ${credentials}
    { "foo": ${foo},
    "bar": ${bar}}`(myOnReadyStateChangeHandler);
  5. 解构

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    // 列表(数组)匹配
    var [a, , b] = [1,2,3];

    // 对象匹配
    var { op: a, lhs: { op: b }, rhs: c }
    = getASTNode()

    // 对象匹配的简写
    // 绑定当前作用域的 `op`, `lhs` 和 `rhs`
    var {op, lhs, rhs} = getASTNode()

    // 可以用在函数的参数中
    function g({name: x}) {
    console.log(x);
    }
    g({name: 5})

    // 弱化解构
    var [a] = [];
    a === undefined;

    // Fail-soft destructuring with defaults
    var [a = 1] = [];
    a === 1;
  6. 默认参数(Default) + 不定参数(Rest) + 扩展运算符(Spread)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    //默认参数
    function f(x, y=12) {
    // y is 12 if not passed (or passed as undefined)
    return x + y;
    }
    f(3) == 15

    //不定参数
    function f(x, ...y) {
    // ...运算符将x之后的参数转换为名为y的数组
    return x * y.length;
    }
    f(3, "hello", true) == 6

    //扩展运算符
    function f(x, y, z) {
    return x + y + z;
    }
    // ...运算符将数组转换为连续的参数
    f(...[1,2,3]) == 6
  7. Let(局部变量) + Const(常量)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    function f() {
    {
    let x;
    {
    // 可以执行,因为是在块级作用域内
    const x = "sneaky";
    // 错误,常量不允许被赋值
    x = "foo";
    }
    // 可以执行,因为是使用let声明
    x = "bar";
    // 错误,在当前块级作用域内已经被声明了一次
    let x = "inner";
    }
    }
  8. 迭代器(Iterators) + For..Of循环

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    // 实现斐波那契数列的迭代器
    let fibonacci = {
    [Symbol.iterator]() {
    let pre = 0, cur = 1;
    return {
    next() {
    [pre, cur] = [cur, pre + cur];
    return { done: false, value: cur }
    }
    }
    }
    }

    for (var n of fibonacci) {
    // 循环将在n > 1000 时结束
    if (n > 1000)
    break;
    console.log(n);
    }

参考https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Iteration_protocols

可迭代协议:为了变成可迭代对象, 一个对象必须实现 @@iterator 方法, 意思是这个对象(或者它原型链prototype chain上的某个对象)必须有一个名字是 Symbol.iterator 的属性(返回一个对象的无参函数,被返回对象符合==迭代器协议==)
当一个对象需要被迭代的时候(比如开始用于一个for..of循环中),它的@@iterator方法被调用并且无参数,然后返回一个用于在迭代中获得值的迭代器。

迭代器协议:它实现了一个 next() 的方法并且返回{ done: false, value: cur }

done (boolean)
如果迭代器已经经过了被迭代序列时为 true。这时 value 可能描述了该迭代器的返回值。返回值在这里有更多解释。
如果迭代器可以产生序列中的下一个值,则为 false。这等效于连同 done 属性也不指定。
value - 迭代器返回的任何 JavaScript 值。done 为 true 时可省略

  1. Generator(和py的生成器类似)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    // 实现斐波那契数列
    var fibonacci = {
    [Symbol.iterator]: function*() {
    var pre = 0, cur = 1;
    for (;;) {
    var temp = pre;
    pre = cur;
    cur += temp;
    yield cur;
    }
    }
    }

    for (var n of fibonacci) {
    // truncate the sequence at 1000
    if (n > 1000)
    break;
    console.log(n);
    }
  2. 模块

    1
    2
    3
    4
    5
    // lib/math.js
    export function sum(x, y) {
    return x + y;
    }
    export var pi = 3.141593;
1
2
3
// app.js
import * as math from "lib/math";
alert("2π = " + math.sum(math.pi, math.pi));
1
2
3
// otherApp.js
import {sum, pi} from "lib/math";
alert("2π = " + sum(pi, pi));

以及一些额外的功能:export default和export *

1
2
3
4
5
6
// lib/mathplusplus.js
export * from "lib/math";
export var e = 2.71828182846;
export default function(x) {
return Math.exp(x);
}

1
2
3
// app.js
import exp, {pi, e} from "lib/mathplusplus";
alert("2π = " + exp(pi, e));
  1. 模块加载器(Module Loaders)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    // 动态加载 – ‘System’ 是默认的加载器
    System.import("lib/math").then(function(m) {
    alert("2π = " + m.sum(m.pi, m.pi));
    });

    // 创建执行沙箱 – new Loaders
    var loader = new Loader({
    global: fixup(window) // replace ‘console.log’
    });
    loader.eval("console.log(\"hello world!\");");

    // 直接操作模块的缓存
    System.get("jquery");
    System.set("jquery", Module({$: $})); // WARNING: not yet finalized
  2. Map + Set + WeakMap + WeakSet

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    // Sets
    var s = new Set();
    s.add("hello").add("goodbye").add("hello");
    s.size === 2; //true
    s.has("hello") === true; //true

    // Maps
    var m = new Map();
    m.set("hello", 42);
    m.set(s, 34);
    m.get(s) == 34; //true

    // Weak Maps
    var wm = new WeakMap();
    wm.set(s, { extra: 42 });
    wm.size === undefined

    // Weak Sets
    var ws = new WeakSet();
    ws.add({ data: 42 });
    // 由于传入的对象没有其他引用,故将不会被set保存。
    //这些作为属性键的对象如果没有别的变量在引用它们,则会被回收释放掉。
  3. Proxies(代理对象)

参考https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Proxy

1
2
3
4
5
6
7
8
9
10
// 代理普通对象
var target = {};
var handler = {
get: function (receiver, name) {
return `Hello, ${name}!`;
}
};

var p = new Proxy(target, handler);
p.world === "Hello, world!"; //true

target:用Proxy包装的目标对象(可以是任何类型的对象,包括原生数组,函数,甚至另一个代理)。

handler:一个对象,其属性是当执行一个操作时定义代理的行为的函数。

  1. Symbols
    Symbol对对象的状态进行访问控制。Symbol允许对象的属性不仅可以通过string(ES5)命名,还可以通过symbol命名。symbol是一种基本数据类型。可选的name参数用于调试——但并不是他本身的一部分。Symbol是唯一的,但不是私有的,因为他们使用诸如Object.getOwnPropertySymbols这样的方法来使用。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    (function() {

    // 模块内的symbol
    var key = Symbol("key");

    function MyClass(privateData) {
    this[key] = privateData;
    }

    MyClass.prototype = {
    doStuff: function() {
    ... this[key] ...
    }
    };

    // 被Babel部分支持,原生环境可以完全实现。
    typeof key === "symbol"
    })();

    var c = new MyClass("hello")
    c["key"] === undefined
  2. 可以创建内建对象的子类

    1
    2
    3
    4
    5
    6
    7
    8
    // 创建Array的子类
    class MyArray extends Array {
    constructor(...args) { super(...args); }
    }

    var arr = new MyArray();
    arr[1] = 12;
    arr.length == 2
  3. Math + Number + String + Object APIs

新增很多功能,如核心的Math库,数组转换和用于对象复制的Object.assign()。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Number.EPSILON
Number.isInteger(Infinity) // false
Number.isNaN("NaN") // false

Math.acosh(3) // 1.762747174039086
Math.hypot(3, 4) // 5
Math.imul(Math.pow(2, 32) - 1, Math.pow(2, 32) - 2) // 2

"abcde".includes("cd") // true
"abc".repeat(3) // "abcabcabc"

Array.from(document.querySelectorAll("*")) // 将类似数组的对象转换为真正的数组
Array.of(1, 2, 3) // 类似与new Array(),但是当仅有一个参数时,两者表现不同
[0, 0, 0].fill(7, 1) // [0,7,7]
[1,2,3].findIndex(x => x == 2) // 1
["a", "b", "c"].entries() // 迭代结果 [0, "a"], [1,"b"], [2,"c"]
["a", "b", "c"].keys() // 迭代结果 0, 1, 2
["a", "b", "c"].values() // 迭代结果 "a", "b", "c"

Object.assign(Point, { origin: new Point(0,0) })

  1. 二进制和八进制字面量

    1
    2
    0b111110111 === 503 // true
    0o767 === 503 // true
  2. Promises

Promises是一种异步编程的方式。Promises在将来可能会得到支持。目前很多的JavaScript库都使用了Promises。
参考https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Promise
http://www.ruanyifeng.com/blog/2012/12/asynchronous%EF%BC%BFjavascript.html

1
2
3
4
5
6
7
8
9
10
11
12
13
function timeout(duration = 0) {
return new Promise((resolve, reject) => {
setTimeout(resolve, duration);
})
}

var p = timeout(1000).then(() => {
return timeout(2000);
}).then(() => {
throw new Error("hmm");
}).catch(err => {
return Promise.all([timeout(100), timeout(200)]);
})

  1. Reflect API
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    var O = {a: 1};
    Object.defineProperty(O, 'b', {value: 2});
    O[Symbol('c')] = 3;

    Reflect.ownKeys(O); // ['a', 'b', Symbol(c)]

    function C(a, b){
    this.c = a + b;
    }
    var instance = Reflect.construct(C, [20, 22]);
    instance.c; // 42

总结:以上只是初步了解,相信在之后的js路上会经常遇到

对象字面量

发表于 2018-03-14 | 分类于 js学习笔记

参考(http://blog.csdn.net/qq_34267645/article/details/50993379)
对象字面量是一种可以方便地按指定的规格创建新对象的表述法。属性名可以是标识符或字符串。这些名字被当作字面量名而不是变量名来对待,所以对象的属性名在编译时才能知道。属性的值就是表达式。

对象字面量提供了一种非常方便的创建新对象的表示法。一个对象字面量就是包围在一对花括号中的零或多个”名/值“对。对象字面量可以出现在任何允许表达式出现的地方。

1
2
3
4
5
var  empty_object = {};
var stooge = {
"first-name" : "Jerome",
"last-name" : "Howard"
}

属性名可以是包括空字符串在内的所有字符串。在对象字面量中,如果属性名是一个合法的Javascript标识符且不是保留字,则并不强制要求你用引号括住。所以上面的代码中”first-name“必须用”“括起来,而first_name就不用(因为中间是下划线)。逗号用来分割多个“名/值”对。

属性的值可以从包括另一个对象字面量在内的任意字表达式获得。对象可以是嵌套的:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
var flight = {
airline : "Oceanic",
number : 815,
departure : {
TATA : "SYD",
time : "2004-09-22 14:55"
city : "Sydeny"
},
arrival : {
TATA : "LAX",
time : "2004-09-22 14:55",
city : "Los Angeles"
}
}

要检索对象里面包含的值,可以采用在[]后缀括住一个字符串表达式的方式。如果字符串表达式是一个字符串字面量,而且是一个合法的Javascript标识符且不是保留字,那么也可以用 . 表示法。

1
2
3
4
5
stooge ["first-name"]
//"Jerome"

flight.departure.TATA
//"SYD"

如果检索一个不存在的成员属性的值,将返回undefined。||运算符可以用来填充默认值:

1
var middle = stooge["middle-name"] || ["none"];  //若不存在middle-name属性,将返回none

尝试从undefined的成员属性中取值将会导致TypeError异常。这时可以通过&&运算符来避免错误。(原文中例子写得不是很清楚)

1
2
3
4
var flight = {}
flight.equipment //undefined
var test = flight.equipment.model // throw TypeError
var test = flight.equipment && flight.equipment.model //所以在使用flight.equipment.model 先进行非空判断

对象通过引用来传递。它们永远不会被复制:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
var stooge = {
"first-name" : "Jerome",
"last-name" : "Howard"
}
var x = stoogle
stooge['first-name'] = 'Greet'
x['first-name'] //'Greet'

//还有个例子很危险
var a = b = c = {}
a['test'] = 123
b.test //123 因为他们指向同一个空对象
var test = a.test
a.test = 2222
test //123 似乎只有对象之间是用引用来传递

开启标签和分类

发表于 2018-03-14 | 分类于 杂记

发现hexo的/tags和/categories是404
百度后发现(https://segmentfault.com/q/1010000009361385)
这两个页面还要单独生成

1
2
hexo new page tags
hexo new page categories

这完了还不够。。还得修改两个md文件如下

1
2
3
4
5
6
7
8
#tags/index.md
title: 标签
date: 日期
type: "tags"
#categories/index.md
title: 分类
date: 日期
type: "categories"

大功告成

你好Hexo

发表于 2018-03-13 | 分类于 杂记

阿里云服务器马上到期了,一年强奸我1K的费用想来不合算,找了几家其他的云服务器 域名还要重备案,就作罢了

今年是工作的第5个年头,想来也还没在组织贡献过代码,就来注册了一个,顺便把博客也转过来了。

旧博客上的文章存在db里懒得转过来了,就当是重新开始吧。
说说我是怎么布属hexo的吧

  1. 首先你要准备的是npm,这里我使用阿里的镜像,原因就不多说了🤣
  2. 在github创建一个pages项目,参考:https://pages.github.com/
  3. 使用npm安装hexo,这里我用的是mac环境
1
2
3
4
5
6
7
mkdir blog #这里我准备把hexo相关的组件都放在blog目录下
cd blog
npm install hexo -g
hexo init #初始化
npm install #安装所需要的组件
hexo g #首次体验Hexo
hexo s --debug #开启本地环境
  1. 关联github
1
2
3
4
5
6
git config --global user.name "Uname"
git config --global user.email "Uemail@host.com"
cd ~/.ssh
ssh-keygen -t rsa -C "Uemail@host.com" #生成密钥,id_rsa和id_rsa.pub
eval "$(ssh-agent -s)" #添加密钥到ssh-agent
ssh-add ~/.ssh/id_rsa #将生成的SSH key到ssh-agent

登录Github => settings,添加ssh,新建一个ssh key,将id_rsa.pub文件里的内容复制上去

1
ssh -T git@github.com #如果看到Hi后面是你的用户名,就说明成功了

配置Deployment,在hexo根目录中,找到_config.yml文件,修改repo值(在末尾)

1
2
3
deploy: 
type: git
repository: #这里填上原先在github上创建的git地址
  1. 新建一篇博客
1
hexo new post "hello,hexo"
  1. 安装布属扩展
1
npm install hexo-deployer-git --save
  1. 发布文章
1
hexo d -g

部署成功后访问你的地址:http://用户名.github.io。那么将看到生成的文章

到这里我觉得hexo自带的皮肤太丑了,我百度了一下hexo的皮肤发现知乎上有人分享(https://www.zhihu.com/question/24422335) 第一个next皮肤就不错😘
装完之后我发现几个问题

  1. 皮肤怎么是英文的
  2. favicon太丑了

怎么处理?还是百度😝😝😝😝😝
发现根目录下的_config.yml 有几处东西可以改改

1
2
3
4
5
6
7
# Site
title: wuztooo
subtitle: 点点点
description: 这是一个简单的小bloger
author: wuzt
language: zh-Hans
timezone: Asia/Shanghai

favicon我在themes/next/_config.yml下

1
2
3
4
5
favicon:
small: /images/favicon.ico
medium: /images/favicon.ico
apple_touch_icon: /images/favicon.ico
safari_pinned_tab: /images/favicon.ico

最后把我们自己的域名绑定到github

  1. 在域名后台添加CNAME解析
  2. 在/hexo/source/下新建一个CNAME文件
1
blog.wuzt.net

希望我能善始善终,每周写一篇之类的(先立下flag)

Hello World

发表于 2018-03-13

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment

wuzt

这是一个简单的小bloger

9 日志
3 分类
5 标签
© 2018 wuzt
由 Hexo 强力驱动
|
主题 — NexT.Muse v5.1.4