Giter Site home page Giter Site logo

daily-code's Introduction

daily-code

  • 日常工作代码笔记
  • 详情请见Issues

daily-code's People

Contributors

fourtwothree avatar

Stargazers

 avatar

Watchers

 avatar  avatar

daily-code's Issues

Linux命令帮助解释

在查看命令幫助時,會出現[],<>,|等符號,它們的含義如下:

[] 表示是可選的;

<> 表示是可變化的;

x|y|z 表示隻能選擇一個;

-abc 表示三個參數(或任何二個)的混合使用

laravel模型事件触发条件

laravel模型事件触发必须要获取模型实例,eg:

$user = User::find(1);
$user->delete();

以上代码可触发deleted事件
以下代码不可触发deleted事件:

User::where('id', 1)->delete();

Linux more命令

more命令是一个基于vi编辑器文本过滤器,它以全屏幕的方式按页显示文本文件的内容,支持vi中的关键字定位操作。more名单中内置了若干快捷键,常用的有H(获得帮助信息),Enter(向下翻滚一行),空格(向下滚动一屏),Q(退出命令)。

该命令一次显示一屏文本,满屏后停下来,并且在屏幕的底部出现一个提示信息,给出至今己显示的该文件的百分比:--More--(XX%)可以用下列不同的方法对提示做出回答:

按Space键:显示文本的下一屏内容。
按Enier键:只显示文本的下一行内容。
按斜线符|:接着输入一个模式,可以在文本中寻找下一个相匹配的模式。
按H键:显示帮助屏,该屏上有相关的帮助信息。
按B键:显示上一屏内容。
按Q键:退出rnore命令。

如何查看linux系统是32位还是64位?

$ uname -a
 Linux ubuntu 3.11.0-12-generic #19-Ubuntu SMP Wed Oct 9 16:12:00 UTC 2013 i686 athlon i686 GNU/Linux
$ uname -m
 i686

i686 (or 有时候会是i386) 说明操作系统是32位的,但是如果显示的是 x86_64,那就说明这个操作系统是64位的。

Nginx相关配置

nginx.conf

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;


# Settings for a TLS enabled server.
#
 #   server {
  #      listen       80;
#        listen       [::]:443 ssl http2 default_server;
#        server_name  localhost:80;
#        root         /usr/share/nginx/html;
#
#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_ciphers HIGH:!aNULL:!MD5;
#        ssl_prefer_server_ciphers on;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        location / {
#	  root /var/www/html/vue/dist
#	  index.html index
 #       }
#
#        error_page 404 /404.html;
#            location = /40x.html {
#        }
#
#        error_page 500 502 503 504 /50x.html;
#            location = /50x.html {
#        }
#    }

}

laravel.conf

server {
    listen     60;
    root /var/www/html/kuaijibao/public;
    index index.php;
    server_name  127.0.0.1;
    access_log     /var/log/nginx/nginx.vhost.access.log;
    error_log      /var/log/nginx/nginx.vhost.error.log;
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_script_name;
        include        fastcgi_params;
    }
}

CentOS上安装微软雅黑字体

fc-list

查看linux系统已安装字体,若无该命令,需要先安装相关的软件包

yum install -y fontconfig mkfontscale

查看系统中已经安装的中文字体

fc-list :lang=zh

如无中文字体

cp msyh.ttf /usr/share/fonts/
mkfontscale
mkfontdir
fc-cache

可用fc-list :lang=zh查看,字体已安装成功

JS日期格式与时间戳相互转换

var date = new Date('2018-06-08 18:00:00');
    // 有三种方式获取
    var time1 = date.getTime();
    var time2 = date.valueOf();
    var time3 = Date.parse(date);
    console.log(time1);//1528452000000
    console.log(time2);//1528452000000
    console.log(time3);//1528452000000
--------------------- 

作者:calmlc
来源:CSDN
原文:https://blog.csdn.net/Lc_style/article/details/80626748
版权声明:本文为博主原创文章,转载请附上博文链接!

Laravel Attribute Casting

The $casts property on your model provides a convenient method of converting attributes to common data types. The $casts property should be an array where the key is the name of the attribute being cast and the value is the type you wish to cast the column to. The supported cast types are: integer, real, float, double, string, boolean, object, array, collection, date, datetime, and timestamp.

解决laravel-dompdf中文乱码

首先 download load_font.php, 改掉以下两行

// require_once "autoload.inc.php";
require_once "vendor/autoload.php";

//$fontDir = "lib/fonts";
$fontDir = "storage/fonts";

找到你想要的字型 ChineseFontName.ttf, 上传 load_font.php 和 ChineseFontName.ttf 到你 Laravel 的项目根目录(非public目录),在你的 Laravel/storage 底下新增一個 fonts文件夹(storage/fonts),进入项目根目录执行

php load_font.php "Font Name" ChineseFontName.ttf

会把想要的字型的信息 load 到 dompdf 中,并把 ChineseFontName.ttf copy 到 storage/fonts 底下。
在你的 dompdf view 中加上

body {
    font-family: "Font Name";
}

即可正确输出中文了~

阿里云Centos服务器部署laravel项目

1.移除已有PHP及其扩展

yum remove php*

2.yum安装PHP7及其扩展、Mysql、php-fpm

yum install php70w php70w-opcache php70w-fpm php70w-mysql php70w-mbstring 

注意:mysql 和 mysqlnd 会冲突,选择其一安装
3.yum 安装nginx

yum install nginx

4.yum 安装git

yum install git

5.git 拉取项目代码

git clone 地址
  1. 配置nginx 、启动php-fpm、重启nginx
systemctl start php-fpm.service
nginx -s reload

查看nginx是否启动

ps -A | grep nginx

7.yum 安装redis,并修改redis配置daemonize (守护进和)为yes

yum install redis

8.yum安装composer,并更新

yum install composer
composer update

9.新建laravel配置.env并修改
10.修改storage文件夹权限

chmod -R 777 storage

group by mysql5.7 不支持 sql_mode里不要有ONLY_FULL_GROUP_BY

    public static function getDataDictionariesByIDs($category_ids)
    {
        $data = DataDictionary::whereIn('data_category_id', $category_ids)->get();
        $qb = DataDictionary::whereIn('data_category_id', $category_ids)
            ->selectRaw(
                '
                    ANY_VALUE(id) as id,
                    ANY_VALUE(data_category_id) as data_category_id,
                    ANY_VALUE(data_category_name) as data_category_name,
                    ANY_VALUE(value_id) as value_id,
                    ANY_VALUE(value) as value,
                    ANY_VALUE(status) as status,
                    ANY_VALUE(note) as note
                '
            )
            ->groupBy('data_category_id');

        return $qb;
    }

Determining If An Input Value Is Present

You should use the has method to determine if a value is present on the request. The has method returns true if the value is present on the request:

if ($request->has('name')) {
    //
}

PHP 安装mongodb

sudo pecl install mongodb

Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script.

brew install autoconf

Finally, add the following line to your php.ini file:

extension=mongodb.so

单点登录

比对登录获取到的token,和存在服务器缓存里的token是否匹配

git checkout -- file

命令git checkout -- readme.txt意思就是,把readme.txt文件在工作区的修改全部撤销,这里有两种情况:
一种是readme.txt自修改后还没有被放到暂存区,现在,撤销修改就回到和版本库一模一样的状态;
一种是readme.txt已经添加到暂存区后,又作了修改,现在,撤销修改就回到添加到暂存区后的状态。
总之,就是让这个文件回到最近一次git commit或git add时的状态。

PHP获取两个时间点之间所有的月份?

    private function getMonthArr($time1, $time2)
    {
        $time1 = strtotime($time1); //
        $time2 = strtotime($time2);

        $monthArr = array();
        $monthArr[] = date('Y-m', $time1); // 当前月;
        while(($time1 = strtotime('+1 month', $time1)) <= $time2){
            $monthArr[] = date('Y-m',$time1); // 取得递增月;
        }

        return $monthArr;
    }

Homebrew install php72-mongodb

All formulas in homebrew/php has been deleted or moved to homebrew/core.

To avoid installation problem in homebrew, you can use the command below:

brew tap kyslik/php
brew install phpXX-mongodb

如何知道正在使用的是哪一个PHP及其路径?

which php - will locate the php executable (this should be the default php used by you)

If you want to find out the php version, then php -v will print the php version in the CLI and any Zend modules installed.

php -v  
PHP 5.6.30 (cli) (built: Mar 11 2017 09:56:27)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

If you want to find out the ini files included then php --ini will display th list of ini files loaded by the php module (this applies for the CLI version).

php --ini
Configuration File (php.ini) Path: /usr/local/etc/php/5.6
Loaded Configuration File:         /usr/local/etc/php/5.6/php.ini
Scan for additional .ini files in: /usr/local/etc/php/5.6/conf.d
Additional .ini files parsed:      /usr/local/etc/php/5.6/conf.d/ext-xdebug.ini

CentOS7下将PHP和mysql命令加入到环境变量中

修改/etc/profile文件使其永久性生效,并对所有系统用户生效,在文件末尾加上如下两行代码

PATH=$PATH:/usr/local/php/bin:/usr/local/mysql/bin
export PATH

执行 命令source /etc/profile或 执行点命令 ./profile使其修改生效,执行完可通过echo $PATH命令查看是否添加成功。

关联查询必须要select id(关联键),才能将关联关系查询出来,否则为空

$qb = self::selectRaw
('
businesses.id as businesses_id, 
businesses.name as businesses_name, 
businesses.full_name, 
businesses.designation, 
businesses.type as business_type, 
businesses.audit_status, 
business_contacts.name as business_contacts_name, 
business_contacts.type as business_contacts_type, 
business_contacts.phone
')
                    ->Search($conditions)
                    ->leftJoin('customers', 'businesses.customer_id', '=', 'customers.id')
                    ->leftJoin('business_contacts', 'businesses.customer_id', '=', 'business_contacts.customer_id');

VirtualBox虚拟机Centos7指定固定IP, Shell远程连接

1.设置虚拟机使用“桥接模式”

2.使用 vi /etc/sysconfig/network-scripts/ifcfg-enp0s3 打开配置文件(其中 enp0s3 是你的linux的网卡名,在shell中 使用 ip addr 命令自行查看自己的名称并将此处的改成自己的,紧跟数字的后面那个参数就是,不是ol那个)

修改以下参数

将 BOOTPROUTE="dhcp" 改为 BOOTPROUTE="static"
将 ONBOOT="no" 改为 ONBOOT="yes"

然后添加如下参数(位置随意)

IPADDR="192.168.0.150"(注意:因为使用“桥接模式”所以此处的 ip 地址一定要和宿主机在一个网段,设置时先看一下宿主机的ip)

NETMASK="255.255.255.0"
NM_CONTROLLED="no"

3.关闭防火墙并使防火墙开启 22 端口

 sudo firewall-cmd --zone=public --add-port=22/tcp --permanent

4.重新开启防火墙

 sudo systemctl restart firewalld.service

5.重启网络服务

sudo systemctl restart network.service

6.重启系统

右击 centos7 -> 重启

7.打开xshell客户端

输入ip 192.168.0.150 连接即可,配置完成

常犯错误

1.修改完参数后没有重启网络服务及虚拟机
2.没有设置防火墙开放 22 端口


使用xshell远程连接设置完成后发现 xshell 终端可以远程连接虚拟机了 但是ping 不通外网 ,原因很简单,就是因为没有设置好虚拟机的“网关”和“域名”这两个因素
解决:

1.打开配置文件   # vi /etc/resolv.conf
写入以下配置项
    nameserver="8.8.8.8"    #(Google的公共DNS服务)
    nameserver="8.8.4.4"    #(Google的公共DNS服务)
2.打开配置文件 vi /etc/sysconfig/network-scripts/ifcfg-enp0s3  配置 网关 和 dns
写入以下配置项
   GATEWAY="10.0.70.1"(这个要写成自己机器上的)
   DNS1="8.8.8.8" # (Google公共DNS以下相同)
   DNS2="8.8.4.4" 
3.保存后记得重启网络服务
sudo systemctl restart network.service
4.重启虚拟机(不进行重启不会生效,非常重要),完成配置

CentOS上安装wkhtmltopdf

先查看linux系统是64位还是32位

uname -m
x86_64(64位)

选取64位下载地址

wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
unxz wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
tar -xvf wkhtmltox-0.12.4_linux-generic-amd64.tar
mv wkhtmltox/bin/* /usr/local/bin/
rm -rf wkhtmltox
rm -f wkhtmltox-0.12.4_linux-generic-amd64.tar

---- or ----

yum install -y libpng
yum install -y libjpeg
yum install -y openssl
yum install -y icu
yum install -y libX11
yum install -y libXext
yum install -y libXrender
yum install -y xorg-x11-fonts-Type1
yum install -y xorg-x11-fonts-75dpi

wget https://bitbucket.org/wkhtmltopdf/wkhtmltopdf/downloads/wkhtmltox-0.13.0-alpha-7b36694_linux-centos7-amd64.rpm

rpm -Uvh wkhtmltox-0.13.0-alpha-7b36694_linux-centos7-amd64.rpm

错误1:

unxz wkhtmltox-0.12.4_linux-generic-amd64.tar.xz                                                  /var/www/html/kuaijibao
unxz: wkhtmltox-0.12.4_linux-generic-amd64.tar.xz: Unexpected end of input

ll查看发现wkhtmltox-0.12.4_linux-generic-amd64.tar.xz文件大小只有68k,远小于14M,文件包未下载完全,重新下载后成功解压

错误2:

wkhtmltopdf                                                                                                           /usr/local/bin
wkhtmltopdf: error while loading shared libraries: libXrender.so.1: cannot open shared object file: No such file or directory

安装libXrender,yum install libXrender

错误3:

wkhtmltopdf                                                                                                           /usr/local/bin
wkhtmltopdf: error while loading shared libraries: libXext.so.6: cannot open shared object file: No such file or directory

安装libXext, yum install libXext

至此,wkhtmltopdf安装成功

PHP下安装memcached扩展包

brew install memcached
brew install libmemcached
brew services start memcached
telnet localhost 11211

下载php-memcached扩展包:https://pecl.php.net/package/memcached
下载之后解压memcached-3.0.4.tgz,进入memcached-3.0.4文件夹执行命令:

phpize

执行完成后会生成一个可执行的configure文件,执行它:

./configure --with-php-config=/usr/local/Cellar/php70/7.0.27_19/bin/php-config

说明:/usr/local/Cellar/php70/7.0.27_19/为php的安装路径,需要根据你安装的实际目录进行调整
注意:在执行过程中可能会出现一些错误,原因是服务器可能缺少一些依赖的包,这些只需要根据报错信息安装那些依赖包即可。

执行完成后安装并编译:

make && make install

安装完成后生成一个memcached.so文件,记住路径:/usr/local/Cellar/php70/7.0.27_19/lib/php/extensions/no-debug-non-zts-20151012/

修改php.ini,进入/usr/local/etc/php/7.0,

vim php.ini

修改配置如下:

extension_dir = "/usr/local/Cellar/php70/7.0.27_19/lib/php/extensions/no-debug-non-zts-20151012/"
extension = memcached.so

重启php,
php -m
查看是否安装成功

Nginx Error

nginx: [error] open() "/usr/local/var/run/nginx.pid" failed (2: No such file or directory)

sudo nginx

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.