叶测试 发布的文章

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>

phpword添加批注注释信息

$phpWord = \PhpOffice\PhpWord\IOFactory::load("/test/test1.docx");

//创建注释
$comment= new \PhpOffice\PhpWord\Element\Comment('森森', new \DateTime(), 'my_initials');
$comment->addText('这是批注的信息内容', array('bold' => false, 'color'=>'ff0000'));

//添加到注释
$phpWord->addComment($comment);

$section = $phpWord->getSection(0);

//创建文本并添加注释
$textrun = $section->addTextRun();
$textrun->addText('这里需要进行');
$text = $textrun->addText('注释');
//将注释链接到刚创建的文本上
$text->setCommentRangeStart($comment);
//也可以为注释设置起始位置
//$comment->setStartElement($text);

//原始文本添加注释

//导出注释版
$phpWord->save("/test/test2.docx");

1111.png