liuliaixue

当白云悠然褪去我已等不及登上高山仰望西方的天空但最美的不是夕阳是夜色如水月色流离


  • 首页

  • 归档

  • 标签

git merge

发表于 2017-09-11

normal merge

1
2
3
4
5
git checkout -b f1
git commit -m 'some commits'
git git checkout master
// git merge f1
git merge --no-ff //recommend

git merge --squash

发表于 2017-09-11

1.直接合并(straight merge):

  把两条分支上的历史轨迹合并,交汇到一起。

  比如要把dev分支上的所有东东合并到master分支:

  首先先到master分支:git checkout master

  然后把dev给合并过来:git merge dev

  注意没参数的情况下merge是fast-forward的,即Git将master分支的指针直接移到dev的最前方。

  换句话说,如果顺着一个分支走下去可以到达另一个分支的话,那么Git在合并两者时,只会简单移动指针,所以这种合并成为快进式(Fast-forward)。


  2.压合合并(squashed commits):

  将一条分支上的若干个提交条目压合成一个提交条目,提交到另一条分支的末梢。

  把dev分支上的所有提交压合成主分支上的一个提交,即压合提交:

  git checkout master

  git merge –squash dev

  此时,dev上的所有提交已经合并到当前工作区并暂存,但还没有作为一个提交,可以像其他提交一样,把这个改动提交到版本库中:

  git commit –m “something from dev”

即,使用–squash参数,这样提交的commit只有一个parent,即原来的分支,

图形看起来,比较好看。

不加的话,有两个parent,还能看见合并过来那个分支的图形,看着乱~~

js继承

发表于 2017-09-11
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
function test(str) {
alert(this.name + " " + str);
}
var object = {name:"zhangsan"}
test.call(object, "langsin");
//此时,第一个参数值object传递给了test类(即方法)中出现的this,而第二个参数"langsin"则赋值给了test类(即方法)的str

function Parent(username) {
this.username = username;
this.hello = function() {
alert(this.username);
}
}

function Child(username, password) {
Parent.call(this, username);

this.password = password;
this.world = function() {
alert(this.password);
}
}
var parent = new Parent("zhangsan");
var child = new Child("lisi", "123456");
parent.hello();
child.hello();
child.world();

git config

发表于 2017-09-11

config list

1
git config -l

init user and email

1
2
$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com

js继承

发表于 2017-09-11

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
27
28
29
function Parent(username) {
this.name = username;
this.hello = function () {
alert(this.username);
}

}

function Child(username, password) {
//通过以下3行实现将Parent的属性和方法追加到Child中,从而实现继承
//第一步:this.method是作为一个临时的属性,并且指向Parent所指向的对象,
//第二步:执行this.method方法,即执行Parent所指向的对象函数
//第三步:销毁this.method属性,即此时Child就已经拥有了Parent的所有属性和方法
this.method = Parent;
this.method(username);//最关键的一行
delete this.method;

this.password = password;
this.world = function () {
alert(this.password);
}
}
var parent = new Parent("zhangsan");
var child = new Child("lisi", "123456");
parent.hello();

//Child中没有声明hello()
child.hello();
child.world();

2 继承第二种方式:call()方法方式

call方法是Function类中的方法
call方法的第一个参数的值赋值给类(即方法)中出现的this
call方法的第二个参数开始依次赋值给类(即方法)所接受的参数

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
function test(str) {
alert(this.name + " " + str);
}
var object = new Object();
object.name = "zhangsan";
test.call(object, "langsin");

//此时,第一个参数值object传递给了test类(即方法)中出现的this,而第二个参数"langsin"则赋值给了test类(即方法)的str

function Parent(username) {
this.username = username;
this.hello = function() {
alert(this.username);
}
}

function Child(username, password) {
Parent.call(this, username);

this.password = password;
this.world = function() {
alert(this.password);
}
}
var parent = new Parent("zhangsan");
var child = new Child("lisi", "123456");
parent.hello();
child.hello();
child.world();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
var animals = [
{ species: 'Lion', name: 'King' },
{ species: 'Whale', name: 'Fail' }
];

for (var i = 0; i < animals.length; i++) {
(function(i) {
this.print = function() {
console.log('#' + i + ' ' + this.species
+ ': ' + this.name);
}
this.print();
}).call(animals[i], i);
}

继承的第三种方式:apply()方法方式

apply方法接受2个参数,
A、第一个参数与call方法的第一个参数一样,即赋值给类(即方法)中出现的this
B、第二个参数为数组类型,这个数组中的每个元素依次赋值给类(即方法)所接受的参数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function Parent(username) {
this.username += username;
this.hello = function() {
alert(this.username);
}
}

function Child(username, password) {
Parent.apply(this, new Array(username,username,username));

this.password = password;
this.world = function() {
alert(this.password);
}
}
var parent = new Parent("zhangsan");
var child = new Child("lisi", "123456");
parent.hello();
child.hello();
child.world();

与call()方法类似,第二个参数为数组,可以直接使用arguments

继承的第四种方式:原型链方式,即子类通过prototype将所有在父类中通过prototype追加的属性和方法都追加到Child,从而实现了继承

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function Person() {}
Person.prototype.hello = "hello";
Person.prototype.sayHello = function() {
alert(this.hello);
}

function Child() {}
Child.prototype = new Person(); //这行的作用是:将Parent中将所有通过prototype追加的属性和方法都追加到Child,从而实现了继承
Child.prototype.world = "world";
Child.prototype.sayWorld = function() {
alert(this.world);
}

var c = new Child();
c.sayHello();
c.sayWorld();

继承的第五种方式: 混合方式混合了call方式、 原型链方式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
function Parent(hello) {
this.hello = hello;
}
Parent.prototype.sayHello = function() {
alert(this.hello);
}

function Child(hello, world) {
Parent.call(this, hello); //将父类的属性继承过来
this.world = world; //新增一些属性
}

Child.prototype = new Parent(); //将父类的方法继承过来

Child.prototype.sayWorld = function() { //新增一些方法
alert(this.world);
}

var c = new Child("zhangsan", "lisi");
c.sayHello();
c.sayWorld();

git commit

发表于 2017-09-11

#
git commit

1
2
3
4
5
6
7
8
9
git commit
// 显示提交信息界面,需要添加commit message

git commit -m 'commit message'

git commit -a -m 'commit message'

git commit --amend
// 修改 commit message

ref:
https://git-scm.com/docs/git-commit

node debugger

发表于 2017-09-11

#

ref : https://nodejs.org/api/debugger.html

1
2
3
4
5
6
7
// start script
node inspect server.js
// will break at the first 3 lines, print c or cont
cont
// will pause at 'debugger', print repl
repl
// you can print the variables in repl line
1
2
3
4
5
cont, c - Continue execution
next, n - Step next
step, s - Step in
out, o - Step out
pause - Pause running code (like pause button in Developer Tools)

正则表达式

发表于 2017-09-11

#

基本匹配模式

普通匹配方式

^once 以once开头的字符串
bucket$
^bucket$
once

包含转义字符的匹配方式

^\t 制表符
\n
\r
\
.

字符簇 只能表示一个字符

[a-z] //匹配所有的小写字母
[A-Z] //匹配所有的大写字母
[a-zA-Z] //匹配所有的字母
[0-9] //匹配所有的数字
[0-9.-] //匹配所有的数字,句号和减号
[ \f\r\t\n] //匹配所有的白字符

^[a-z][0-9]$ 匹配两个字符,字母+数字
^[^0-9][0-9]$ 匹配两个字符,非数字+数字

[^a-z] //除了小写字母以外的所有字符
[^\\/\^] //除了()(/)(^)之外的所有字符
[^\”\’] //除了双引号(“)和单引号(‘)之外的所有字符

重复出现

^[a-zA-Z0-9_]{1,}$ //所有包含一个以上的字母、数字或下划线的字符串
^[1-9]{1,}$ //所有的正数
^-{0,1}[0-9]{1,}$ //所有的整数
^[-]?[0-9]+.?[0-9]+$ //所有的浮点数

常用示例

手机号

^[1][358][0-9]{9}$

邮箱

/^([a-zA-Z0-9_.-])+\@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/

车牌号

var re=/^[\u4e00-\u9fa5]{1}[A-Z]{1}[A-Z_0-9]{5}$/;

匹配特定数字:

  ^[1-9]d$    //匹配正整数
  ^-[1-9]d
$   //匹配负整数
  ^-?[1-9]d$   //匹配整数
  ^[1-9]d
|0$  //匹配非负整数(正整数 + 0)
  ^-[1-9]d|0$   //匹配非正整数(负整数 + 0)
  ^[1-9]d
.d|0.d[1-9]d$   //匹配正浮点数
  ^-([1-9]d
.d|0.d[1-9]d)$  //匹配负浮点数
  ^-?([1-9]d
.d|0.d[1-9]d|0?.0+|0)$  //匹配浮点数
  ^[1-9]d
.d|0.d[1-9]d|0?.0+|0$   //匹配非负浮点数(正浮点数 + 0)
  ^(-([1-9]d
.d|0.d[1-9]d*))|0?.0+|0$  //匹配非正浮点数(负浮点数 + 0)
  评注:处理大量数据时有用,具体应用时注意修正

javascript apply and call

发表于 2017-09-11
1
2
3
4
5
6
7
8
9
10
11
12
13
14
var add = function(a,b){
this.alias = "ADD";
return a + b;
}


var sub = function(a,b){
this.alias = "SUB";
return a-b
}

add(5,3) ; //8
add.call(sub,5,3);//8
add.apply(sub,[5,3]);//8

都是8好像sub没什么用啊,主要是因为 add 和 sub 这两个方法没有用到 this 这个对象

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
var add = function(a,b){

return a + this.alias + b;
}

add.alias = "+";


var sub = function(a,b){

return a + this.alias+ b;
}

sub.alias = "-";

add(5,3) ;//NaN
add.call(sub,5,3); //'5-3'
add.apply(sub,[5,3]); //'5-3'

虽然运行了add的方法 ,但是用到了sub对象的参数(this.alias)

set environment variables in powershell

发表于 2017-09-11

set environment variables

1
$env:NODE_ENV='cnTest';

a powershell script file(.ps1)

1
2
3
"cnTest server";
$env:NODE_ENV='cnTest';
node server.js;
1…456
Alan

Alan

55 日志
92 标签
© 2019 Alan
由 Hexo 强力驱动
主题 - NexT.Muse