作者归档:ning

IntelliJ/PhpStorm/PyCharm等启动报错Cannot Lock System Folders

解决办法

Disable hyper-v (which will required a couple of restarts)

dism.exe /Online /Disable-Feature:Microsoft-Hyper-V

When you finish all the required restarts, reserve the port you want so hyper-v doesn't reserve it back

netsh int ipv4 add excludedportrange protocol=tcp startport=50051  numberofports=1

Re-Enable hyper-V (which will require a couple of restart)

dism.exe /Online /Enable-Feature:Microsoft-Hyper-V /All

when your system is back, you will be able to bind to that port successfully.

参考

Windows Terminal通过ssh连接linux

打开 profiles.json 配置文件

打开Windows Terminal,点击设置,可以看到,复制增加一组ssh配置,然后修改三个地方。

{
// Make changes here to the powershell.exe profile.
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"name": "Windows PowerShell",
"commandline": "powershell.exe",
"hidden": false
},

修改guid

利用powershell可以生成guid

powershell -Command "[guid]::NewGuid().ToString()"

修改名字

任意,可以是系统名字,IP,用户名等,如 username@aliyun-bj

修改commandline

ssh -i C:\user\username\id_rsa username@aliyun-bj

其中i参数后面为证书存放位置,如果试用密码登录可以不填

修改其他项目(图标,配色等)

 {
     "acrylicOpacity" : 0.5,
     "closeOnExit" : true,
     "colorScheme" : "One Half Dark",
     "commandline" : "ssh username@aliyun-bj",
     "cursorColor" : "#FFFFFF",
     "cursorShape" : "bar",
     "fontFace" : "Consolas",
     "fontSize" : 14,
     "guid" : "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
     "historySize" : 9001,
     "icon" : "ms-appx:///ProfileIcons/{9acb9455-ca41-5af7-950f-6bca1bc9722f}.png",
     "name" : "username@aliyun-bj",
     "padding" : "0, 0, 0, 0",
     "snapOnInput" : true,
     "startingDirectory" : "",
     "useAcrylic" : false
 }

参考

付费、免费以及开源工单系统比较

比较了网易七鱼,创逸云客服,udesk,单小二,腾讯云智服,售后宝,以及国内开源产品。

收费软件大多是集成在客服、CRM中,存在接口不足、界面太重、价格过高的问题。开源项目都基本是没法用。而国外的对微信,钉钉支付不好。

目前看来售后宝比较符合需求。API调用10万次1000元。

file

nginx 非www跳www,www跳非www,http跳https

非www跳www

if ($host ~ ^(?!www\.)(?<domain>.+)$) {
    return  301 $scheme://www.$domain$request_uri;
}

www to non-www

if ($host ~ ^www\.(?<domain>.+)$) {
    return  301 $scheme://$domain$request_uri;
}

其他域名跳统一域名

if ($host != "example.com") {
    return  301 $scheme://example.com$request_uri;
}

http跳https

if ($scheme != "https") {
       return 301 https://$host$request_uri;
   } # managed by Certbot

参考

letsencrypt https证书增加OCSP Stapling解决iOS公众号H5首次打开慢问题

原因

最近收到反馈网站公众号H5打卡慢,发现都是iOS用户,最后搜了以下发现可能因为letsencrypt证书域名被污染,导致到国外验证证书慢,解决办法是开启OCSP Stapling本地服务器缓存。

nginx 日志可以看到

ocsp.int-x3.letsencrypt.org could not be resolved (110: Operation timed out)

检查证书是否已开启OCSP Stapling

openssl s_client -connect c4ys.com:443 -servername c4ys.com -status -tlsextdebug < /dev/null 2>&1 | grep "OCSP"

(nginx重启后需要运行两次,第二次才有结果)

如果结果是下面这样,说明 OCSP Stapling 已开启:

OCSP response:
OCSP Response Data:
    OCSP Response Status: successful (0x0)
    Response Type: Basic OCSP Response

而这样显然是未开启:

OCSP response: no response sent

开启ssl_stapling的两个条件

根据 nginx ssl_stapling 官方文档只需要两个条件即可:

  • 指定了resolver
  • 如果ssl_certificate没有包含中间商证书,则需要将中间证书包含在ssl_trusted_certificate中

letsencrypt certbot的ssl_certificate使用的是fullchain.pem,带了中间证书,所以只需要指定resolver即可。生成ssl_trusted_certificate和ssl_stapling_file的步骤不是必须的。

ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=60s ipv6=off;
resolver_timeout 5s;

查看当前域名的证书链

查看站点根证书,0,站点证书;1,中间证书,2,根证书

openssl s_client -connect c4ys.com:443 -servername c4ys.com -showcerts < /dev/null 2>&1

depth=2 O = Digital Signature Trust Co., CN = DST Root CA X3
verify return:1
depth=1 C = US, O = Let's Encrypt, CN = Let's Encrypt Authority X3
verify return:1
depth=0 CN = c4ys.com
verify return:1

下载根证书

letsencrypt 的证书链介绍和下载

其他证书下载

cd /etc/letsencrypt/live/c4ys.com/
wget https://letsencrypt.org/certs/trustid-x3-root.pem.txt
mv trustid-x3-root.pem.txt trustid-x3-root.pem

验证证书

openssl x509 -in cert.pem -noout -subject
openssl x509 -in chain.pem -noout -subject
openssl x509 -in trustid-x3-root.pem -noout -subject

生成ssl_trusted_certificate

cat cert.pem chain.pem  trustid-x3-root.pem > ca_bundled.pem

查看证书ocsp地址

查看证书签署,来自ocsp.int-x3.letsencrypt.org

openssl x509 -in cert.pem -noout -ocsp_uri

验证ocsp获取

openssl ocsp -no_nonce -text \
-issuer chain.pem \
-cert cert.pem \
-CAfile ca_bundled.pem \
-VAfile ca_bundled.pem \
-url http://ocsp.int-x3.letsencrypt.org/ \
-header "HOST" "ocsp.int-x3.letsencrypt.org"

发现超时,修改/etc/resolv.conf,服务器dns

nameserver 8.8.8.8

然后出现

Response verify OK
cert.pem: good

开启ssl_stapling

ssl_trusted_certificate /etc/letsencrypt/live/c4ys.com/ca_bundled.pem;

开启后可以通过前面的方法验证,第二次才有效

服务器缓存OSCP staplingresp(可选)

服务器可以将OSCP resp缓存起来,避免走国外下载

使用ssl_stapling_responder(方式一,推荐)

由于ssl_stapling_file需要手动更新,比较麻烦,所以通过http代理获取。
参考:https://jhuo.ca/post/ocsp-stapling-letsencrypt/

开启ssl_stapling_file(方式二,推荐)

ssl_stapling_file可以将oscp缓存起来,避免服务器下载

下载并保存 oscp resp

openssl ocsp -no_nonce -text \
-issuer chain.pem \
-cert cert.pem \
-CAfile ca_bundled.pem \
-VAfile ca_bundled.pem \
-url http://ocsp.int-x3.letsencrypt.org/ \
-header "HOST" "ocsp.int-x3.letsencrypt.org" \
-respout ocsp.resp

nginx启用ssl_stapling_file

ssl_stapling_file /etc/letsencrypt/live/c4ys.com/ocsp.resp;

自动更新ssl_stapling_file

oscp有效时间通常只有7天,所以需要使用脚本自动更新缓存,参考:https://quchao.com/entry/how-to-configure-ocsp-stapling-on-nginx-for-the-certificates-issued-by-lets-encrypt/

参考

族谱的数据设计

需求分析

  • 族谱有一个特点就是写入少,所以可以建立一个缓存表。
  • 维护关系尽量简单
  • 查询上下几代尽量快速,避免递归

数据库结构

people 表

id 
name 姓名

relation 表

id
family_id 族号 一个用户可能存在多个族谱中,比如外嫁后进入其他族谱
people_id 用户编号
level 代系
relate_people_id 关联人,
type 关系:如丈夫,妻子,儿子,孙子,情人
order 第几个孩子,第几任妻子

索引

alter table relation create index family_level(family_id,level);

查询(高性能将上下三代查出来)

select * from relation where family_id=3 and level between current_level-3,current_level+3;

分析

这两个表记录基本不用改(除非录错了),任何时候都是增加记录即可,所以维护也非常简单。

界面展示上,查询出上下几代,然后名字作为主要展示标签,关系用连线展示,关系和人是多对多,完美解决关系混乱的问题。

level 代表是族谱里面的第几代。

如果发现了新的祖先,然么当然自己代数要加一。

比如李渊原来 level 是 1 代,然后认了老子做祖宗,那么他就不 1 代了,老子是 1 代。

族谱草图

file

参考

让Windows支持通过ide://open和phpstorm://open打开phpstorm

C:\Program Files下新建PhpStorm Protocol (Win)文件夹,包含以下两个文件。
修改run_editor.reg后,点击运行即可。

run_editor.reg

REGEDIT4

[HKEY_CLASSES_ROOT\phpstorm]
@="URL:phpstorm Protocol"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\phpstorm\shell\open\command]
@="wscript \"C:\\Program Files\\PhpStorm Protocol (Win)\\run_editor.js\" \"%1\" //E:JScript"

[HKEY_CLASSES_ROOT\ide]
@="URL:ide Protocol"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\ide\shell\open\command]
@="wscript \"C:\\Program Files\\PhpStorm Protocol (Win)\\run_editor.js\" \"%1\" //E:JScript"

run_editor.js

var settings = {
    // flag to active Jetbrain Toolbox configuration
    toolBoxActive: false,

    // Set to 'true' (without quotes) if run on Windows 64bit. Set to 'false' (without quotes) otherwise.
    x64: true,

    // Set to folder name, where PhpStorm was installed to (e.g. 'PhpStorm')
    folder_name: 'PhpStorm 2018.3.1',

    // Set to window title (only text after dash sign), that you see, when switching to running PhpStorm instance
    window_title: 'PhpStorm',

    // In case your file is mapped via a network share and paths do not match.
    // eg. /var/www will can replaced with Y:/
    projects_basepath: '',
    projects_path_alias: ''
};

// don't change anything below this line, unless you know what you're doing
var url = WScript.Arguments(0),
    match = /^phpstorm|ide:\/\/open\/?\?(url=file:\/\/|file=)(.+)&line=(\d+)$/.exec(url),
    project = '',
    editor = '"C:\\' + ( settings.x64 ? 'Program Files' : 'Program Files (x86)' ) + '\\JetBrains\\' + settings.folder_name + ( settings.x64 ? '\\bin\\phpstorm64.exe' : '\\bin\\phpstorm.exe' ) + '"';

if (settings.toolBoxActive) {
    configureToolboxSettings(settings);
}

// WScript.Echo(editor);
// WScript.Echo(url);

if (match) {

    var shell = new ActiveXObject('WScript.Shell'),
        file_system = new ActiveXObject('Scripting.FileSystemObject'),
        file = decodeURIComponent(match[ 2 ]).replace(/\+/g, ' '),
        search_path = file.replace(/\//g, '\\');

    if (settings.projects_basepath !== '' && settings.projects_path_alias !== '') {
        file = file.replace(new RegExp('^' + settings.projects_basepath), settings.projects_path_alias);
    }

    while (search_path.lastIndexOf('\\') !== -1) {
        search_path = search_path.substring(0, search_path.lastIndexOf('\\'));

        if (file_system.FileExists(search_path + '\\.idea\\.name')) {
            project = search_path;
            break;
        }
    }

    if (project !== '') {
        editor += ' "%project%"';
    }

    editor += ' --line %line% "%file%"';

    var command = editor.replace(/%line%/g, match[ 3 ])
        .replace(/%file%/g, file)
        .replace(/%project%/g, project)
        .replace(/\//g, '\\');

    shell.Exec(command);
    shell.AppActivate(settings.window_title);
}

function configureToolboxSettings(settings) {
    var shell = new ActiveXObject('WScript.Shell'),
        appDataLocal = shell.ExpandEnvironmentStrings("%localappdata%"),
        toolboxDirectory = appDataLocal + '\\JetBrains\\Toolbox\\apps\\PhpStorm\\ch-0\\';

    // Reference the FileSystemObject
    var fso = new ActiveXObject('Scripting.FileSystemObject');

    // Reference the Text directory
    var folder = fso.GetFolder(toolboxDirectory);

    // Reference the File collection of the Text directory
    var fileCollection = folder.SubFolders;

    var maxMajor = 0,
        maxMinor = 0,
        maxPatch = 0,
        maxVersionFolder = "";
    // Traverse through the fileCollection using the FOR loop
    // read the maximum version from toolbox filesystem
    for (var objEnum = new Enumerator(fileCollection); !objEnum.atEnd(); objEnum.moveNext()) {
        var folderObject = ( objEnum.item() );
        if (folderObject.Name.lastIndexOf('plugins') === -1) {
            var versionMatch = /(\d+)\.(\d+)\.(\d+)/.exec(folderObject.Name),
                major = parseInt(versionMatch[ 1 ]),
                minor = parseInt(versionMatch[ 2 ]),
                patch = parseInt(versionMatch[ 3 ]);
            if (maxMajor === 0 || maxMajor <= major) {
                maxMajor = major;
                if (maxMinor === 0 || maxMinor <= minor) {
                    maxMinor = minor;
                    if (maxPatch === 0 || maxPatch <= patch) {
                        maxPatch = patch;
                        maxVersionFolder = folderObject.Name;
                    }
                }
            }
        }
    }

    settings.folder_name = maxVersionFolder;

    // read version name and product name from product-info.json
    var versionFile = fso.OpenTextFile(toolboxDirectory + settings.folder_name + "\\product-info.json", 1, true);
    var content = versionFile.ReadAll();

    eval('var productVersion = ' + content + ';');
    settings.window_title = 'PhpStorm ' + productVersion.version;
    editor = '"' + toolboxDirectory + settings.folder_name + '\\' + productVersion.launch[ 0 ].launcherPath.replace(/\//g, '\\') + '"';
}

参考

Win10下好用的看图软件

Win10上有哪些好用的图片查看软件呢?发现知乎和掘金上面一堆推荐,选了一圈之后,发现很多可能是广告。最终选择XnView MP与FastStone Image Viewer,因为他们界面美观,且支持收藏夹功能,速度相对较快。

FastStone Image Viewer

FastStone Image Viewer是Microsoft Windows的图像查看器和管理器,从7.0版开始免费提供,供个人和教育使用。该程序还包括基本的图像编辑工具。

速度快,有收藏夹

下载地址

XnView MP

XnView为一款支持图片浏览、转换和编辑的多平台软件。该软件支持改变用户界面语言以及自定义工具栏按钮与面板。它支持读取超过500种的图像文件格式及部分音频文件格式及视频文件格式,亦支持写入50种图帧式。提供免费的个人使用及简易操作。

定制性强,有收藏夹

下载地址

Win10原生预览

WIN10中打开文件夹中文件预览功能

https://jingyan.baidu.com/article/a501d80c1c81aaec630f5e92.html

win10图片不能预览怎么办 如何显示缩略图

https://jingyan.baidu.com/article/2a138328eb0448074a134f9c.html

Mysql update select同一张表

根据下级状态更新上级状态

原来语句

SET display = 1
WHERE
    id IN (
        SELECT
            a.pid
        FROM
            area a
        WHERE
            a.display = 1
        AND pid != 0
    );

提示:[Err] 1093 - You can't specify target table 'area' for update in FROM clause

修改后

UPDATE area a1,(
        SELECT
            pid
        FROM
            area
        WHERE
            display = 1
        AND pid != 0
    ) a2
SET a1.display = 1
where a1.id=a2.pid;