Faremax

Faremax 查看完整档案

北京编辑中国海洋大学  |  电子与通信工程 编辑大数据公司  |  前端开发工程师 编辑 nothing.else 编辑
编辑

小编初入职场,由于精力有限,博客产量有点低,请同学们见谅!

个人动态

Faremax 关注了用户 · 9月1日

wangshijun @wangshijun2010

资深前端工程师、架构师、布道师、麦子学院金牌讲师、前端周刊编辑

关注 217

Faremax 评论了文章 · 2019-04-28

面向web前端及node开发人员的vim配置

鉴于 window 下基本用不到 vim,所以下面内容不再提及 window,具体可以在相应 github 中查看手册
操作基础:已装有上有 nodejs(npm)。没装的可以移步官网:https://nodejs.org/en/
<!--善其事利其器(3) - -->
另有 sublime 配置方式,请移步:sublime配置及使用技巧

插件管理工具 pathogen

github地址: github

mkdir -p ~/.vim/autoload ~/.vim/bundle && \
curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim

插件

安装插件都在 ~/.vim/bundle/ 中安装,以下部分操作可能需要 root 权限

  • vim-sensible vim新人专属 github
cd ~/.vim/bundle/
git clone git://github.com/tpope/vim-sensible.git
cd ~/.vim/bundle/
git clone https://github.com/vim-airline/vim-airline-themes.git
cd ~/.vim/bundle/
git clone https://github.com/vim-airline/vim-airline-themes ~/.vim/bundle/vim-airline-themes
  • Emmet 快速建立html树 github
cd ~/.vim/bundle/
git clone https://github.com/mattn/emmet-vim.git
  • editorconfig 编辑器配置 github
cd ~/.vim/bundle/
git clone https://github.com/editorconfig/editorconfig-vim.git

新建文件 vim ~/.vim/.editconfig (可自定义,通常放在项目根目录),键入以下设置:

root = true

indent_style = space
indent_size = 2
tab_width = 2
end_of_line = lf
charset = utf-8
insert_final_newline = true
trim_trailing_whitespace = true
  • vim-multiple-cursors 支持多行编辑 github
cd ~/.vim/bundle/
git clone https://github.com/terryma/vim-multiple-cursors.git
  • unite-vim 快速管理项目中的文件 github
cd ~/.vim/bundle/
git clone https://github.com/Shougo/unite.vim.git
  • vim-javascript 缩进和语法支持 github
cd ~/.vim/bundle/
git clone https://github.com/pangloss/vim-javascript.git
  • jsDoc 对 vim-javascript 的补充,支持 es6和 TypeScirpt github
cd ~/.vim/bundle/
git clone https://github.com/heavenshell/vim-jsdoc.git
  • Fugitive git版本控制 github
git clone git://github.com/tpope/vim-fugitive.git
vim -u NONE -c "helptags vim-fugitive/doc" -c q
cd ~/.vim/bundle/
git clone --depth=1 https://github.com/vim-syntastic/syntastic.git

syntastic 需要一些其他的

npm install -g jslint
npm install -g csslint
cd ~/.vim/bundle/
git clone https://github.com/hail2u/vim-css3-syntax.git
brew install tidy-html5
  • vim-css-color 自动预览颜色 github
cd ~/.vim/bundle/
git clone https://github.com/skammer/vim-css-color.git
  • vim-snipmate 自动完成代码块 github
cd ~/.vim/bundle/
git clone https://github.com/tomtom/tlib_vim.git
git clone https://github.com/MarcWeber/vim-addon-mw-utils.git
git clone https://github.com/garbas/vim-snipmate.git
# Optional:
git clone https://github.com/honza/vim-snippets.git
  • vim-surround 辅助格式控制(用于括号、引号等) github
cd ~/.vim/bundle/
git clone git://github.com/tpope/vim-surround.git
  • jsbeauty-vim 自动美化代码,可配合 vim-autoformat 使用 github
cd ~/.vim/bundle/
git clone https://github.com/maksimr/vim-jsbeautify.git
cd vim-jsbeautify && git submodule update --init --recursive
  • vim-markdown 把高亮功能推广到 markdown github
cd ~/.vim/bundle/
git clone https://github.com/plasticboy/vim-markdown.git
  • vim-instant-markdown 预览 markdown githjub
npm -g install instant-markdown-d
  • vim-markdown-toc 为 markdown 生成标题 github
cd ~/.vim/bundle/
git clone https://github.com/mzlogin/vim-markdown-toc.git
  • youcompleteme 代码提示和补全 github

这个放在最后因为它比较复杂。属于可选的插件,根据自己需求安装。
首先,在 vim normal 模式输入 :version 查看其版本,要求版本大于7.4.143, 否则更新它。
其次,在 vim normal 模式输入 :echo has('python') || has('python3'), 如果输出为0,请更新 vim 以支持 python。
之后,在终端输入:

cd ~/.vim/bundle/
git clone https://github.com/Valloric/YouCompleteMe.git
cd ~/.vim/bundle/YouCompleteMe/
git submodule update --init --recursive
cd ~/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/tern_runtime
npm install --production

如果你需要支持 typescript,安装:

npm install -g typescript
cd ~/.vim/bundle/
git clone https://github.com/groenewege/vim-less

到这里还没有完,作为前端人,这个还不能正常工作,它需要一些依赖,下面我们来安装这些依赖:

回到 bundle 目录 安装

cd ~/.vim/bundle
git clone https://github.com/ternjs/tern_for_vim.git
cd ~/.vim/bundle/tern_for_vim
npm install

之后需要在您的项目根目录建立一个 .tern-project 文件,没有内容,空白即可。该文件内部结构如下:

{ "libs": [ "browser", "jquery" ], "loadEagerly": [ "importantfile.js" ], "plugins": {
    "requirejs": {
      "baseURL": "./",
      "paths": {}
    }
  }
}

此部分详细配置在此 http://ternjs.net/doc/manual.html

  • apt-vim 自动管理插件 github

这里再安装一个插件自动管理插件,也比较麻烦,根据自己需求安装:

  1. 自动安装
curl -sL https://raw.githubusercontent.com/egalpin/apt-vim/master/install.sh | sh

2.手动安装
需要Python2.7.x或Python3.0+

cd ~/.vim/bundle/
git clone https://github.com/egalpin/apt-vim.git
cd apt-vim
sudo ./apt-vim init

编辑 ~/.bashrc 或 ~/.bash_profile , 添加下面一句话

export PATH=$PATH:~/.vimpkg/bin

编辑 ~/.vimrc 添加:

execute pathogen#infect()
call pathogen#helptags()

继续在终端执行:

source ~/.bashrc
apt-vim install

如果这里提示了:Completed successfully. 那就大功告成了。

到此为止,作为一个前端人的 vim 就基本搭建好了,如果还有什么好用的插件欢迎分享交流,如果你觉得这些插件还足够,可以去知乎、stackoverflow、或 github 上再挖掘一些。一些更高级插件会随着博主的积累,不断更新这篇内容的,欢迎关注。

下面附了我 .vimrc.editorconfig 文件的内容:

"vimrc
"vim original config
set ignorecase        " ignore upper- or lowercase in search model
set smartcase         " if there is uppercase in search string ignore 'ignorecase' setting. it only works with 'ignorecase' setting
set autowrite         " auto write changes into file after :next、:rewind、:last、:first、:previous、:stop、:suspend、:tag、:!、:make、<C-]> or <C-^> runs, as well as jumps to another file with :buffer、<C-O>、<C-I>、'{A-Z0-9}' or `{A-Z0-9}`
set nocompatible      "Donot compate with vi, to avoid some bugs
filetype on           "check the file type
set autoindent        " use auto-indentation
set smartindent       " use smart indentation
set tabstop=2         " set the width of tab key
set softtabstop=2     " set the width of soft key
set shiftwidth=2      " auto-indent with 2 spaces
set backspace=2       " enable to use backspace
set showmatch         " show the matched braces
set linebreak         " wrap without breakword
set whichwrap=b,s,<,>,[,]   "jump to previous/next line when cursor at the head/end of line when input 'b'/'w' in normal model
set relativenumber    " show relative line number
set previewwindow     " show preview window
set history=1000      " set command history to 1000
set laststatus=2      " show the last activited window's status line always
set ruler             " show line number and column number in status  line

"command line setting
set showcmd           " show inputted command in command line
set showmode          " show current model in command line
set showmatch         "show match brace
set guioptions=T      "remove the toolbar in GUI
filetype on           "check the file type

"finding setting
set incsearch         " show matched words when input string
set hlsearch

"pathongen
execute pathogen#infect()
syntax on
filetype plugin indent on

"airline
let g:airline_theme='molokai'    "use a theme called 'molokai'
let g:airline#extensions#tabline#enabled=1    "show the tab line on the top
let g:airline_powerline_fonts=1    "use powerline fonts

"emmet
let g:user_emmet_mode='n'    "only enable normal mode functions.
let g:user_emmet_mode='inv'  "enable all functions, which is equal to
let g:user_emmet_mode='a'    "enable all function in all mode.
let g:user_emmet_install_global=0
autocmd FileType html,css EmmetInstall    "enable for just html/css
let g:user_emmet_leader_key='<C-Z>'    "change the default key(<C-Y>) to <C-Z>,  the trailing ',' still needs to be entered as well

"editConfig
let g:EditorConfig_exclude_patterns = ['fugitive://.*']    "ensure that this plugin works well with Tim Pope's fugitive
let g:EditorConfig_exclude_patterns = ['scp://.*']    "avoid loading EditorConfig for any remote files over ssh
let g:EditorConfig_exec_path = '~/.vim/.editorconfig'
let g:editorconfig_Beautifier = '~/.vim/.editorconfig'
"vim-javascript
let g:javascript_plugin_jsdoc=1    "Enables syntax highlighting for JSDocs.
let g:javascript_plugin_ngdoc=1    "Enables some additional syntax highlighting for NGDocs. Requires JSDoc plugin to be enabled as well.

"jsDoc
let g:jsdoc_enable_es6=1    "Enable to use ECMAScript6's Shorthand function, Arrow function.
let g:javascript_plugin_flow=1    "Enables syntax highlighting for Flow.

"syntastic
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
let g:syntastic_enable_highlighting=1

"apt-vim
execute pathogen#infect()
call pathogen#helptags()

"jsbeautify
autocmd FileType javascript noremap <buffer>  <c-f> :call JsBeautify()<cr>
autocmd FileType json noremap <buffer> <c-f> :call JsonBeautify()<cr>
autocmd FileType jsx noremap <buffer> <c-f> :call JsxBeautify()<cr>
autocmd FileType html noremap <buffer> <c-f> :call HtmlBeautify()<cr>
autocmd FileType css noremap <buffer> <c-f> :call CSSBeautify()<cr>

"vimCSS3syntsx
augroup VimCSS3Syntax
  autocmd!
  autocmd FileType css setlocal iskeyword+=-
augroup END

"vimCSScolor
let g:cssColorVimDoNotMessMyUpdatetime = 1

"YCM
let g:ycm_semantic_triggers =  { 'scss,css': [ 're!^\s{2,4}', 're!:\s+' ], 'html': ['<', '"', '</', ' '] }

"less2css
let g:less_autocompile = 1  " 这是开关 设置1保存less自动生成css  设置0关闭
function! s:auto_less_compile() " {{{
  if g:less_autocompile != 0
    try
      let css_name = expand("%:r") . ".css"
      let less_name = expand("%")
      if filereadable(css_name) || 0 < getfsize(less_name)
        let cmd = ':!lessc '.less_name.' 'css_name.' '
        silent execute cmd
      endif
    endtry
  endif
endfunction " }}}
autocmd BufWritePost *.less call s:auto_less_compile()
;.editorconfig
root = true

indent_style = space
indent_size = 2
tab_width = 2
end_of_line = lf
charset = utf-8
insert_final_newline = true
trim_trailing_whitespace = true

[**.js]
path=~/.vim/bundle/js-beautify/js/lib/beautify.js
bin=node

[**.jsx]
e4x = true
查看原文

Faremax 评论了文章 · 2019-03-27

Mac 下 MySQL 环境搭建

Mac 下安装 MySQL 还是很方便的, 总结来看有2个方法。

方法一:用dmg镜像安装

1、安装

官网下载好 MySQL Mac 版安装包,常规步骤安装,安装过程中会出现如下提示:

2019-03-24T18:27:31.043133Z 1 [Note] A temporary password is generated for root@localhost: TdfRm19!o0Xi

其中TdfRm19!o0Xi是初始密码,最好先记住!

2、登陆

在终端命令行 登陆mysql:

$ mysql -u root -p
# 输入上述密码即可

如果这一步提示: bash: mysql: command not found, 执行下面2个命令做个软连接即可:

cd /usr/local/bin
ln -fs /usr/local/mysql-8.0.11-macos10.13-x86_64/bin/mysql mysql

3、修改密码

在 MySQL8.0.4 以前,执行 SET PASSWORD=PASSWORD('新密码') 即可。但新版本不能这样改了,因为密码认证变了。具体步骤可以参考 https://blog.csdn.net/yi247630676/article/details/80352655

方法二:用 Homebrew 进行安装

总所周知,Mac 可以利用 homebrew 进行安装管理,十分方便,如果没有安装 homebrew, 可以点击 https://brew.sh/ 安装。

下面是 mysql 的安装方式

$ brew install mysql   # 安装指定版本: brew install mysql@1.1.1

接下来只要等待就可以了,出现下面文字后我们已经很清楚我们需要做什么了:

==> mysql
We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
    mysql -u root

To have launchd start mysql now and restart at login:
  brew services start mysql
Or, if you don't want/need a background service you can just run:
  mysql.server start

按说明继续执行,进行初始化操作:

$ myysql_secure_installation

初始化过程中会有很多问题,以下是具体问题部分,以注释为解释:

Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: Y   ## 回复y 需要密码8位以上,回复n 则不做限制

The password validation component is not available. Proceeding with the further steps without the component.
Please set the password for root here.

New password:   ## 设置你的密码

Re-enter new password:   ## 再次输入你的密码

By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y    ## 是否移除匿名用户。考虑安全我选了y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y   ## 是否允许远程连mysql 的 root。我用做本地调试,不是远程服务器,所以y了
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y      ## 是否y了删除test数据库,我选了y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y      ## 选y, 重新加载权限列表
Success.

All done!

到此配置就结束了,下面我们启动 mysql 即可,记住以下命令:

$ mysql -u root -p   ## 登陆 mysql
$ brew services start mysql@5.7   ## 启动 mysql
$ brew services stop mysql@5.7   ## 停止 mysql
$ mysql.server start   ## 启动 mysql(无后台服务)
查看原文

Faremax 评论了文章 · 2019-03-27

Mac 下 MySQL 环境搭建

Mac 下安装 MySQL 还是很方便的, 总结来看有2个方法。

方法一:用dmg镜像安装

1、安装

官网下载好 MySQL Mac 版安装包,常规步骤安装,安装过程中会出现如下提示:

2019-03-24T18:27:31.043133Z 1 [Note] A temporary password is generated for root@localhost: TdfRm19!o0Xi

其中TdfRm19!o0Xi是初始密码,最好先记住!

2、登陆

在终端命令行 登陆mysql:

$ mysql -u root -p
# 输入上述密码即可

如果这一步提示: bash: mysql: command not found, 执行下面2个命令做个软连接即可:

cd /usr/local/bin
ln -fs /usr/local/mysql-8.0.11-macos10.13-x86_64/bin/mysql mysql

3、修改密码

在 MySQL8.0.4 以前,执行 SET PASSWORD=PASSWORD('新密码') 即可。但新版本不能这样改了,因为密码认证变了。具体步骤可以参考 https://blog.csdn.net/yi247630676/article/details/80352655

方法二:用 Homebrew 进行安装

总所周知,Mac 可以利用 homebrew 进行安装管理,十分方便,如果没有安装 homebrew, 可以点击 https://brew.sh/ 安装。

下面是 mysql 的安装方式

$ brew install mysql   # 安装指定版本: brew install mysql@1.1.1

接下来只要等待就可以了,出现下面文字后我们已经很清楚我们需要做什么了:

==> mysql
We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
    mysql -u root

To have launchd start mysql now and restart at login:
  brew services start mysql
Or, if you don't want/need a background service you can just run:
  mysql.server start

按说明继续执行,进行初始化操作:

$ myysql_secure_installation

初始化过程中会有很多问题,以下是具体问题部分,以注释为解释:

Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: Y   ## 回复y 需要密码8位以上,回复n 则不做限制

The password validation component is not available. Proceeding with the further steps without the component.
Please set the password for root here.

New password:   ## 设置你的密码

Re-enter new password:   ## 再次输入你的密码

By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y    ## 是否移除匿名用户。考虑安全我选了y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y   ## 是否允许远程连mysql 的 root。我用做本地调试,不是远程服务器,所以y了
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y      ## 是否y了删除test数据库,我选了y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y      ## 选y, 重新加载权限列表
Success.

All done!

到此配置就结束了,下面我们启动 mysql 即可,记住以下命令:

$ mysql -u root -p   ## 登陆 mysql
$ brew services start mysql@5.7   ## 启动 mysql
$ brew services stop mysql@5.7   ## 停止 mysql
$ mysql.server start   ## 启动 mysql(无后台服务)
查看原文

Faremax 评论了文章 · 2019-03-27

Mac 下 MySQL 环境搭建

Mac 下安装 MySQL 还是很方便的, 总结来看有2个方法。

方法一:用dmg镜像安装

1、安装

官网下载好 MySQL Mac 版安装包,常规步骤安装,安装过程中会出现如下提示:

2019-03-24T18:27:31.043133Z 1 [Note] A temporary password is generated for root@localhost: TdfRm19!o0Xi

其中TdfRm19!o0Xi是初始密码,最好先记住!

2、登陆

在终端命令行 登陆mysql:

$ mysql -u root -p
# 输入上述密码即可

如果这一步提示: bash: mysql: command not found, 执行下面2个命令做个软连接即可:

cd /usr/local/bin
ln -fs /usr/local/mysql-8.0.11-macos10.13-x86_64/bin/mysql mysql

3、修改密码

在 MySQL8.0.4 以前,执行 SET PASSWORD=PASSWORD('新密码') 即可。但新版本不能这样改了,因为密码认证变了。具体步骤可以参考 https://blog.csdn.net/yi247630676/article/details/80352655

方法二:用 Homebrew 进行安装

总所周知,Mac 可以利用 homebrew 进行安装管理,十分方便,如果没有安装 homebrew, 可以点击 https://brew.sh/ 安装。

下面是 mysql 的安装方式

$ brew install mysql   # 安装指定版本: brew install mysql@1.1.1

接下来只要等待就可以了,出现下面文字后我们已经很清楚我们需要做什么了:

==> mysql
We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
    mysql -u root

To have launchd start mysql now and restart at login:
  brew services start mysql
Or, if you don't want/need a background service you can just run:
  mysql.server start

按说明继续执行,进行初始化操作:

$ myysql_secure_installation

初始化过程中会有很多问题,以下是具体问题部分,以注释为解释:

Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: Y   ## 回复y 需要密码8位以上,回复n 则不做限制

The password validation component is not available. Proceeding with the further steps without the component.
Please set the password for root here.

New password:   ## 设置你的密码

Re-enter new password:   ## 再次输入你的密码

By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y    ## 是否移除匿名用户。考虑安全我选了y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y   ## 是否允许远程连mysql 的 root。我用做本地调试,不是远程服务器,所以y了
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y      ## 是否y了删除test数据库,我选了y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y      ## 选y, 重新加载权限列表
Success.

All done!

到此配置就结束了,下面我们启动 mysql 即可,记住以下命令:

$ mysql -u root -p   ## 登陆 mysql
$ brew services start mysql@5.7   ## 启动 mysql
$ brew services stop mysql@5.7   ## 停止 mysql
$ mysql.server start   ## 启动 mysql(无后台服务)
查看原文

Faremax 发布了文章 · 2019-03-25

Mac 下 MySQL 环境搭建

Mac 下安装 MySQL 还是很方便的, 总结来看有2个方法。

方法一:用dmg镜像安装

1、安装

官网下载好 MySQL Mac 版安装包,常规步骤安装,安装过程中会出现如下提示:

2019-03-24T18:27:31.043133Z 1 [Note] A temporary password is generated for root@localhost: TdfRm19!o0Xi

其中TdfRm19!o0Xi是初始密码,最好先记住!

2、登陆

在终端命令行 登陆mysql:

$ mysql -u root -p
# 输入上述密码即可

如果这一步提示: bash: mysql: command not found, 执行下面2个命令做个软连接即可:

cd /usr/local/bin
ln -fs /usr/local/mysql-8.0.11-macos10.13-x86_64/bin/mysql mysql

3、修改密码

在 MySQL8.0.4 以前,执行 SET PASSWORD=PASSWORD('新密码') 即可。但新版本不能这样改了,因为密码认证变了。具体步骤可以参考 https://blog.csdn.net/yi247630676/article/details/80352655

方法二:用 Homebrew 进行安装

总所周知,Mac 可以利用 homebrew 进行安装管理,十分方便,如果没有安装 homebrew, 可以点击 https://brew.sh/ 安装。

下面是 mysql 的安装方式

$ brew install mysql   # 安装指定版本: brew install mysql@1.1.1

接下来只要等待就可以了,出现下面文字后我们已经很清楚我们需要做什么了:

==> mysql
We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
    mysql -u root

To have launchd start mysql now and restart at login:
  brew services start mysql
Or, if you don't want/need a background service you can just run:
  mysql.server start

按说明继续执行,进行初始化操作:

$ myysql_secure_installation

初始化过程中会有很多问题,以下是具体问题部分,以注释为解释:

Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: Y   ## 回复y 需要密码8位以上,回复n 则不做限制

The password validation component is not available. Proceeding with the further steps without the component.
Please set the password for root here.

New password:   ## 设置你的密码

Re-enter new password:   ## 再次输入你的密码

By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y    ## 是否移除匿名用户。考虑安全我选了y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y   ## 是否允许远程连mysql 的 root。我用做本地调试,不是远程服务器,所以y了
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y      ## 是否y了删除test数据库,我选了y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y      ## 选y, 重新加载权限列表
Success.

All done!

到此配置就结束了,下面我们启动 mysql 即可,记住以下命令:

$ mysql -u root -p   ## 登陆 mysql
$ brew services start mysql@5.7   ## 启动 mysql
$ brew services stop mysql@5.7   ## 停止 mysql
$ mysql.server start   ## 启动 mysql(无后台服务)
查看原文

赞 0 收藏 0 评论 4

Faremax 发布了文章 · 2019-03-10

前端开发 VS Code 上手使用

如果想配置 sublime 开发工具 => 面向web前端及node开发人员的vim配置

如果想配置 vim 开发工具 => sublime配置及使用技巧

所谓网红编辑器,我觉得比vim来的更爽,因为vim的所有操作和插件,对于vs code 来说也就是一个插件就能无缝兼容。

比如我之前是一直在使用 sublime 的,使用vs code 之后明显感觉 vscode 无论是配置还是使用都更顺手一点,学习成本很小。当然本文不是谈哪个编辑器更好的问题,每个软件都在发展,相互学习和补充才是重点。

作为一个前端开发,vs code 开箱即用的代码编辑、高亮、提示都十分友好。但作为一个追求完美的程序员,还是装了不少插件,比如

前端开发用的一些插件:

  • Auto Rename Tag: 当你编辑HTML标签是会自动修改配对标签
  • HTML Class Suggestions: HTML class 名称提示
  • ESLint: ES 语法检查
  • Hap Extension: 快应用开发基础支持
  • JavaScript(ES6) code snippets: js 代码片段,提高编码速度
  • open in browser: 在浏览器打开页面,这个已经不常用了,但对于前端初学者还是很友好的
  • QuickApp For Highlighter: 快应用开发高亮
  • Color Info: css 中颜色预览

工程化也需要一些插件:

  • npm: npm 管理
  • npm Intellisense: npm 自动配置
  • GitLens: git 记录查看
  • minify: 代码压缩

写作办公也需要一些工具呀:

  • Excel Viewer: 实际感觉只能预览 csv 文件,不过这也够用了
  • Markdown PDF: markdown 转 pdf
  • Markdown TOC: markdown 目录生成
  • Markdown+Math: markdown 中数学公式支持
  • vscode-pdf: pdf 阅读插件

编辑器本身的插件

  • seti-icons: 文件icon
  • Theme - Seti-Monokai: 高亮及编辑器外观
  • Sublime Text Keymap and Settings Importer: sublime 功能键及配置映射
  • Sublime Babel: sublime
  • vscode-faker: 随机数据生成

其他的一些工具

  • SVG Viewer: SVG 图片预览
  • xtemplate: xtpl 文件高亮支持

我安装了sublime 的插件,其实还有vim 的插件,安装后无缝兼容 .vimrc 配置和 vim plugin。正常的快捷键可以看参考下图,其实和 sublime 差不了太多。

windows

macOS

对于一些不如意的地方,可以在配置文件中进行配置,个人感觉 vs code 配置开放比 sublime 更丰富。

{
    "beautify.language": {
        "js": {
            "type": [
                "javascript",
                "json"
            ],
            "filename": [
                ".jshintrc",
                ".jsbeautify"
            ]
        },
        "css": [
            "css",
            "scss",
            "less"
        ],
        "html": [
            "htm",
            "html"
        ]
    },
    "debug.showInStatusBar": "always",
    "debug.node.autoAttach": "off",
    "beautify.tabSize": 2,
    "css.lint.duplicateProperties": "warning",
    "css.lint.idSelector": "warning",
    "css.lint.universalSelector": "warning",
    "css.lint.zeroUnits": "error",
    "less.lint.duplicateProperties": "warning",
    "less.lint.idSelector": "warning",
    "less.lint.universalSelector": "warning",
    "less.lint.zeroUnits": "error",
    "scss.lint.duplicateProperties": "warning",
    "scss.lint.idSelector": "warning",
    "scss.lint.universalSelector": "warning",
    "scss.lint.zeroUnits": "error",
    "csv-preview.skipComments": true,
    "csv-preview.lineNumbers": true,
    "editor.formatOnPaste": true,
    "editor.find.autoFindInSelection": true,
    "editor.formatOnSave": true,
    "editor.fontSize": 14,
    "editor.formatOnType": true,
    "editor.multiCursorModifier": "ctrlCmd",
    "editor.minimap.enabled": false,
    "editor.snippetSuggestions": "top",
    "editor.tabSize": 2,
    "editor.wordSeparators": "`~!@#$%^&*()=+[{]}\\|;:'\",.<>/?",
    "emmet.includeLanguages": {
        "vue-html": "html",
        "javascript": "javascriptreact"
    },
    "emmet.triggerExpansionOnTab": true,
    "emmet.showAbbreviationSuggestions": false,
    "eslint.autoFixOnSave": true,
    "eslint.options": {
        "configFile": "/Users/faremax/eslintrc.json"
    },
    "eslint.run": "onSave",
    "eslint.workingDirectories": [
        "./public",
        "./src"
    ],
    "explorer.confirmDelete": false,
    "explorer.confirmDragAndDrop": false,
    "explorer.openEditors.visible": 4,
    "files.associations": {
        "*.ux": "ux"
    },
    "files.autoSave": "onFocusChange",
    "files.exclude": {
        "**/.git": true,
        "**/.svn": true,
        "**/.hg": true,
        "**/CVS": true,
        "**/.DS_Store": true,
        "**/node_modules": true
    },
    "files.insertFinalNewline": true,
    "files.trimFinalNewlines": true,
    "files.trimTrailingWhitespace": true,
    "git.detectSubmodules": false,
    "gulp.autoDetect": "off",
    "grunt.autoDetect": "off",
    "html.format.wrapLineLength": 0,
    "jake.autoDetect": "off",
    "javascript.implicitProjectConfig.experimentalDecorators": true,
    "markdown-pdf.displayHeaderFooter": false,
    "markdown-pdf.margin.left": "1.8cm",
    "markdown-pdf.margin.right": "1.8cm",
    "markdown-pdf.margin.top": "1cm",
    "markdown.preview.lineHeight": 1.5,
    "markdown.styles": [
        "/Users/faremax/github-markdown.css"
    ],
    "markdown-pdf.styles": [
        "/Users/faremax/github-markdown.css"
    ],
    "markdown-toc.insertAnchor": true,
    "open-in-browser.default": "Google Chrome.app",
    "search.exclude": {
        "**/node_modules": true,
        "**/bower_components": true,
        "**/build": true,
        "**/dist": true,
    },
    "search.location": "sidebar",
    "svgviewer.enableautopreview": true,
    "terminal.explorerKind": "integrated",
    "window.restoreWindows": "all",
    "workbench.statusBar.feedback.visible": false,
    "window.zoomLevel": 0,
    "workbench.colorTheme": "Monokai",
    "workbench.startupEditor": "newUntitledFile"
}

vs code 还有很多实用技巧,可以看官方github: https://github.com/Microsoft/vscode

查看原文

赞 19 收藏 15 评论 1

Faremax 评论了文章 · 2019-02-25

Chrome 调试技巧

写在前面
本文包括浏览器调试,不包括web移动端调试。
本文调试均在chrome浏览器进行

alert

这个不用多说了,不言自明

console

基本输出

想必大家都在用console.log在控制台输出点东西,其实console还有其它的方法:

console.log("打印字符串");//在控制台打印自定义字符串
console.error("我是个错误");//在控制台打印自定义错误信息
console.info("我是个信息");//在控制台打印自定义信息
console.warn("我是个警告");//在控制台打印自定义警告信息
console.debug("我是个调试");//在控制台打印自定义调试信息
cosole.clear();//清空控制台(这个下方截图中没有)

console

注意上面输出的error和throw出的error不一样,前者只是输出错误信息,无法捕获,不会冒泡,更不会中止程序运行。

格式化输出

除此以外,console还支持自定义样式和类似c语言的printf形式

console.log("%s年",2016);//%s表示字符串
console.log("%d年%d月",2016,11);//%d表示整数
console.log("%f",3.1415926);//%f小数
console.log("%o",console);//%o表示对象

console.log("%c自定义样式","font-size:30px;color:#00f");
console.log("%c我是%c自定义样式","font-size:20px;color:green","font-size:10px;color:red");

console
<todo>

DOM输出

下面几个比较简单的,就不举例子了,简单说一下:

var ul = document.getElementsByTagName("ul");
console.dirxml(ul); //树形输出table节点,即<table>和它的innerHTML,由于document.getElementsByTagName是动态的,所以这个得到的结果肯定是动态的

console

对象输出

var o = {
  name:"Lily",
  age: 18
};
console.dir(obj);//显示对象自有属性和方法

console

对于多个对象的集合,你可以这样,输出更清晰:

var stu = [{name:"Bob",age:13,hobby:"playing"},{name:"Lucy",age:14,hobby:"reading"},{name:"Jane",age:11,hobby:"shopping"}];
console.log(stu);
console.table(stu);

console

成组输出

//建立一个参数组
console.group("start"); //引号里是组名,自己起
console.log("sub1");
console.log("sub1");
console.log("sub1");
console.groupEnd();

console

函数计数和跟踪

function fib(n){ //输出前n个斐波那契数列值
  if(n == 0) return;
  console.count("调用次数");//放在函数里,每当这句代码运行输出所在函数执行次数
  console.trace();//显示函数调用轨迹(访问调用栈)
  var a = arguments[1] || 1;
  var b = arguments[2] || 1;
  console.log("fib=" + a);
  [a, b] = [b, a + b];
  fib(--n, a, b);
}
fib(6);

console
注:Chrome开发者工具中的Sources标签页也在Watch表达式下面显示调用栈。

计时

console.time() //计时开始
fib(100); //用上述函数计算100个斐波那契数
console.timeEnd() //计时结束并输出时长

console
断言语句,这个c++调试里面也经常用到。js中,当第一个表达式或参数为true时候什么也不发生,为false时终止程序并报错

console.assert(true, "我错了");
console.assert(false, "我真的错了");

console

性能分析

function F(){
  var i = 0;
  function f(){
    while(i++ == 1000);
  }
  function g(){
    while(i++ == 100000);
  }
  f();
  g();
}
console.profile();
F();
console.profileEnd();

console
注:Chrome开发者工具中的Audits标签页也可以实现性能分析。

debugger

这个重量级的是博主最常用的,可能是c++出身,对于单步调试由衷的热爱。单步调试就是点一下,执行一句程序,并且可以查看当前作用域可见的所有变量和值。而debugger就是告诉程序在那里停下来进行单步调试,俗称断点。

debugger

右边按钮如下:

  • Pause/Resume script execution:暂停/恢复脚本执行(程序执行到下一断点停止)。
  • Step over next function call:执行到下一步的函数调用(跳到下一行)。
  • Step into next function call:进入当前函数。
  • Step out of current function:跳出当前执行函数。
  • Deactive/Active all breakpoints:关闭/开启所有断点(不会取消)。
  • Pause on exceptions:异常情况自动断点设置。

其实右侧还有很多强大的功能
debugger

  • Watch:Watch表达式
  • Call Stack: 栈中变量的调用,这里是递归调用,肯定是在内存栈部分调用。
  • Scope:当前作用域变量观察。
  • BreakPoints:当前断点变量观察。
  • XHR BreakPoints:面向Ajax,专为异步而生的断点调试功能。
  • DOM BreakPoints:主要包括下列DOM断点,注册方式见下图
  1. 当节点属性发生变化时断点(Break on attributes modifications)
  2. 当节点内部子节点变化时断点(Break on subtree modifications)
  3. 当节点被移除时断点(Break on node removal)

debugger

  • Global Listeners:全局事件监听
  • Event Listener Breakpoints:事件监听器断点,列出了所有页面及脚本事件,包括:鼠标、键盘、动画、定时器、XHR等等。

chrome中的调试技巧

  1. DOM元素的控制台书签

Chrome开发者工具和Firebug都提供了书签功能,用于显示你在元素标签页(Chrome)或HTML标签页(Firebug)中最后点击的DOM元素。如果你依次选择了A元素、B元素和C元素,那么&dollar;0 表示C元素,&dollar;1 表示B元素,&dollar;2 表示A元素。(这个和正则表达式的&dollar;符号类似,不过顺序不同)

  1. 如果你想调试f函数,用debug(f)语句可以增加这种断点。
  2. Sources标签页左侧面板上有一个代码片段(Snippet)子标签页,可用于保存代码片段,帮你调试代码。
  3. 可以用Chrome开发者工具Sources标签页中的格式化按钮(Pretty Print Button)格式化压缩后的代码。
  4. 在Network面板,选择一个资源文件,右键Copy Response可快速复制响应内容。
  5. 利用媒体查询,这个主要是在Device Mode调节不同的分辨率显示。
  6. 选择Elements,按 Esc > Emulation > Sensors进行传感器模拟。
  7. 点击渐入效果样式图标(紫色图标),可以预览动画效果,并可对相应的贝塞尔曲线(cubic-bezier)进行调节动画效果。
  8. 在Source中按住Alt键并拖动鼠标进行多列内容选择。
  9. Elements面板右键执行DOM元素节点,选择Force Element State或者点击右侧Toggle Element State图标可以出发伪类。
  10. Network面板中选择一张图片,在右侧图片上鼠标右键选择copy it as a Data URI,就可以获取图片的Data URL (base64编码)。
  11. 通过按住Ctrl键可以添加多个编辑光标,同时对多处进行编辑。按下Ctrl + U可以撤销编辑。
  12. Elements面板右侧的Style编辑器中,点击颜色十六进制编码前的小色块,会弹出一个调色板。
  13. 按下Alt键并且鼠标双击选择DOM元素前面的箭头,就会展开该DOM元素下的所有字节点元素.
  14. 快捷键:
  • 快速定位到行:快捷键Ctrl+O(Mac:CMD+O),输入:行号:列号 来进行定位
  • 元素搜索:快捷键Ctrl+F(Mac:CMD+F),试试在搜索栏输入ID选择符或者类选择符就可以定位到元素啦

调试过程注意事项

1.避免记录引用类型
当记录对象或数组时,永远记得你在记录什么。记录原始类型时,使用带断点的watch表达式。如果是异步代码,避免记录引用类型。

var arr = [{ num: 0 }];
setInterval(function(){
console.log(arr);
arr[0].num += 1;
}, 1000);

careful

这里,第一个属性中对象引用的值是不可靠的。当你第一次在开发者工具中显示这个属性时,num的值就已经确定了。之后无论你对同一个引用重新打开多少次都不会变化。

2.尽可能使用 source map。有时生产代码不能使用source map,但不管怎样,你都不应该直接对生产代码进行调试。

查看原文

Faremax 回答了问题 · 2018-12-15

nodeName/nodeValue 选取顺序问题

如下图,规范中 DOM 节点分为12类,第一列是type编号,你得代码中包括Element节点和Text节点。

很明显,不论换行空格还是文字都属于Text节点,通过element.childNode是可以获取包括这12类的所有节点,而我们通常习惯中说的DOM节点指的是Element节点(这么说其实并不严谨,只是大家的习惯说法)。所以通过element.childElementNodeelement.firstElementNode 获得的才是你想要的节点(对于你的代码来说就是span)

clipboard.png

关注 3 回答 3

Faremax 回答了问题 · 2018-12-15

iframe嵌套登录页 进行登录跳转chrome68 提示错误

登录跳转地址应该由外层页面传进iframe,并保证外层页面和跳转目标页面不跨域。

关注 2 回答 1

认证与成就

  • 获得 498 次点赞
  • 获得 8 枚徽章 获得 0 枚金徽章, 获得 0 枚银徽章, 获得 8 枚铜徽章

擅长技能
编辑

开源项目 & 著作
编辑

(゚∀゚ )
暂时没有

注册于 2017-01-24
个人主页被 855 人浏览