0%

1
7za x file.7z

安装

1
sudo yum install epel-release
1
sudo yum install p7zip

php get DOM

remove script tags

https://stackoverflow.com/questions/7130867/remove-script-tag-from-html-content/7131085

美剧网 《爱,死亡和机器人 第一季》

https://91mjw.com/video/1295.htm

压缩 css

uglifycss –convert-urls test lib/font-awesome-4.7.0/css/font-awesome.min.css lib/ionicons-2.0.0/css/ionicons.min.css lib/mwa/mwa.css lib/animation.min.css \

css/ok.css

插件兼容AMD, CMD ,CommonJS和 原生 JS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
;(function(){
function MyModule() {
// ...
}
var moduleName = MyModule;
if (typeof module !== 'undefined' && typeof exports === 'object' && define.cmd) {
module.exports = moduleName;
} else if (typeof define === 'function' && define.amd) {
define(function() { return moduleName; });
} else {
this.moduleName = moduleName;
}
}).call(function() {
return this || (typeof window !== 'undefined' ? window : global);
});
1
2
3
4
5
6
7
8
9
if (typeof module != 'undefined' && module.exports) {  //CMD
module.exports = SB;
} else if (typeof define == 'function' && define.amd) { //AMD
define(function() {
return SB;
});
} else { //no AMD or CMD
window.SB= SB;
}
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
var root = (typeof self == 'object' && self.self == self && self) ||
(typeof global == 'object' && global.global == global && global)||
this || {};

//在浏览器中,除了window属性,我们也可以通过self属性直接访问到Window对象,同时self还可以支持Web Worker
//Node环境中全局变量为 global
//node vm(沙盒模型) 中不存在window,也不存在global变量,但我们却可以通过this访问到全局变量
//在微信小程序中,window和global都是undefined,加上强制使用严格模式,this为undefined,就多了{}

var _ = function(obj){

if(obj instanceof _){
return obj;
}

if(!(this instanceof _)){ // 此处为了实现面向对象风格调用,可以暂时不管
return new _(obj);
}
this._wrapped = obj;
};

//exports.nodeType 防止<div id="exports"></div>产生的window.exports全局变量。

if(typeof exports != 'undefined' && !exports.nodeType){
if((typeof module != 'undefined' && !module.nodeType && module.exports)){

//在nodeJs中,exports是module.exports 的一个引用,当你使用了module.exports = function(){}
//实际上覆盖了module.exports,但是exports并未发生改变,为了避免后面在修改exports而导致不能正确输出
//写成这样,将两者保持统一。

exports = module.exports = _;
}
exports._ = _;
}else{
//?不太懂部分,将_挂到全局属性_上
root._ = _;
}

via

array remove duplicated item

const arr = [22,33,22,44,22];

// 1
[…new Set(arr)];

// 2
arr.filter((k,j)=>arr.indexOf(k)=== j)

// 3
arr.reduce((tt,k)=>{
console.log(tt,k)
return tt.includes(k) ? tt: […tt,k]
},[])

via
https://medium.com/dailyjs/how-to-remove-array-duplicates-in-es6-5daa8789641c

uglifyjs 默认只能 es5

https://www.npmjs.com/package/uglify-es

需要安装

npm install uglify-es -g

uglifyjs gsmap.js -m -o gsmap.min.js

uglifyjs js/file1.js js/file2.js
-o foo.min.js -c -m
–source-map “root=’http://foo.com/src',url='foo.min.js.map'"

uglifyjs ../lib/axios.min.js gsmap.js
-c drop_console -m -o gsmap.min.js

压缩项目

uglifyjs main.js app.js pos.js
-c drop_console -m -o gs.min.js

let a = Array(14).fill().map((k,j)=>j+1);
a.reduce((tt,k)=>{
return tt+’curl https://i.jd.com/defaultImgs/'+k+'.jpg -o ‘+k+’.jpg\n’;
},’’)

n ES6 using Array from() and keys() methods.

Array.from(Array(10).keys())
//=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Shorter version using spread operator.

[…Array(10).keys()]
//=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

babel

https://blog.zfanw.com/babel-js/#babelcli

1231231314

abc

https://blog.zfanw.com/babel-js/#babel-套餐

const alertMe = (msg) => {
window.alert(msg)
}
class Robot {
constructor (msg) {
this.message = msg
}
say () {
alertMe(this.message)
}
}
const marvin = new Robot(‘hello babel’)

firebase-hosting-static-site

https://blog.zfanw.com/firebase-hosting-static-site/

iOS Safari 点击事件失效

这是移动端 Safari 至今仍存在的一个 bug 特性。

有几个解决办法:

最简单的,给 CSS 加上 cursor: pointer;
停止委托,直接给 #btn 绑定事件处理器;
给 div 元素加上 onclick=’void(0);’;
将 div 换成其它不受该 bug 特性影响的元素,比如 a、button 等。

有效 json

A comment first. The question was about not using try/catch.
If you do not mind to use it, read the answer below. Here we just check a JSON string using a regexp, and it will work in most cases, not all cases.

Have a look around the line 450 in https://github.com/douglascrockford/JSON-js/blob/master/json2.js

There is a regexp that check for a valid JSON, something like:

1
2
3
4
5
6
7
8
9
10
11
if (/^[\],:{}\s]*$/.test(text.replace(/\\["\\\/bfnrtu]/g, '@').
replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {

//the json is ok

}else{

//the json is not ok

}

pan.baidu.com

davidguoshuang@gmail.com

mqtt

http://test.mosquitto.org/ws.html
http://louiszhai.github.io/2017/04/28/array/#keys-ES6
https://juejin.im/post/5d66b019f265da03a715e5d7
https://dev.to/saigowthamr/how-to-loop-through-object-in-javascript-es6-3d26

需要一个 autoindex 的 www。先建立一个 guoshuang_labs.conf

1
2
3
4
5
6
7
8
9
10
server {
listen 80;
server_name labs.guoshuang.com;
charset utf-8;
index index.html index.htm index.php;
root /usr/share/nginx/html/guoshuang_labs/;
location / {
autoindex on;
}
}

然后 copy 到 docker nginx 容器

1
docker cp guoshuang_labs.conf nginx:/etc/nginx/conf.d/guoshuang_labs.conf 

重启

1
docker retart nginx

更多参考


1
2
3
4
5
6
# 查找镜像
docker search nginx
# 拉取镜像
docker pull nginx
# 查看本地镜像
docker images
1
docker cp nginx:/etc/nginx/conf.d/guoshuang_demo.conf guoshuang_demo.conf

进入容器

1
docker exec -it nginx bash

autoindex

1
2
3
4
5
6
location /somedirectory/ {
autoindex on;
autoindex_exact_size off;
autoindex_format html;
autoindex_localtime on;
}

autoindex_exact_size; – This directive specifies whether Nginx should display the exact file sizes of the output in the directory index or simply round to the nearest KB, MB, or GB. This directive has 2 options: on | off.

autoindex_format; – This directive specifies what format the Nginx index listing should be outputted to. This directive has 4 options: html | xml | json | jsonp.

autoindex_localtime; – This directive specifies whether the times for the directory listing should be outputted to local time or UTC. This directive has 2 options: on | off.

with php

docker run –name w3 -d webdevops/php-nginx

sudo apachectl stop

sudo apachectl start

docker stop w3
docker rm w3

docker run –name w3 -p 8088:80 -d
-v ~/ddd/www:/app:ro
-v ~/ddd/guo.conf:/opt/docker/etc/nginx/conf.d:ro
webdevops/php-nginx

my cloud

docker pull webdevops/php-nginx

home/guoshuang/myphp/

docker stop w3
docker rm w3

docker run –name w3 -p 8088:80 -d
-v /home/guoshuang/myphp/html:/app
-v /home/guoshuang/myphp/conf:/opt/docker/etc/nginx/conf.d:ro
webdevops/php-nginx

docker restart w3

crontab

https://blog.csdn.net/yelllowcong/article/details/78483579

shell show date

date +’%Y-%m-%d %T’

https://www.cyberciti.biz/faq/unix-linux-getting-current-date-in-bash-ksh-shell-script/

每分钟

          • date +’%Y-%m-%d %T’ > 1.txt

% 要转义

          • 2.sh

看邮件

cat /var/spool/mail/root

每小时

*/60 * * * * /root/2.sh

注意!!网上大笨蛋

  • */1 * * * #错误的每隔一小时执行一次,事实上每分钟执行一次

cd /home/guoshuang/myphp/html/corona/data

curl http://127.0.0.1:8088/qs/get-data-world.php

cd /home/guoshuang/myphp/html/qs/data

cd /home/guoshuang/myphp/conf

docker exec -it w3 /bin/bash

http {
server {
index index.html;
}
}

docker restart w3
docker ps
curl 127.0.0.1:8088

君子矜而不争,群而不党。

【译文】孔子说:“君子庄重自尊不与人争,合群却不因私结党。”

群居终日,言不及义,好行小慧,难矣哉!

【译文】孔子说:“整天聚在一起,不谈正经的事情,喜欢玩弄小聪明,难有所成!”

【解读】这类人没有人生目标,好耍小聪明。这是我想到了青年时的毛泽东,毛泽东有“三不谈”,不谈金钱、不谈女人、不谈家庭琐事,正好与这类人相反,所以毛泽东成了毛泽东。蔡元培德国留学归来谨守“三不主义”:一不做官,二不纳妾,三不打麻将,因此蔡元培成了蔡元培。孔子不语怪力乱神,我想也与孔子的这样认识相关。

在陈绝粮,从者病,莫能兴。子路愠见曰:“君子亦有穷乎?”子曰:“君子固穷,小人穷斯滥矣。

【译文】孔子在陈国的时候断绝了粮食,跟随的人都病了,没有人能爬起来。子路一腔怨气地对孔子说:“君子也有穷困的时候吗?”孔子说:“君子在穷困的时候仍然会坚持。小人穷困的时候,就会胡作非为。”

君子疾没世而名不称焉。

【译文】孔子说:“君子担心自己到死也没名。”

众恶之,必察焉;众好之,必察焉。

【译文】孔子说:“所有的人都讨厌他,一定要考察为什么;所有的人都喜欢他,也一定要了解一下为什么。”

志士仁人,无求生以害仁,有杀身以成仁。

【译文】孔子说:“有理想抱负的、有仁德的人,没有人为了求生而伤害仁德的,只会献出生命来成就仁德。”

躬自厚而薄责于人,则远怨矣。

【译文】孔子说:“严格要求自己少责怪别人,就会远离怨恨。”

君子病无能焉,不病人之不己知也。

【译文】孔子说:“君子担忧自己没本事,不担忧别人不了解自己。”

人能弘道,非道弘人。

【译文】孔子说:“人能够弘扬道义,不是道义弘扬人。”

吾尝终日不食,终夜不寝,以思,无益,不如学也。

【译文】孔子说:“我曾经整天不吃饭,整宿不睡觉,为了思考,但没有什么收益,还不如去读书学习。”

君子谋道不谋食。耕者,馁在其中矣;学也,禄在其中矣。君子忧道不忧贫。

【译文】孔子说:“君子谋求道义,不谋求衣食。为谋食耕田的人,也难免会饿肚子;为谋求道义去学习的人,就可以做官拿到俸禄。所以君子只担心道义而不担心贫穷。”

知及之,仁不能守之,虽得之,必失之。知及之,仁能守之,不庄以莅之,则民不敬。知及之,仁能守之,庄以莅之,动之不以礼,未善也。

【译文】孔子说:“凭头脑得到,不用仁心守住它,虽然得到了,最终也一定会失去它。凭头脑得到,又能用仁心守住它,但不用庄重严肃的态度面对它,老百姓就不会敬重你。凭头脑得到,用仁心守住,以庄敬的态度面对,行动如果不依据礼制,就仍没有达到最好。”

君子不可小知,而可大受也。小人不可大受,而可小知也。

【译文】孔子说:“君子不可以用小聪明小事情考验他,却可以让他承受大使命。小人不可以让他承受重大任务,去可以让他做些小聪明的事情。”

子张问行。子曰:“言忠信,行笃敬,虽蛮貊之邦行矣。言不忠信,行不笃敬,虽州里行乎哉?立,则见其参于前也;在舆,则见其倚于衡也。夫然后行。”子张书诸绅。

【译文】子张问自己的行为怎样才能正确。孔子说:“说话忠诚守信,行动恭敬踏实,即使是到了蒙昧落后的地方也能行得通。说话不诚实守信,行动不真诚敬慎,就是在本乡本土又怎么能行得通呢?站着,就好像看见 ‘忠信笃敬’几个字在眼前;坐车,就好像看见这几个字可在车前的横木上。这样就到哪都行得通。”子张把这句话写在自己的衣带上。

躬自厚而薄责于人,则远怨矣。

【译文】孔子说:“严格要求自己少责怪别人,就会远离怨恨。”

君子义以为质,礼以行之,孙以出之,信以成之。君子哉!

【译文】孔子说:“君子以道义为本质,通过礼去实行它,用谦逊的语言表达它,用诚信去成就它。这才是君子啊!”

via 《卫灵公第十五》原文、注释、翻译与解读

1
['1', '7', '11'].map(parseInt)

返回的是

[ 1, NaN, 3 ]

原因很简单,map(a,b,c): 其实三个参数

[‘1’, ‘7’, ‘11’].map((a,b,c) => console.log(a,b,c));

1 0 Array(3) [ “1”, “7”, “11” ]
7 1 Array(3) [ “1”, “7”, “11” ]
11 2 Array(3) [ “1”, “7”, “11” ]

a 自己
b 序号
c 整个数组

循环的其实是:

parseInt(1,0,array) // 1
parseInt(7,1,array) // NaN
parseInt(11,2,array) // 3

思路:小于的 segment 合并 画 1 个?(填补 segments 之间的 缝隙)

导致新问题: 何时重画 为 小段?

styleFunc 里面不能修改 feature 本身数据!需要 map on change:resolutuon 和 map on moveend (如果 point 视野外 被删除的话)

必须 styleFunction 里面 否则 zoom drag 永远不显示啦!!!!

styleFunction 里面和外面(不进入geojson) return 的区别:全局变量有。但是不画,也点不到。

  • multiline 多根 -> 1根 缺点是: 不能识别 segment

  • 同理 multi point

  • 短于 10 像素的 line 不画

  • point 数量 > 2000 不画

  • point 位置重叠 不画

短于 10 像素的 line 不画

1
2
3
let res = map.getView().getResolution();
let dt = get_distance_by_co2([sposx, sposy],[eposx,eposy],1) / res;
if(dt<20){return;}

getClosestFeatureToCoordinate

注意:这个性能也很差!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// 伟业开  pos_x: 108.939079   pos_y: 34.254787

var cor = [108.939079,34.254787];
var pos = ol.proj.transform(cor,'EPSG:4326', 'EPSG:3857');
var rs = layer_bdz.getSource().getClosestFeatureToCoordinate(pos,function(d){
// console.log(d);
let prop = d.getProperties();
return prop['pos_x']!= cor[0] && prop['pos_y']!= cor[1];
})
console.log(rs);

// 最近的 多少 米
var pp2 = rs.getProperties();
var pos2 = ol.proj.transform([pp2.pos_x,pp2.pos_y],'EPSG:4326', 'EPSG:3857');
var dd = get_distance_by_co2(pos,pos2,0); // 1 是经纬度;0 是 google 坐标
console.log(dd);

// 最近的 多少 像素
var dxy = dd/map.getView().getResolution();
console.log('最近的 feature 距离 像素:',dxy);
if(dxy < 20){return;}

map.hasFeatureAtPixel(pixel)

1
2
3
4
5
6
7
8
var pos = ol.proj.transform([108,34],'EPSG:4326', 'EPSG:3857'); //
var pixel = map.getPixelFromCoordinate(pos); // lnglat -> xy
console.log(pixel);
var is_repeated = map.hasFeatureAtPixel(pixel,{
hitTolerance:20
}); // xy has feature
console.log(is_repeated);
if(is_repeated){return;}

注意:但是 map.hasFeatureAtPixel 性能很差!!!!!!执行时间很长!

stylefunc_node_default

styleFunction_segment

querySelectorAll 结果 是 nodelist 不是数组!!!!

var a = Array.from(document.querySelectorAll(‘label’));

var a = […document.querySelectorAll(‘label’)];

var a = Array.prototype.map.call(document.querySelectorAll(‘label’),k=>k);

var a = Array.prototype.slice.call(document.querySelectorAll(‘label’))

var a = Array.prototype.filter.call(document.querySelectorAll(‘label’),k=>k);

var a = [];for(i of document.querySelectorAll(‘label’)){a.push(i);}

var a = [], rs = document.querySelectorAll(‘label’);for(i=0;i< rs.length;i++){a.push(rs[i]);}

var a = [], rs = document.querySelectorAll(‘label’);rs.forEach(k=>k);

var a = [];document.querySelectorAll(‘label’).forEach(k=>a.push(k));

var a = [], rs = document.querySelectorAll(‘label’);for(k of rs.entries()){a.push(k);}

var a = [], rs = document.querySelectorAll(‘label’);for(k of rs.entries()){a.push(k[1]);}

var a = [], rs = document.querySelectorAll(‘label’);for(k of rs.values()){a.push(k);}

var a =[];
var rs = document.querySelectorAll(‘label’);

some 只要1个符合;every 全部符合 返回 true

var a = [];
Array.prototype.some.call(document.querySelectorAll(‘label’),k=>{
a.push(k);
});

var a = [];
Array.prototype.every.call(document.querySelectorAll(‘label’),k=>{
return a.push(k);
});

一直找不到。。。

var a = [];
Array.prototype.find.call(document.querySelectorAll(‘label’),k=>{
return !a.push(k);
});

https://medium.com/poka-techblog/simplify-your-javascript-use-map-reduce-and-filter-bd02c593cc2d

https://medium.com/mr-frontend-community/5-ways-to-loop-over-dom-elements-from-queryselectorall-in-javascript-55bd66ca4128

https://medium.com/@chuckdries/traversing-the-dom-with-filter-map-and-arrow-functions-1417d326d2bc

Array keys

for (var elem of Array(3).keys()){
console.log(elem);
}

// If you really want to use forEach…
[…Array(3).keys()].forEach(k => console.log(‘spread syntax -> ‘, k));

// Or using Array.from
Array.from(Array(3).keys()).forEach(k => console.log(‘Array.from ->’, k));