晨曦's Blog

This is a window to the soul

查看 npm 全局包

1
2
npm ll -g
npm la -g

上面这两个命令会显示包的简介和 git 地址和 readme 信息

npm ls -g 只会显示包名和版本

depth 参数代表依赖关系最大深度

如:npm ls -g --depth 0 表示只显示最顶层

前记

去年团建的时候公司一直在物色一个好的农家乐,由此关注上了不舍。鹿山。虽然最后也没有去,好心累

这次找了个周末双休带上孩子一起出发,去到大山卡卡里头呼吸新鲜的空气

在百度直接导航不舍。鹿山度假酒店即可差不多一个半小时左右

从重庆出发经过 G85->G93->江习高速在李市下道,再走上过 10 分钟左右就到了,有一个问题有差不多 500m 的距离小路非常窄,可能也就 2m 左右。记得要注意上面来车,真的很难错车

关于住宿最好是在网上订好,差不多只有 20 多间房吧,所有越早订好越好,基本周末都是满房。

就是因为我们订房晚了,所以只能订在周五…

目前订房好像是只接受官微订房,官微:蕙家农业价格方面有四个档次

以下价格为周末价格,平常价格可能会有波动请以官微为准

  1. 普通标间 280 元
  2. 精品标间 380 元
  3. 大床房 480 元
  4. 套房 680 元

普标房间内部,有热水,感觉空调不是嘿给力,如果冷可以找前台拿棉被

吃的还是比较多,价格也还能接收,有炒菜烧烤汤锅

价格方面:

  1. 晚上炒菜 8个菜 366元,分量非常足,就是冬天菜上桌易冷
  2. 早上房间含双早,自己点有饺子、汤圆、小面
  3. 中午汤锅整只乌鸡汤锅 299,现杀

对于我们 6 个大人 3 个小孩来说整体不算太贵,而且食材都还比较新鲜,尤其是鸡更是后山现抓、现杀

酒店门前有一大片竹林,夏天歇凉好去处,竹林下有草坪可露营等,晚上有篝火活动 (可能这个要看人多少)

由于冬天所有官方的活动只有丛林寻蛋59元一个小朋友,捡的蛋可以自己带走,如果是夏天会有各种采摘活动

也可以带小朋友看孔雀 、 梅花鹿 、 鸵鸟 、 鸡 、 香猪

总结

总体来说周末休闲,带小朋友出去耍还是不错的

写在前面

SOAR(SQL Optimizer And Rewriter) 是一个对 SQL 进行优化和改写的自动化工具。 由小米人工智能与云平台的数据库团队开发与维护。

本来之前使用过一段时间美团的 SQLAdvisor,但是依然有诸多问题无法解决,所以改用 SOAR 试试。

安装

下载二进制安装包

1
2
wget https://github.com/XiaoMi/soar/releases/download/0.10.0/soar.linux-amd64 -O soar
chmod a+x soar

验证安装

1
echo 'select * from film' | ./soar

配置

配置参考

写在前面

首先终端已经换为 zsh 了,至于怎样安装和更换默认终端,这里我就不赘述,可以参考下面网友做法

Homebrew install zsh & oh-my-zsh

安装

1
brew install nvm

设置

.bash_profile 加入以下这行,让你可以直接在 shell 使用 nvm 指令

1
source $(brew --prefix nvm)/nvm.sh

重新 source .bash_profile 来让设定生效

1
source .bash_profile

问题

以上操作看似没有任何问题,安装 node 后也能使用。但是,当你第二次重新打开终端时 node 将不能使用,提示错误 Run nvm use --delete-prefix v8.14.0 to unset it.

后面在 nvm 文档看到这段话 Homebrew installation is not supported. If you have issues with homebrew-installed nvm, please brew uninstall it, and install it using the instructions below, before filing an issue.,额… 看来没事还是要多看看文档啊,同时也有网友对此提有 Issues

正确安装

推荐使用官方script安装

1
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

最后在安装好 node 之后不要忘记设置 alias default

1
nvm alias default 8.14.0

对数组中的对象进行排序

函数:

1
2
3
4
5
function keysort (key, desc) {
return function (a, b) {
return desc ? (a[key] < b[key]) : (a[key] > b[key]);
};
}

示例:

1
2
const arr = [{"id":2,"name":"2"},{"id":1,"name":"1"}]
arr.sort(keysort('name', 'desc'));

判断是否是 Float 浮点

1
2
3
function isFloat (num) {
return num !== parseInt(num);
}

保留两位小数,同时不四舍五入

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// number
// num 保留位数
function toFixedNum (number, num) {
const type = typeof (number);
let number_arr = [];
if (type === 'number') {
const str = number.toString();
number_arr = str.split('.');
} else if (type === 'string') {
number_arr = number.split('.');
}
if (number_arr.length > 1) {
number = number_arr[0] + '.' + number_arr[1].substr(0, num);
}
return parseFloat(number);
}

给出开始时间和结束时间,算出中间所有的日期

1
2
3
4
5
6
7
8
9
10
11
12
13
// start : 2018-01-01
// end : 2018-01-03
// return : ["2018-01-01","2018-01-02","2018-01-03"]
function getDate (start, end) {
start = new Date(start).getTime();
end = new Date(end).getTime();
const date = [];
for (; start <= end; start += 86400000) {
const tmp = new Date(start);
date.push(tmp.getFullYear() + '-' + (tmp.getMonth() + 1) + '-' + tmp.getDate());
}
return date;
}

从数组中随机取出 N 个元素

1
2
3
4
5
6
7
8
9
10
11
12
13
14
function getRandomArrayElements (arr, count) {
const shuffled = arr.slice(0);
let i = arr.length;
const min = i - count;
let temp,
index;
while (i-- > min) {
index = Math.floor((i + 1) * Math.random());
temp = shuffled[index];
shuffled[index] = shuffled[i];
shuffled[i] = temp;
}
return shuffled.slice(min);
}

简介

CleanMyMac X 是一款强大的 Mac 系统垃圾清理工具,可以清除 Mac 系统多余的语言包、系统缓存、应用程序、PowerPc 软件运行库等,是硬盘瘦身的好工具

官网

国际版官网

中文官网

下载地址

因为 CleanMyMac 对不同的版本有不同的授权信息。

下面地址均为官网下载地址 https://dl.devmate.com 开头。

国际版 CleanMyMac 3

国际版 CleanMyMac X

中文版 CleanMyMac 3

中文版 CleanMyMac X

MacPaw 支持

可在支持中心查询许可证,或者当换机不成功时可以通过支持中心进行许可证重置。

支持中心

说在前面

压缩页面无非就是减小页面大小加快博客访问时间

实现

安装依赖

1
npm i gulp gulp-htmlclean gulp-htmlmin gulp-minify-css gulp-uglify -s

gulp 配置

在根目录下创建 gulpfile.js 文件

gulpfile.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
var gulp = require('gulp');
var minifycss = require('gulp-minify-css');
var uglify = require('gulp-uglify');
var htmlmin = require('gulp-htmlmin');
var htmlclean = require('gulp-htmlclean');
// 压缩 public 目录 css
gulp.task('minify-css', function () {
return gulp.src('./public/**/*.css')
.pipe(minifycss())
.pipe(gulp.dest('./public'));
});
// 压缩 public 目录 html
gulp.task('minify-html', function () {
return gulp.src('./public/**/*.html')
.pipe(htmlclean())
.pipe(htmlmin({
removeComments: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true,
}))
.pipe(gulp.dest('./public'))
});
// 压缩 public/js 目录 js
gulp.task('minify-js', function () {
return gulp.src('./public/**/*.js')
.pipe(uglify())
.pipe(gulp.dest('./public'));
});
// 执行 gulp 命令时执行的任务
gulp.task('default', [
'minify-html', 'minify-css', 'minify-js'
]);

一键部署

package.json 中加入如下 script

1
2
3
"scripts": {
"push": "hexo cl && hexo g && gulp && hexo d"
}

然后在部署的时候只需要运行

1
npm run push

前因

版本:NexT.Pisces v6.6.0
Error: 阅读次数:Counter not initialized! See more at console err msg.

解决

出现上述之错误,遂查看配置文件之说明

1
2
3
4
5
6
7
8
9
10
11
# Show number of visitors to each article.
# You can visit https://leancloud.cn get AppID and AppKey.
leancloud_visitors:
enable: true
app_id: <<your app id>>
app_key: <<your app key>>
# Dependencies: https://github.com/theme-next/hexo-leancloud-counter-security
# If you don't care about security in lc counter and just want to use it directly
# (without hexo-leancloud-counter-security plugin), set the `security` to `false`.
security: true
betterPerformance: false

如上述两个解决办法:

  1. 安装 hexo-leancloud-counter-security 并设置 leancloudapp_idapp_key

  2. security 设置为 security: false

因为懒所以选择了第二方案。

简介

Beanstalkd - 一个高性能、轻量级的分布式内存队列系统。

英文协议

中文协议

安装

这里我们用 Docker 来运行。

1
2
docker pull schickling/beanstalkd
docker run -d -p 11300:11300 schickling/beanstalkd

beanstalkd 管理 WEB 平台,主要用来看看以后的任务详情。

1
2
docker pull schickling/beanstalkd-console
docker run -d -p 2080:2080 --link beanstalkd:beanstalkd schickling/beanstalkd-console

通过 127.0.0.1:2080 访问

使用

官方客户端推荐列表 Client

下面我们主要介绍 Nodejs 客户端 bsw

客户端安装

1
npm i bsw --save

客户端示例

这里我们用阿里开源框架 eggjs 做测试。
app.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
'use strict';
const { Consumer } = require('bsw');
module.exports = app => {
app.beforeStart(async () => {
const consumer = new Consumer({
host: 'localhost',
port: '11300',
tube: 'node',
async handler(payload, job_info) {
console.log('processing job: ', payload);
console.log('processing job_info: ', job_info);
// 这里进行业务操作
return 'success';
},
});
consumer.on('error', e => {
console.log(e);
});
console.log('beanstalkd启动了');
await consumer.start();
});
};

home.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
'use strict';
const Controller = require('egg').Controller;
const { Producer } = require('bsw');
class HomeController extends Controller {
async index() {
const producer = new Producer({
host: 'localhost',
port: '11300',
tube: 'node',
});
await producer.start();
await producer.putJob({
payload: JSON.stringify({ throw: true, result: 'success' }),
priority: 0, // 优先级
delay: 30, // 延时单位(s)
ttr: 60, // 允许worker执行的最大秒数
});
producer.stop();
this.ctx.body = 'hi, egg';
}
}
module.exports = HomeController;

天若有情天亦老,月如无恨月长圆