分类 默认分类 下的文章

申请软著或知识产权用的。主要统计代码行数和合并所有代码文件到一个文件,打印前后各30页这个需要自己打开合并后的文件去打印。

<?php

$output = 'print.txt';
$dir = 'app';

$list = scanFiles('app');
$info = mergeFiles($output, $list);
echo '文件总数:' . count($list) . '个' . PHP_EOL;
echo '代码总量:' . $info['content length'] . '字' . PHP_EOL;
echo '代码行数:' . $info['line total'] . '行' . PHP_EOL;

/**
 * 扫描指定目录下的所有文件
 * @param string $path 要扫描的目录
 * @param string $regex 文件名规则(正则)
 * @return array
 */
function scanFiles($path, $regex = '\.(php|html)$')
{
    $list = [];
    foreach (scandir($path) as $item) {
        if ('.' === $item || '..' === $item) continue;
        if (is_dir($path . '/' . $item)) {
            $list = array_merge($list, scanFiles($path . '/' . $item));
        } elseif (is_file($path . '/' . $item)) {
            if (!preg_match('@' . $regex . '@', $item)) continue;
            $list[] = $path . '/' . $item;
        }
    }

    return $list;
}

/**
 * 合并数组中的所有文件
 * @param string $output 合并后的内容的输出路径
 * @param array $list 要合并的文件列表
 * @return array
 */
function mergeFiles($output, $list)
{
    $file = fopen($output, 'w+');
    $length = 0;
    $line = 0;
    foreach ($list as $item) {
        $itemRes = fopen($item, 'r');
        $findEnd = false;
        while(!feof($itemRes))
        {
            $itemLine = fgets($itemRes);
            if ($findEnd) {
                if (false !== strpos($itemLine, '*/')) {
                    $findEnd = false;
                }
                continue;
            }

            if (preg_match('@^\s*//@', $itemLine)) {
                continue;
            } elseif (preg_match('@^\s*$@', $itemLine)) {
                continue;
            } elseif (preg_match('@\s*/\*.*\*/\s*@', $itemLine)) {
                continue;
            } elseif (false !== strpos($itemLine, '/*')) {
                $findEnd = true;
                continue;
            } else {
                $line++;
                $length += fwrite($file, $itemLine);
            }
        }
        fclose($itemRes);
    }
    fclose($file);
    return ['content length' => $length, 'line total' => $line];
}

执行效果

# php print.php
文件总数:317个
代码总量:1808293字
代码行数:41856行

fork 仓库后同步上游仓库的修改,个人总结了两种方法,个人感觉第一种适合仓库所有者使用,第二种适合仓库贡献者使用。

方法一

拉取上游更新

git fetch upstream

检出代码

git checkout -b master upstream/master

合并代码

会产生一条 Merge remote-tracking branch 'upstream/master'记录
git merge upstream/master

推送到github

git push origin master

方法二

拉取上游更新

git fetch upstream

检出代码

远程仓库的代码和提交记录会强制覆盖本地
git checkout -B master upstream/master

推送到github

强制推送到 github
git push -f origin master

其它命令

查看所有分支和当前所处分支

git branch -a

拉取仓库更新

git fetch origin
git fetch upstream

每次要在电脑上启动v2ray还是挺不方便的,直接在路由器运行,这样局域网的设备都能直接使用,方便很多。

更新opkg源

opkg update
Downloading http://downloads.pangubox.com:6380/pandorabox/19.02/targets/ralink/mt7621/packages/Packages.gz
Updated list of available packages in /var/opkg-lists/19.02_core
Downloading http://downloads.pangubox.com:6380/pandorabox/19.02/packages/mipsel_1004kc_dsp/base/Packages.gz
Updated list of available packages in /var/opkg-lists/19.02_base
Downloading http://downloads.pangubox.com:6380/pandorabox/19.02/packages/mipsel_1004kc_dsp/newifi/Packages.gz
Updated list of available packages in /var/opkg-lists/19.02_newifi
Downloading http://downloads.pangubox.com:6380/pandorabox/19.02/packages/mipsel_1004kc_dsp/pear/Packages.gz
Updated list of available packages in /var/opkg-lists/19.02_pear
Downloading http://downloads.pangubox.com:6380/pandorabox/19.02/packages/mipsel_1004kc_dsp/packages/Packages.gz
Updated list of available packages in /var/opkg-lists/19.02_packages
Downloading http://downloads.pangubox.com:6380/pandorabox/19.02/packages/mipsel_1004kc_dsp/luci/Packages.gz
Updated list of available packages in /var/opkg-lists/19.02_luci
Downloading http://downloads.pangubox.com:6380/pandorabox/19.02/packages/mipsel_1004kc_dsp/lafite/Packages.gz
Updated list of available packages in /var/opkg-lists/19.02_lafite
Downloading http://downloads.pangubox.com:6380/pandorabox/19.02/packages/mipsel_1004kc_dsp/mtkdrv/Packages.gz
Updated list of available packages in /var/opkg-lists/19.02_mtkdrv

安装unzip

opkg install unzip
Installing unzip (6.0-2) to root...
Downloading http://downloads.pangubox.com:6380/pandorabox/19.02/packages/mipsel_1004kc_dsp/packages/unzip_6.0-2_mipsel_1004kc_dsp.ipk
Configuring unzip.

安装ssl ca证书

opkg install wget ca-certificates openssl-util ca-bundle
Package wget (1.18-2) installed in root is up to date.
Installing ca-certificates (20160104) to root...
Downloading http://downloads.pangubox.com:6380/pandorabox/19.02/packages/mipsel_1004kc_dsp/base/ca-certificates_20160104_all.ipk
Installing openssl-util (1.0.2o-1) to root...
Downloading http://downloads.pangubox.com:6380/pandorabox/19.02/packages/mipsel_1004kc_dsp/base/openssl-util_1.0.2o-1_mipsel_1004kc_dsp.ipk
Installing ca-bundle (20160104) to root...
Downloading http://downloads.pangubox.com:6380/pandorabox/19.02/packages/mipsel_1004kc_dsp/base/ca-bundle_20160104_all.ipk
Configuring openssl-util.
Configuring ca-certificates.
Configuring ca-bundle.

下载v2ray

wget https://github.com/v2ray/v2ray-core/releases/download/v4.23.1/v2ray-linux-mipsle.zip

解压v2ray

unzip v2ray-linux-mipsle.zip
Archive:  v2ray-linux-mipsle.zip
  inflating: config.json
   creating: doc/
  inflating: doc/readme.md
  inflating: geoip.dat
  inflating: geosite.dat
   creating: systemd/
  inflating: systemd/v2ray.service
   creating: systemv/
  inflating: systemv/v2ray
  inflating: v2ctl
 extracting: v2ctl.sig
  inflating: v2ctl_softfloat
 extracting: v2ctl_softfloat.sig
  inflating: v2ray
 extracting: v2ray.sig
  inflating: v2ray_softfloat
 extracting: v2ray_softfloat.sig
  inflating: vpoint_socks_vmess.json
  inflating: vpoint_vmess_freedom.json

配置v2ray

省略,跟linux或windows端一样配置

运行v2ray

./v2ray
V2Ray 4.23.1 (V2Fly, a community-driven edition of V2Ray.) Custom (go1.13 linux/mipsle)
A unified platform for anti-censorship.
2020/04/11 13:35:08 Using default config:  /mnt/sda1/v2ray/config.json
2020/04/11 13:35:11 [Info] v2ray.com/core/common/platform/ctlcmd: <v2ctl message>
v2ctl> Read config:  /mnt/sda1/v2ray/config.json
2020/04/11 13:35:12 [Warning] v2ray.com/core: V2Ray 4.23.1 started

写入启动项

系统 - 启动项 - 本地启动脚本

# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.

/mnt/sda1/v2ray/v2ray >/dev/null 2>&1 &

exit 0

如果没配置URL重写规则的情况下,每次访问都要加上index.php,看起来是没这么美观和方便的。
例如:http://test.ll00.cn/index.php/index/test/hello
本文主要记录Apache、Nginx和IIS配置。

Apache配置

站点配置:

<VirtualHost *:80>
    # 将PHP可以访问的文件限制到指定的目录树(http://php.net/manual/zh/ini.core.php#ini.open-basedir)
    # 配置这个主要是有些环境默认把open_basedir设置为DocumentRoot,导致thinkphp无法正常使用
    # 不是所有环境都这样,所有看情况配置
    php_admin_value open_basedir "/home/wwwroot/www.ll00.cn:/tmp/:/var/tmp/:/proc/"
    DocumentRoot "/home/wwwroot/www.ll00.cn/public"
    ServerName www.ll00.cn
    <Directory "/home/wwwroot/www.ll00.cn">
        SetOutputFilter DEFLATE
        Options FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
        DirectoryIndex index.html index.php
    </Directory>
</VirtualHost>

.htaccess配置:

需要Apache加载mod_rewrite.so模块,并且将AllowOverride配置项设置为All,例如AllowOverride All
框架安装后,默认提供一个.htaccess文件,里面就写好了重写规则,一般都是安装即用。
可以说,Apache是对thinkphp框架支持最好的了!

<IfModule mod_rewrite.c>
    Options +FollowSymlinks -Multiviews
    RewriteEngine on

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]
</IfModule>

Nginx

站点配置

server
{
    listen 80;
    server_name www.ll00.cn;
    index index.php index.html index.htm default.php default.htm default.html;
    # 站点目录
    root /www/wwwroot/www.ll00.cn/public;
    
    # URL重写规则
    location / {
        if (!-e $request_filename){
            rewrite  ^(.*)$  /index.php?s=$1  last;   break;
        }
    }
}

IIS

IIS这个了解不大多,只是简单的尝试了下,后面坑太多,放弃了。

web.Config文件配置:

在IIS的高版本下面可以配置下面的URL重写规则,如果不行,再试试其它方式。
主要是rewrite节点的配置,如果配置文件已有其它配置,将rewrite节点的配置放在system.webServer内的最后面即可。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="OrgPage" stopProcessing="true">
                    <match url="^(.*)$" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{HTTP_HOST}" pattern="^(.*)$" />
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php/{R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

https://www.iis.net/downloads/microsoft/url-rewrite