叶测试 发布的文章

PHP获取指定N个工作日后日期

<?php
// 制定允许其他域名访问
header('Access-Control-Allow-Origin:*');
// 响应类型
header('Access-Control-Allow-Methods:*');
//请求头
header('Access-Control-Allow-Headers:*');
// 响应头设置
header('Access-Control-Allow-Credentials:false');

//节假日 需要手动维护配置文件或者放入db中
$holiday=['2019-01-01', '2019-01-05', '2019-01-06', '2019-01-12', '2019-01-13', '2019-01-19', '2019-01-20', '2019-01-26', '2019-01-27', '2019-02-04', '2019-02-05', '2019-02-06', '2019-02-07', '2019-02-08', '2019-02-09', '2019-02-10', '2019-02-16', '2019-02-17', '2019-02-23', '2019-02-24', '2019-03-02', '2019-03-03', '2019-03-09', '2019-03-10', '2019-03-16', '2019-03-17', '2019-03-23', '2019-03-24', '2019-03-30', '2019-03-31', '2019-04-05', '2019-04-06', '2019-04-07', '2019-04-13', '2019-04-14', '2019-04-20', '2019-04-21', '2019-04-27', '2019-05-01', '2019-05-02', '2019-05-03', '2019-05-04', '2019-05-11', '2019-05-12', '2019-05-18', '2019-05-19', '2019-05-25', '2019-05-26', '2019-06-01', '2019-06-02', '2019-06-07', '2019-06-08', '2019-06-09', '2019-06-15', '2019-06-16', '2019-06-22', '2019-06-23', '2019-06-29', '2019-06-30', '2019-07-06', '2019-07-07', '2019-07-13', '2019-07-14', '2019-07-20', '2019-07-21', '2019-07-27', '2019-07-28', '2019-08-03', '2019-08-04', '2019-08-10', '2019-08-11', '2019-08-17', '2019-08-18', '2019-08-24', '2019-08-25', '2019-08-31', '2019-09-01', '2019-09-07', '2019-09-08', '2019-09-13', '2019-09-14', '2019-09-15', '2019-09-21', '2019-09-22', '2019-09-28', '2019-10-01', '2019-10-02', '2019-10-03', '2019-10-04', '2019-10-05', '2019-10-06', '2019-10-07', '2019-10-13', '2019-10-19', '2019-10-20', '2019-10-26', '2019-10-27', '2019-11-02', '2019-11-03', '2019-11-09', '2019-11-10', '2019-11-16', '2019-11-17', '2019-11-23', '2019-11-24', '2019-11-30', '2019-12-01', '2019-12-07', '2019-12-08', '2019-12-14', '2019-12-15', '2019-12-21', '2019-12-22', '2019-12-28', '2019-12-29'];

function afterWorkDay($start_timestamp='',$add_workday_num='',$holiday=[]){
    //实际工作时间数组
    $workday=array();
    $i=0;
    //判断实际工作时间数组的长度
    while(count($workday)<intval($add_workday_num)){
        $i++;
        $onewdate=date('Y-m-d',($start_timestamp)+$i*(60*60*24));
        //非节假日添加实际工作时间数组
        if(!in_array($onewdate,$holiday)){
            $workday[]=$onewdate;
        }
    }
    return date('Y-m-d',($start_timestamp)+$i*(60*60*24));
}

$day = $_GET['day'];
$date = $_GET['date'];
$day = (int)$day - 1;
$start_time=strtotime($date);
//计算N个工作日后的时间 $N-1对应共N天
echo afterWorkDay($start_time,$day,$holiday);

PHP获取法定节假日接口

<?php
// 过慢,暂不使用 http://api.goseek.cn/Tools/holiday?date=20201002
// 正常工作日对应结果为 0, 法定节假日对应结果为 1, 节假日调休补班对应的结果为 2,休息日对应结果为 3
// 使用:http://tool.bitefu.net/jiari/?d=
// 工作日对应结果为 0, 休息日对应结果为 1, 节假日对应的结果为 2
$arr=[];
$start=strtotime('20191028');
for ($i=0; $i < 100; $i++) { 
    $now = $start+86400*$i;
    $day = date('Ymd', $now);
    $res = https_request("http://tool.bitefu.net/jiari/?d=".$day);
    if($res==1||$res==2){
        file_put_contents('holiday.txt', $day.PHP_EOL, FILE_APPEND);
    }
    usleep(300);
}

function https_request($url, $data = null){
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($curl, CURLOPT_TIMEOUT,6);
    if (!empty($data)){
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    }
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($curl);
    curl_close($curl);
    return $output;
}

mysql表中依据一个字段更新另一个字段

判断字段是否存在值,如果不存在则写入本行中另一个字段值。
update table_name set new_column= case when (new_column=0) then old_column else new_column end
即:如new_column不存在值则更新为old_column

.gitignore忽略已提交的文件

对于首次提交时,会忽略.gitignore中对应的文件。如果已提交再次修改.gitignore则不会忽略,仍会追踪文件变化。

解决:
git rm --cached folder/file 并修改.gitignore文件

另:
git update-index --assume-unchanged 的真正用法是这样的:

  1. 你正在修改一个巨大的文件,你先对其 git update-index --assume-unchanged,这样 Git
    暂时不会理睬你对文件做的修改
  2. 当你的工作告一段落决定可以提交的时候,重置改标识:git update-index
    --no-assume-unchanged,于是 Git 只需要做一次更新,这是完全可以接受的了
  3. 提交+推送

原文:https://segmentfault.com/q/1010000000430426

shell判断文件、文件夹是否存在

dir="/folder"
file="/test/test.txt"
file2="/test/test.php"

判断文件夹是否存在,不存在则创建
if [ ! -d "${dir}" ]; then
    mkdir -p ${dir}
fi

判断文件是否存在且可执行
if [ ! -x "${dir}"]; then
    mkdir "${dir}"
fi

判断文件是否存在
if [ ! -f "$file" ]; then
    touch "$file"
fi

判断变量是否有值
if [ ! -n "$file" ]; then
 echo "$file 变量为空!"
 exit 0
fi

判断两个变量的字符串内容是否相同
if [ "$file" = "$file2" ]; then
    echo "$file equal $file2"
else
    echo "$file not equal $file2"
fi

shell脚本批量检测mysql表中是否存在指定字段

批量查询数据库中表是否存在指定字段,批量添加表字段:

#!/bin/bash
#exit
db_con="/usr/local/mysql/bin/mysql -uroot -p123456"
arr=(db1 db2 db3)
for db in ${arr[*]}
do
    ${db_con} -e "select count(*) from information_schema.columns where table_schema = '${db}' and table_name = 'table_name' and column_name = 'column_name';"  >> /data/shell/test.txt
    echo ${db} >> /data/shell/test.txt 
    #${db_con} -e "ALTER TABLE ${db}.gy_com_customer ADD new_column varchar(100) NOT NULL default '';" 2>/dev/null
    echo ${db} " --- done"
done

apache同时配置80和443端口 the first has precedence, perhaps you need a NameVirtualHost directive

同时添加:
NameVirtualHost *:80
NameVirtualHost *:443

<VirtualHost *:443>
    DocumentRoot "/www/hitortoise"
    ServerName www.r1989.com

    SSLEngine on
    SSLCertificateFile /www/ssl/2_www.r1989.com.crt
    SSLCertificateKeyFile /www/ssl/3_www.r1989.com.key
    SSLCertificateChainFile /www/ssl/1_root_bundle.crt
</VirtualHost>

<VirtualHost *:80>
     DocumentRoot "/www/hitortoise"
     ServerName www.r1989.com

     RewriteEngine on
     RewriteCond %{HTTP_HOST} ^www.r1989.com$
     RewriteRule ^/(.*)$ https://www.r1989.com/$1 [R=301,L]
</VirtualHost>