2017年8月

javascript常见函数

js混淆数据
function shuffle(arr){
return arr.sort(function(){ return 0.5 - Math.random() });
}

js数字数组排序
function sort(arr){
return arr.sort(function(a, b){return a - b})
}

json自动加上引号
var s = "{name:sb,age:3}";
console.log(s.replace(/\b/g, """));
输出为{"name":"sb","age":"3"}
优点:正则非常简单,适合多层级结构例如"{name:sb,age:3,info:{count:5}}"

js获取url参数
function getUrlParam(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
var r = window.location.search.substr(1).match(reg); //匹配目标参数
if (r != null) return unescape(r[2]); return null; //返回参数值
}
浏览器不支持禁止缩放,我在UC和QQ浏览器都是如此
在onload加入如下代码可以办到:
document.addEventListener('touchstart',function (event) {
if(event.touches.length>1){
event.preventDefault();
}
})
var lastTouchEnd=0;
document.addEventListener('touchend',function (event) {
var now=(new Date()).getTime();
if(now-lastTouchEnd<=300){
event.preventDefault();
}
lastTouchEnd=now;
},false)

图片压缩工具Kraken.io

ELK(ElasticSearch, Logstash, Kibana)搭建

ElasticSearch5.x最好在centos7搭建,会比较容易,我采用的是官方的rpm方式安装,过程非常简单
一、安装elasticsearch-5.x
下载public signing key:
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
添加repo
vim /etc/yum.repos.d/elasticsearch.repo

[elasticsearch-5.x]
name=Elasticsearch repository for 5.x packages
baseurl=https://artifacts.elastic.co/packages/5.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md

sudo yum install elasticsearch
添加开机启动
sudo chkconfig --add elasticsearch

启动
sudo service elasticsearch start
sudo service elasticsearch stop
开放内网IP访问
vim /etc/elasticsearch/elasticsearch.yml
network.host: 192.168.0.1
改成network.host: 0.0.0.0

二、安装kabana-5.x

添加repo
vim /etc/yum.repos.d/kibana.repo

[kibana-5.x]
name=Kibana repository for 5.x packages
baseurl=https://artifacts.elastic.co/packages/5.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md

添加开机启动
sudo chkconfig --add kibana

sudo service kibana start
sudo service kibana stop
修改配置
vim /etc/kibana/kibana.yml

三、安装logstash-5.x

添加repo
vim /etc/yum.repos.d/logstash.repo

[logstash-5.x]
name=Elastic repository for 5.x packages
baseurl=https://artifacts.elastic.co/packages/5.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
type=rpm-md

sudo yum install logstash
添加开机启动
sudo chkconfig --add logstash

sudo service logstash start
sudo service logstash stop
运行Ip访问
vim /etc/kibana/kibana.yml
#server.host: "localhost"
改成
server.host: 0.0.0.0