简客-记忆

抽象的才是永恒的

0%

您的教诲,您的事迹,您的荣誉…不会消逝,一直在我们的心里

背景

安装某laravel项目

参考

http://old.ruesin.com/system/mac/mac-mongodb-345.html

安装mongodb服务

1
brew install mongodb
1
2
3
4
5
6
7
8
9
10
==> Installing mongodb
==> Downloading https://homebrew.bintray.com/bottles/mongodb-3.4.10.high_sierra.
######################################################################## 100.0%
==> Pouring mongodb-3.4.10.high_sierra.bottle.tar.gz
==> Caveats
To have launchd start mongodb now and restart at login:
brew services start mongodb
Or, if you don't want/need a background service you can just run:
mongod --config /usr/local/etc/mongod.conf
==> Summary

php 的 mongodb 扩展

search一下

1
brew search mongo
1
brew install php71-mongo

安装出错

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
NOTICE: PHP message: PHP Warning:  PHP Startup: mongodb: Unable to initialize module
Module compiled with build ID=API20160303,NTS
PHP compiled with build ID=API20160303,NTS,debug
These options need to match
in Unknown on line 0
<br />
<b>Warning</b>: PHP Startup: mongodb: Unable to initialize module
Module compiled with build ID=API20160303,NTS
PHP compiled with build ID=API20160303,NTS,debug
These options need to match
in <b>Unknown</b> on line <b>0</b><br />
Unknown(0) : Warning - PHP Startup: mongodb: Unable to initialize module
Module compiled with build ID=API20160303,NTS
PHP compiled with build ID=API20160303,NTS,debug
These options need to match


网上搜是需要重新安装编译

1
brew reinstall <formulaname> --build-from-source

背景

使用JWT时,因为本地时间和服务器上的时间不一致,导致的请求发送失败

解决方法

vendor\firebase\php-jwt\src\JWT.php中的第113行左右添加如下的代码

1
echo '<br /> payload->iat = '. $payload->iat . '<br />and time() = '.time() . "<br />leeway= ". self::$leeway;

会打印出

1
2
3
payload->iat = 1447702275  
and time() = 1447702211
leeway= 0

通过时间差计算出和服务器的差值,并调整本地的时间

背景

自己有翻墙工具,而其他人没有,无法获取到插件

步骤

访问Chrome扩展商店

搜索需要提取的扩展

点击进入扩展详情

复制地址栏连接

打开chrome-extension-downloader.com

粘贴地址

点击下载即可

背景

服务器的内容转到另一台服务器

过程

首先进行了打包

1
tar -cvf ./kod.tar ./kod3.1

打完包,发现有3个多G
就尝试打包压缩

1
tar -zcvf ./kod2.tar.gz ./kod3.1

结果还是3G多,只压缩了200M

进行传输

1
scp ./kod.tar root@192.168.60.168:/tmp

开始有5M/s的速度,可慢慢地变得只有800K/s
最气人的是在60%时的时候居然出现了stalled

排查问题

1
2
3
4
5
6
7
8
9
10
11
12


When transferring large files(for example mksysb images) using scp through a firewall, the scp connection stalls.
Cause:

The reason for scp to stall, is because scp greedily grabs as much bandwith of the network as possible when it transfers files, any delay caused by the network switch of the firewall can easily make the TCP connection stalled.
Solution:

There’s a solution to this problem: Add “-l 8192″ to the scp command.

Adding the option “-l 8192″ limits the scp session bandwith up to 8192 Kbit/second, which seems to work safe and fast enough (up to 1 MB/second):

解决问题

在原有的命令行上加上了-l 8192可以维持在1M/s

1
scp -l 8192 ./kod.tar root@192.168.60.168:/tmp

开始速度也有6M/s,后面速度一直维持在1M/s,中间无stalled

如果是-l 16000则维持在2M/s,以此类推

解压

1
tar -xvf kod.tar

或者

1
tar -zxvf kod.tar.gz

补充

因为转移的文件有很多,而且都很大,我们不可能一直开者等待它传完,这就需要后台运行

先输入密码进行传输
然后用ctrl+z,将当前进程挂起到后台暂停运行,执行一些别的操作
然后用 bg 来将挂起的进程放在后台(也可以用 fg 来将挂起的进程重新放回前台)继续运行

1
2
3
4
5
6
7
8
9
10
11
[root@pvcent107 build]# scp -l 8192 ./kod.tar root@192.168.60.168:/tmp
---------ctrl+zx
[1]+ Stopped scp -l 8192 ./kod.tar root@192.168.60.168:/tmp
[root@pvcent107 build]# bg %1
[1]+ scp -l 8192 ./kod.tar root@192.168.60.168:/tmp &
[root@pvcent107 build]# jobs
[1]+ Running scp -l 8192 ./kod.tar root@192.168.60.168:/tmp &
[root@pvcent107 build]# disown -h %1
[root@pvcent107 build]# ps -ef |grep kod
root 5790 5577 1 10:04 pts/3 00:00:00 scp -l 8192 ./kod.tar root@192.168.60.168:/tmp
root 5824 5577 0 10:05 pts/3 00:00:00 grep kod

注意

有时jobs会有多个,注意自己的文件大小是否正常,我就别坑了1次,没传输完成(完成了一个jobs),以为完成了就进行解压缩了。

400G个文件打包

之前想着。。。400G的文件需要切分-,-!可是用了切分时,却始终没有获取完整的包,好几次我都相信我的总包才80G

最后用了整包打包

1
nohup tar -cjf kod.tar.bz2 ./kod >/dev/null 2>&1 &

打完包发现才有400G+…….我的天,整整打包了一天一夜

400G的传输

scp 已经无法满足,因为万一中间来个服务器重启,或者其他因素那over了,那流量可就白白流失了
最后采用了rsync

1
rsync -P --rsh=ssh ./kod_all.tar.bz2 112.13.14.156:/data/ 

然后输入密码
再ctrl+z 暂停
再bg %1 放入后台(假设当前后台允许索引为1)
然后用jobs查看
如果你当前退出过当前终端,jobs已经无法查看到后台运行的进程,只能用ps

1
ps -ef |grep kod

会有如下的显示

1
2
root     175100 174758 47 08:10 pts/2    00:15:13 rsync -P --rsh=ssh ./kod_all.tar.bz2 112.13.91.176:/data/
root 183245 174758 0 08:42 pts/2 00:00:00 grep --color=auto kod

其中00:15:13指本次断点续传进行的时间。
当传输了200G以后,继续进行断点续传,这个时间会有好长一段时间是不更新的(作者认为它在寻找上一次的断点,因为文件大了寻找的时间会久一点),如果你这个时候马上关闭总端,很有可能本次传输就没执行,我就被坑了一次,一觉醒来一点就没传。。。

rsync与scp的差异

用scp时,这边传多少,另一个服务器就显示文件实时大小
而用rsync时,另一个服务器不实时显示文件大小,只有将这边的进程暂时kill掉,才能知道到底传了多少(可能我这个办法比较粗暴)

1
kill -9 175100

400G的解压

1
nohup tar -xjf ./kod_all.tar.bz2 > /dev/null 2>&1 &

其他查看操作同上面

其他,拆分打包(失败了)

1
nohup tar -cjf - kod/ |split -b 10000m - kod.tar.bz2. >/dev/null 2>&1 &

它会生成

1
2
3
4
5
6
7
-rw-r--r-- 1 Administrator 197121   5242880 十二 27 08:39 kod.tar.bz2.aa
-rw-r--r-- 1 Administrator 197121 5242880 十二 27 08:39 kod.tar.bz2.ab
-rw-r--r-- 1 Administrator 197121 5242880 十二 27 08:39 kod.tar.bz2.ac
-rw-r--r-- 1 Administrator 197121 5242880 十二 27 08:39 kod.tar.bz2.ad
-rw-r--r-- 1 Administrator 197121 5242880 十二 27 08:39 kod.tar.bz2.ae
-rw-r--r-- 1 Administrator 197121 5242880 十二 27 08:39 kod.tar.bz2.af
-rw-r--r-- 1 Administrator 197121 5242880 十二 27 08:39 kod.tar.bz2.ag

后面默认2位,字符逐渐增加
它的解压

1
nohup cat pinkephp.tar.bz2.* | tar -xj &

参考

https://linux.cn/article-7170-1.html

http://blog.csdn.net/tdstds/article/details/24870535

http://blog.csdn.net/eroswang/article/details/5555415/

背景

客户想让他的网站都显示思源字体

参考

fontsquirrel
https://www.fontsquirrel.com
CSS @font-face属性实现在网页中嵌入任意字体
http://www.jb51.net/css/23073.html

如何在网页中嵌入自己想要的字体(实例下载)
http://blog.csdn.net/sinolzeng/article/details/41802951

linux安装字体(错误的方法)

下载字体

下载思源全套字体(字体文件名称:NotoSansHans)

1
https://pan.baidu.com/s/1uJBBK

windows的字体比较多,其字体文件位于 C:\WINDOWS\Fonts,如果想额外安装也可以到这里找找

字体格式有ttf和otf等多重后缀,linux上ttf和oft都可以

移动文件到服务器指定位置

1
2
3
4
# mkdir /usr/share/fonts/NotoSansHans
# cp arial*.otf /usr/share/fonts/NotoSansHans/

# cp arial*.ttf /usr/share/fonts/NotoSansHans/

为刚加入的字体设置缓存使之有效

1
2
# cd /usr/share/font/NotoSansHans
# fc-cache -fv

使用

因为我在windows里先安装了思源字体,并在Noto Sans S Chinese中找到了思源字体,所以font-family中我用Noto Sans S Chinese

1
2
3
4
5
6
body {
font-family: "Noto Sans S Chinese", Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
color: #777777;
font-size: 14px;
}

问题

为什么文件名是NotoSansHans,安装后需要Noto Sans S Chinese
这里有个疑惑

疑惑解决(2017.12.8)

自己本地安装了ttf包后,生成了Noto Sans S Chinese字体,可是这个字体不是服务器里的

也就是说,我在linux上安装的字体只能在linux上使用,浏览器里使用一个是看客户端有没有这个字体,另一个是你的css中引入如ttf之类的字体资源,但是对于中文来说,要把整个字体都方法css上,大概要10M以上(这个肯定不是个办法)

css font-face引入(只能引入英文字体)


https://www.fontsquirrel.com
中找到自己需要的字体

1
2
3
4
5
6
7
8
9
10
@font-face {
font-family: 'fontNameRegular';
src: url('fontName.eot');
src: local('fontName Regular'),
local('fontName'),
url('fontName.woff') format('woff'),
url('fontName.ttf') format('truetype'),
url('fontName.svg#fontName') format('svg');
}
/*其中fontName替换为你的字体名称*/

总结

想在网页中全部使用某不常用的字体,几乎是不可取的方法,除非客户端里大家都安装了该字体

背景

element官方的icon太少

参考

http://blog.csdn.net/b376924098/article/details/78286880#reply

CSS3 @font-face [http://www.w3cplus.com/content/css3-font-face]

过程

  • 去阿里巴巴矢量图,地址;http://www.iconfont.cn/
  • 进入网站登录账户后,新建一个项目
  • 选择一些自己要用到的图标如上图点击购物车按钮添加到购物车。
  • 保存时,以yourprogect-icon命名
  • 并命名一个自己的字体名称,jkkjFontFamily
  • 在iconfont.css添加以下代码
    1
    2
    3
    4
    5
    6
    7
    8
    [class^="jkkj-icon"], [class*=" jkkj-icon"] {
    font-family:"jkkjFontFamily" !important;
    /* 以下内容参照第三方图标库本身的规则 */
    font-size: 18px;
    font-style:normal;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    }
    效果类似于下图

背景

公司开始了新项目用了vue,因为用了某人开源的基础架构,所以被动的被用上了eslint,刚开始用sublime写vue,结果各种规法错误,很是恼火。最后按网上教程用了vscode+eslint插件,一键格式化错误,牛X死了

安装eslint插件

安装并配置完成 ESLint 后,我们继续回到 VSCode 进行扩展设置,依次点击 文件 > 首选项 > 设置 打开 VSCode 配置文件,添加如下配置

1
2
3
4
5
6
7
8
9
10
11
"eslint.autoFixOnSave": true,
"files.autoSave":"off",
"eslint.validate": [
"javascript",
"javascriptreact",
"html",
{ "language": "vue", "autoFix": true }
],
"eslint.options": {
"plugins": ["html"]
}

这样每次保存的时候就可以根据根目录下.eslintrc.js你配置的eslint规则来检查和做一些简单的fix。

当前eslint规则

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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
module.exports = {
root: true,
parser: 'babel-eslint',
parserOptions: {
sourceType: 'module'
},
env: {
browser: true,
node: true,
es6: true,
},
extends: 'eslint:recommended',
// required to lint *.vue files
plugins: [
'html'
],
// check if imports actually resolve
'settings': {
'import/resolver': {
'webpack': {
'config': 'build/webpack.base.conf.js'
}
}
},
// add your custom rules here
//it is base on https://github.com/vuejs/eslint-config-vue
'rules': {
'accessor-pairs': 2,
'arrow-spacing': [2, { 'before': true, 'after': true }],
'block-spacing': [2, 'always'],
'brace-style': [2, '1tbs', { 'allowSingleLine': true }],
'camelcase': [0, { 'properties': 'always' }],
'comma-dangle': [2, 'never'],
'comma-spacing': [2, { 'before': false, 'after': true }],
'comma-style': [2, 'last'],
'constructor-super': 2,
'curly': [2, 'multi-line'],
'dot-location': [2, 'property'],
'eol-last': 2,
'eqeqeq': [2, 'allow-null'],
'generator-star-spacing': [2, { 'before': true, 'after': true }],
'handle-callback-err': [2, '^(err|error)$' ],
'indent': [2, 2, { 'SwitchCase': 1 }],
'jsx-quotes': [2, 'prefer-single'],
'key-spacing': [2, { 'beforeColon': false, 'afterColon': true }],
'keyword-spacing': [2, { 'before': true, 'after': true }],
'new-cap': [2, { 'newIsCap': true, 'capIsNew': false }],
'new-parens': 2,
'no-array-constructor': 2,
'no-caller': 2,
'no-console': 'off',
'no-class-assign': 2,
'no-cond-assign': 2,
'no-const-assign': 2,
'no-control-regex': 2,
'no-delete-var': 2,
'no-dupe-args': 2,
'no-dupe-class-members': 2,
'no-dupe-keys': 2,
'no-duplicate-case': 2,
'no-empty-character-class': 2,
'no-empty-pattern': 2,
'no-eval': 2,
'no-ex-assign': 2,
'no-extend-native': 2,
'no-extra-bind': 2,
'no-extra-boolean-cast': 2,
'no-extra-parens': [2, 'functions'],
'no-fallthrough': 2,
'no-floating-decimal': 2,
'no-func-assign': 2,
'no-implied-eval': 2,
'no-inner-declarations': [2, 'functions'],
'no-invalid-regexp': 2,
'no-irregular-whitespace': 2,
'no-iterator': 2,
'no-label-var': 2,
'no-labels': [2, { 'allowLoop': false, 'allowSwitch': false }],
'no-lone-blocks': 2,
'no-mixed-spaces-and-tabs': 2,
'no-multi-spaces': 2,
'no-multi-str': 2,
'no-multiple-empty-lines': [2, { 'max': 1 }],
'no-native-reassign': 2,
'no-negated-in-lhs': 2,
'no-new-object': 2,
'no-new-require': 2,
'no-new-symbol': 2,
'no-new-wrappers': 2,
'no-obj-calls': 2,
'no-octal': 2,
'no-octal-escape': 2,
'no-path-concat': 2,
'no-proto': 2,
'no-redeclare': 2,
'no-regex-spaces': 2,
'no-return-assign': [2, 'except-parens'],
'no-self-assign': 2,
'no-self-compare': 2,
'no-sequences': 2,
'no-shadow-restricted-names': 2,
'no-spaced-func': 2,
'no-sparse-arrays': 2,
'no-this-before-super': 2,
'no-throw-literal': 2,
'no-trailing-spaces': 2,
'no-undef': 2,
'no-undef-init': 2,
'no-unexpected-multiline': 2,
'no-unmodified-loop-condition': 2,
'no-unneeded-ternary': [2, { 'defaultAssignment': false }],
'no-unreachable': 2,
'no-unsafe-finally': 2,
'no-unused-vars': [2, { 'vars': 'all', 'args': 'none' }],
'no-useless-call': 2,
'no-useless-computed-key': 2,
'no-useless-constructor': 2,
'no-useless-escape': 0,
'no-whitespace-before-property': 2,
'no-with': 2,
'one-var': [2, { 'initialized': 'never' }],
'operator-linebreak': [2, 'after', { 'overrides': { '?': 'before', ':': 'before' } }],
'padded-blocks': [2, 'never'],
'quotes': [2, 'single', { 'avoidEscape': true, 'allowTemplateLiterals': true }],
'semi': [2, 'never'],
'semi-spacing': [2, { 'before': false, 'after': true }],
'space-before-blocks': [2, 'always'],
'space-before-function-paren': [2, 'never'],
'space-in-parens': [2, 'never'],
'space-infix-ops': 2,
'space-unary-ops': [2, { 'words': true, 'nonwords': false }],
'spaced-comment': [2, 'always', { 'markers': ['global', 'globals', 'eslint', 'eslint-disable', '*package', '!', ','] }],
'template-curly-spacing': [2, 'never'],
'use-isnan': 2,
'valid-typeof': 2,
'wrap-iife': [2, 'any'],
'yield-star-spacing': [2, 'both'],
'yoda': [2, 'never'],
'prefer-const': 2,
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
'object-curly-spacing': [2, 'always', { objectsInObjects: false }],
'array-bracket-spacing': [2, 'never']
}
}

使用

shift+ctrl+p => 选择 eslint fix all auto-fixable problems

背景

在公司windows下用gitbash,每次打开都要切换到D盘指定目录,非常费时,网上搜了一下果真有对应方法

参考

http://blog.csdn.net/zzfenglin/article/details/54646541

实现方法

在“Git Bash”快捷方式上点击鼠标右键,然后选择“属性”,会弹出如下截图的提示框:

我们可以看到在“目标”后面的输入框中有操作的命令,在命令的最后是“–cd-to-home”,就是这条命令在快捷方式打开的时候切换到“/c/Users/Administrator”路径了。

假如,我们想把默认路径修改为“D:\android_workspace”,那我们需要操作两步:

1.将“目录”后面输入框中命令结尾部分去掉,即删掉“–cd-to-home”。

2.将“起始位置”后面的输入框中的内容修改为我们想要的默认路径“D:\android_workspace”(注意:这个路径是根据你自己代码工程的位置而定的)

修改之后的操作截图如下:

修改之后,点击“确定”,然后重新打开“Git Bash”,就会自动切换到我们想要的路径