西班木有蛀牙

努力的最大意义


  • 首页

  • 归档

jQuery代码-1

发表于 2018-05-24
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
var lei = window.lei = {};

lei.common = {
init: function () {
// 一些公共方法的初始化
this.getUserInfo();
},
getUserInfo: function () {
// Do something
}
}

lei.validateStr = {
tel : /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1})|(14[0-9]{1}))+\d{8})$/,
email : /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/,
password : /^.{6,16}$/,
ip : /^(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9]{1,2})(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9]{1,2})){3}$/,
qq : /^[1-9][0-9]{4,9}$/,
code : /^[0-9]{6}$/
}

lei.datas = {
id: 1
}

lei.prototype.index = {
init: function () {
// 初始化公共方法
lei.common.init();
// 初始化一些其他的操作
// Do something
}
}

// 使用:
new lei().index.init();

JavaScript面向切面编程

发表于 2018-05-24

aop.js

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
// 统计一下当前的所有的函数谁耗时最长
function test() {
alert(2);
return 'me';
}

// 之前
Function.prototype.before = function (fn) {
var __self = this;
// before 回调和 before 送到after 去
return function () {
// this指向了调用的函数
// console.log(this); //window
if (fn(__self, arguments) == false) {
return false;
};
return __self.apply(__self, arguments);
}
}

// 之后
Function.prototype.after = function (fn) {
// after 先执行本身this 再执行回调
var __self = this;
// after 回调 和 after test 送到before 去
return function () {
var result = __self.apply(__self, arguments)
if (result == false) {
return false;
}
fn.apply(__self, arguments);
return result;
}
}

// 挂载__self=>test 执行before 回调 ,执行selft after自己执行回调
test.before(function () {
alert(1);
}).after(function () {
alert(3);
})();

// test.after(function () {
// alert(3);
// }).before(function () {
// alert(1);
// })();

// test.after(function () {
// alert(3);
// }).before(function () {
// alert(1);
// return false;
// })();

index.html

1
2
3
4
5
6
7
8
9
10
11
12
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script src="aop.js"></script>
</body>
</html>

JavaScript-原型继承

发表于 2018-05-24

转载自

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
function Student (name) {
this.name = name;
this.hell = function () {
alert('Hello, ' + this.name + '~');
}
}

// PrimaryStudent构造函数:
function PrimaryStudent (props) {
Student.call(this, props);
this.grade = props.name || 1;
}

// 空函数
// 注意,函数F仅用于桥接,我们仅创建了一个new F()实例,
// 而且,没有改变原有的Student定义的原型链。
function F(){};

// 把F的原型指向Student.prototype;
F.prototype = Student.prototype;

// 把PrimaryStudent的原型指向一个新的F对象,F对象的原型正好指向Student.prototype:
PrimaryStudent.prototype = new F();

// 把PrimaryStudent原型的构造函数修复为PrimaryStudent:
PrimaryStudent.prototype.constructor = PrimaryStudent

// 继续在PrimaryStudent原型(就是new F()对象)上定义方法:
PrimaryStudent.prototype.getGrade = function () {
return this.grade;
};

var xiaoming = new PrimaryStudent({
name: '小明',
grade: 2
})

xiaoming.name; // '小明'
xiaoming.grade; // 2

// 验证原型:
xiaoming.__proto__ === PrimaryStudent.prototype; // true
xiaoming.__proto__.__proto__ === Student.prototype; // true

// 验证继承关系:
xiaoming instanceof PrimaryStudent; // true
xiaoming instanceof Student; // true



// 把继承这个动作用一个inherits()函数封装起来,还可以隐藏F的定义,并简化代码:

function inherits(Child, Parent) {
var F = function () {};
F.prototype = Parent.prototype;
Child.prototype = new F();
Child.prototype.constructor = Child;
}

function Student(props) {
this.name = props.name || 'Unnamed';
}

Student.prototype.hello = function () {
alert('Hello, ' + this.name + '!');
}

function PrimaryStudent(props) {
Student.call(this, props);
this.grade = props.grade || 1;
}

// 实现原型继承链:
inherits(PrimaryStudent, Student);

// 绑定其他方法到PrimaryStudent原型:
PrimaryStudent.prototype.getGrade = function () {
return this.grade;
};

服务器环境搭建——CentOS7-安装PHP

发表于 2018-05-24

安装PHP

由于Centos 7提供的PHP版本与需求不一致,需要配置第三方yum源
1
2
3
4
shell# wget https://mirror.webtatic.com/yum/el7/epel-release.rpm
shell# wget https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
shell# rpm -ivh epel-release.rpm
shell# rpm -ivh webtatic-release.rpm
安装PHP及一些需要的扩张
1
shell# yum install php56w php56w-mysqlnd php56w-gd php56w-mbstring

PHP配置

1
2
#/etc/php.ini
date.timezone = Asia/Shanghai

服务器环境搭建——CentOS7-安装NodeJS

发表于 2018-05-24

1.先进入目录

cd /usr/local/src

2.下载nodeJS压缩包,这里我们下载Linux Binaries (x86/x64) 六十四位的压缩包

wget https://nodejs.org/dist/v8.11.1/node-v8.11.1-linux-x64.tar.xz

3.解压

tar xvf node-v8.11.1-linux-x64.tar.xz

4.重命名文件夹

mv node-v8.11.1-linux-x64 node

5.进入解压之后的文件夹

cd node

6.在进入bin/文件夹

cd ./bin

7.这里输出看一下版本是否正确

./node -v // 输出 v8.11.1
./npm -v // 输出 5.6.0

8.将这里的node和npm设置为全局的

vim ~/.bash_profile

9.找到PATH=$PATH:$HOME/bin 在后面添加路径

PATH=$PATH:$HOME/bin:/usr/local/src/node/bin // 完整路径

10.重载

source ~/.bash_profile

文章来自各种百度。应该只有我自己才来看,不会有人喷我抄袭吧。。。

服务器环境搭建——CentOS7-安装mysql5-7

发表于 2018-05-24

CentOS7下安装mysql5.7

1、安装YUM Repo

由于CentOS 的yum源中没有mysql,需要到mysql的官网下载yum repo配置文件。

1
wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm

然后进行repo的安装:

1
rpm -ivh mysql57-community-release-el7-9.noarch.rpm

执行完成后会在 /etc/yum.repos.d/ 目录下生成两个repo文件 mysql-community.repo mysql-community-source.repo

2、安装MySQL

使用yum命令即可完成安装

1
yum install mysql-server

启动msyql:

1
systemctl start mysqld #启动MySQL`

配置MySQL

获取安装时的临时密码:

1
grep 'temporary password' /var/log/mysqld.log

登录:

1
mysql -u root -p

登录成功后修改密码:

1
set password=password("yourpassword");

设置安全选项:

1
mysql_secure_installation

其他设置:

1
2
3
4
5
systemctl stop mysqld #关闭MySQL
systemctl restart mysqld #重启MySQL
systemctl status mysqld #查看MySQL运行状态
systemctl enable mysqld #设置开机启动
systemctl disable mysqld #关闭开机启动

3、其他配置

开启远程控制

MySQL默认是没有开启远程控制的,必须添加远程访问的用户

1
2
3
4
5
grant all privileges on 数据库名.表名 to 创建的用户名(root)@"%" identified by "密码"; # 数据库名.表名 如果写成*.*代表授权所有的数据库 
flush privileges; #刷新刚才的内容

#如:
grant all privileges on *.* to root@"113.64.243.1" identified by "123456789";

@ 后面是访问mysql的客户端IP地址(或是 主机名) % 代表任意的客户端,如果填写 localhost 为本地访问(那此用户就不能远程访问该mysql数据库了)。

同时也可以为现有的用户设置是否具有远程访问权限。

配置默认编码为utf8:

1
2
3
4
5
vi /etc/my.cnf #添加

[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'

其他默认配置文件路径:

1
2
3
4
配置文件:/etc/my.cnf 
日志文件:/var/log//var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid

Putty登录阿里云CentOS时出现错误:Disconnected-No-supported-authentication-methods

发表于 2018-05-24

winSPC远程连接阿里云ECS实例出现错误:Disconnected:No supported authentication methods available

问题原因:ssh链接未允许远程密码认证导致

解决办法:

vim /etc/ssh/sshd_config
将
PasswordAuthentication no
更改为
PasswordAuthentication yes
按【ESC】输入保存:
:wq

再输入命令重启服务
service sshd restart

例外:

在云服务器 ECS Linux CentOS 7 下重启服务不再通过 service 操作,而是通过 systemctl 操作。

首先:
service sshd restart // 查看是否启动,如图1:则已启动
图1

没有启动:
systemctl start sshd.service

重启:
systemctl restart sshd.service

设置自启
systemctl enable sshd.service

Cmder-连接-ssh-root@服务器ip地址,报错

发表于 2018-05-24

使用Cmder 连接 ssh root@服务器ip地址
Permission denied (publickey).

webpack-作用域提升(Scope-Hoisting)

发表于 2018-05-24

网络爬虫排除标准——robots协议

发表于 2018-05-24

#Robots协议

“网络爬虫排除标准”(Robots Exclusion Protocol)也称为爬虫协议、机器人协议等,网站通过Robots协议告诉搜索引擎哪些页面可以抓取,哪些页面不能抓取。

##简介

####
robots.txt文件是一个文本文件,使用任何一个常见的文本编辑器,比如Windows系统自带的Notepad,就可以创建和编辑它 。

robots.txt是一个协议,而不是一个命令。robots.txt是搜索引擎中访问网站的时候要查看的第一个文件。

robots.txt文件告诉蜘蛛程序在服务器上什么文件是可以被查看的。

当一个搜索蜘蛛访问一个站点时,它会首先检查该站点根目录下是否存在robots.txt,如果存在,搜索机器人就会按照该文件中的内容来确定访问的范围;如果该文件不存在,所有的搜索蜘蛛将能够访问网站上所有没有被口令保护的页面。

百度官方建议,仅当您的网站包含不希望被搜索引擎收录的内容时,才需要使用robots.txt文件。如果您希望搜索引擎收录网站上所有内容,请勿建立robots.txt文件。

百度robots协议

1…345
Lei Tongda

Lei Tongda

努力的最大意义

43 日志
GitHub
© 2018 Lei Tongda
保持 - 对称
|
页尾 - 呵呵