使用 vuex 的 mapState

在 vue 中:

<template>
  <div>
    {{user.name}}
  </div>
</template>

<script>
import {mapState} from 'vuex';

export default {
  computed: {
    ...mapState({
      user: state => state.user
    })
  }
}
</script>

在 store 中:

export default {
    state: {
        user: {}
    },
}

继续阅读

实现mysql自动备份的简单脚本

#!/bin/bash
#chmod 700 backup.sh
#crontab -e
#每天4点, mysql备份数据
#0 4 * * * /home/cron/mysql_backup.sh

host="localhost"
user="dbname"
password="dbname"
db_name="dbname"

#backup directory
base_dir="/home/backup"
backup_log="${base_dir}/mysql_backup.log"
backup_path=${base_dir}

#file info
date=$(date +"%Y-%m-%d")
filename=$backup_path/$db_name-$date.sql.gz

#back up
mkdir -p $backup_path
mysqldump --user=$user --password=$password --host=$host $db_name | gzip > $filename
#Delete files older than 10 days
find $backup_path/* -mtime +10 -exec rm {} \;
echo "backup finished at $(date +'%Y-%m-%d %H:%M:%S')" >> "$backup_log"

js删除数组里的某个元素

// Array Remove - By John Resig (MIT Licensed)
Array.prototype.remove = function(from, to) {
  var rest = this.slice((to || from) + 1 || this.length);
  this.length = from < 0 ? this.length + from : from;
  return this.push.apply(this, rest);
};
// 移除数组中的第二项
array.remove(1);
// 移除数组中的倒数第二项
array.remove(-2);
// 移除数组中的第二项和第三项(从第二项开始,删除2个元素)
array.remove(1,2);
// 移除数组中的最后一项和倒数第二项(数组中的最后两项)
array.remove(-2,-1);

来自 jQuery 之父的 stackoverflow

scss 使用 @font-face 引入 fonticon 字体报错

webpack 内置的路径检索在使用特定方式引入文件时,会出现无法加载字体的问题,例如以下方式:

vue
<style lang="scss" src="./path-to-file.scss"></style>

scss
@font-face {
  font-family: "iconfont";
  src: url('./iconfont/iconfont.eot?t=1501135137439'); /* IE9*/
  src: url('./iconfont/iconfont.eot?t=1501135137439#iefix') format('embedded-opentype'), /* IE6-IE8 */
  url('./iconfont/iconfont.woff?t=1501135137439') format('woff'), /* chrome, firefox */
  url('./iconfont/iconfont.ttf?t=1501135137439') format('truetype'), /* chrome, firefox, opera, Safari, Android, iOS 4.2+*/
  url('./iconfont/iconfont.svg?t=1501135137439#iconfont') format('svg'); /* iOS 4.1- */
}

下载的字体

如果是从 iconfont 下载的字体,将字体放到访问根目录下。

比如 laravel 的访问根目录是 /public,在里面创建字体目录,如 static/fonts/iconfont,将字体放在该目录下。

在 scss 文件中将路径改为绝对路径。如上面的例子,则可以写为:

@font-face {
  font-family: "iconfont";
  src: url('/static/fonts/iconfont/iconfont.eot?t=1501135137439'); /* IE9*/
  src: url('/static/fonts/iconfont/iconfont.eot?t=1501135137439#iefix') format('embedded-opentype'), /* IE6-IE8 */
  url('/static/fonts/iconfont/iconfont.woff?t=1501135137439') format('woff'), /* chrome, firefox */
  url('/static/fonts/iconfont/iconfont.ttf?t=1501135137439') format('truetype'), /* chrome, firefox, opera, Safari, Android, iOS 4.2+*/
  url('/static/fonts/iconfont/iconfont.svg?t=1501135137439#iconfont') format('svg'); /* iOS 4.1- */
}

其实就是不要 loader 自动寻找文件,而直接输出路径,我们只要事先准备好对应的文件即可。

fontawesome

加载 fontawesome 需要先定义 $fa-font-path 变量,如下:

$fa-font-path: "~font-awesome/fonts";
@import '~font-awesome/scss/font-awesome';

laravel 5.5 安装使用 passport

使用 Composer 安装 Passport :

composer require laravel/passport:~4.0

Laravel 5.6 已经发布,最新的 laravel/passport 版本为 5.0 适配 Laravel 5.6,所以我们需要使用 Laravel 5.5 的适配版本 4.0

如果安装过程中遇到 paragonie/random_compat 版本冲突的问题,可以先执行以下命令将其降级为 2.0 的版本。

composer require paragonie/random_compat:^2.0

继续阅读

faker 常见填充的类型

[
    // 个人信息  
    '姓名 name' => $faker->name,
    '姓 lastName' => $faker->lastName,
    '名 firstName' => $faker->firstName,
    '手机 mobile' => $faker->phoneNumber,
    '信用卡信息数组 creditCardDetails'=> $faker->creditCardDetails,

    // 地理位置  
    '纬度 latitude' =>$faker->latitude,
    '经度 longitude' =>$faker->longitude,
    '国家 country' => $faker->country,
    '国家代码 countryCode' => $faker->countryCode,
    '邮政编码:postcode'=> $faker->postcode,
    '地址 address' => $faker->address,
    '城市 city' => $faker->city,
    '省 state'=> $faker->state,
    '省简称 stateAbbr' =>$faker->stateAbbr,
    '区 area' => $faker->area,
    '街道 streetAddress' => $faker->streetAddress,
    '邮编 postcode' => $faker->postcode,

    // 公司,银行,广告语  
    '公司后缀 companySuffix'=> $faker->companySuffix,
    '公司 company'=> $faker->company,
    '银行 bank' => $faker->bank,
    '广告语 catchPhrase'=>$faker->catchPhrase,

    // 时间  
    'unixTime' => $faker->unixTime,
    'year' => $faker->year,
    'month' => $faker->month,
    'dayOfMonth'=> $faker->dayOfMonth,
    'date' =>$faker->date,
    'time' =>$faker->time,

    //互联网  
    'domainName' => $faker->domainName,
    'companyEmail' => $faker->companyEmail,
    'email' => $faker->email,
    'userName' => $faker->userName,
    'password' => $faker->password,
    'url' => $faker->url,
    'ipv4' => $faker->ipv4,
    'ipv6' => $faker->ipv6,
    'localIpv4' => $faker->localIpv4,
    'macAddress' => $faker->macAddress,
    'userAgent' => $faker->userAgent,

    // 杂项  
    '罗马数字century' => $faker->century,
    '颜色hexcolor' =>$faker->hexcolor,
    'mimeType'=>$faker->mimeType,
    '文件后缀fileExtension'=>$faker->fileExtension,
    'img' => $faker->image,
    'imgurl' => $faker->imageUrl,
    'uuid'   => $faker->uuid,
    'sha1' => $faker->sha1,
    'sha256' => $faker->sha256,
    'md5'=> $faker->md5,

    //文本内容  
    '单词 word' => $faker->word,
    '单词 words' => $faker->words ( 5, true ),
    '短标题 sentence' => $faker->sentence,
    '内容 content' => $faker->text ( 500 ) ,
    '内容 realText' => $faker->realText(100),
]

安装zabbix3.4

添加源

官方源:

https://blog.csdn.net/LeoForBest/article/details/80598191

# ubuntu 16.04
wget http://repo.zabbix.com/zabbix/3.4/ubuntu/pool/main/z/zabbix-release/zabbix-release_3.4-1+xenial_all.deb
dpkg -i zabbix-release_3.4-1+xenial_all.deb
apt update
# ubuntu 14.04
wget http://repo.zabbix.com/zabbix/3.4/ubuntu/pool/main/z/zabbix-release/zabbix-release_3.4-1+trusty_all.deb
dpkg -i zabbix-release_3.4-1+trusty_all.deb
apt update
# ubuntu 18.04
wget http://repo.zabbix.com/zabbix/3.4/ubuntu/pool/main/z/zabbix-release/zabbix-release_3.4-1+bionic_all.deb
dpkg -i zabbix-release_3.4-1+bionic_all.deb
apt update

继续阅读

Mysql彻底卸载重装

sudo apt-get purge mysql*
sudo apt-get autoremove
sudo apt-get autoclean
sudo rm -rf /var/log/mysql
sudo rm -rf /var/log/mysql.*
sudo rm -rf /var/lib/mysql
sudo apt-get install mysql-server --fix-missing --fix-broken

laravel使用php-redis和prefix防止redis键名冲突

首先需要安装 php-redis

apt install php-redis

config/database.php 中,修改 redisclientphpredis,并在 default 中添加 prefix => env('REDIS_PREFIX', ''),

最后在 .env 中配置 REDIS_PREFIX 即可实现隔离。

但是,直接使用 redis 要比使用 php-redis 效率更高。