Zan's Home

Good Good Study, Day Day Up!


  • 首页

  • 归档

.net core发布单文件并优化大小

发表于 2022-04-27 | 分类于 C#

命令

1
dotnet publish -r win-x64 -c Release --self-contained /p:PublishSingleFile=true /p:PublishTrimmed=true

-r win-x64: 架构
-c Release: Release模式
–self-contained: 自包含
/p:PublishSingleFile=true: 单文件
/p:PublishTrimmed=true: 裁剪优化

通过NVM安装Node(MacOS)

发表于 2019-12-11 | 更新于 2021-02-19 | 分类于 node

卸载系统中已安装的Node

1
2
3
4
5
# Homebrew安装的情形
brew uninstall node

# 官网下载pkg安装的情形
sudo rm -rf /usr/local/{bin/{node,npm},lib/node_modules/npm,lib/node,share/man/*/node.*}

安装NVM

1
2
3
4
5
# 通过下载网络脚本安装
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash

# 加载环境变量
source ~/.bashrc

修改源

1
2
3
4
5
6
7
8
9
# 打开环境变量文件
vim ~/.bash_profile

# 添加如下内容
export NVM_NODEJS_ORG_MIRROR=http://npm.taobao.org/mirrors/node
export NVM_IOJS_ORG_MIRROR=http://npm.taobao.org/mirrors/iojs

# 重新加载环境变量
source ~/.bash_profile

安装

1
2
3
4
5
# 查看可安装的Node版本
nvm ls-remote

# 安装指定版本的Node
nvm install [v10.16.3]

使用

1
2
3
4
5
6
7
8
9
# 查看已经安装的Node版本
nvm ls

# 切换Node版本
nvm use [12.11.0]

# 查看Node/npm版本
node -v
npm -v

通过NVM安装Node(Windows)

发表于 2019-12-10 | 更新于 2021-02-19 | 分类于 node

安装NVM

  1. 卸载之前安装的Nodejs
  2. 下载nvm-windows
  3. 不要安装在有空格的文件夹中

修改源

1
2
nvm node_mirror https://npm.taobao.org/mirrors/node/
nvm npm_mirror https://npm.taobao.org/mirrors/npm/

安装

1
2
3
4
5
# 显示可安装Node版本列表
nvm ls available

# 安装指定版本的Node
nvm install [12.10.0]

使用

1
2
3
4
5
6
7
8
# 查看已安装的Node
nvm ls

# 切换Node版本
nvm use [12.10.0]

# 查看node版本
node -v

使用Numpy实现与运算感知器

发表于 2019-10-12 | 更新于 2021-02-19 | 分类于 ml , python

背景说明

参考PHP实现感知器

实现代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import numpy as np

data = np.array([
[1, 1, 1],
[1, 0, 0],
[0, 1, 0],
[0, 0, 0],
], dtype=np.int)
bias = np.ones((4, 1))
data = np.concatenate((bias, data), 1) # 偏置值作为输入


def predict(x, w):
"""
预测结果
"""
x = x.reshape(x.shape[0], 1) # 输入
w = w.reshape(1, w.shape[0]) # 权重
return 1 if w.dot(x)[0][0] > 0 else 0


rate = 0.009 # 学习率
weight = np.zeros(data.shape[1] - 1) # 初始权重

for _ in range(10):
for _, item in enumerate(data):
t = item[-1] # Label
d = item[0: -1] # Data
weight = weight + rate * (t - predict(d, weight)) * d

print(weight)

关闭Windows Defender

发表于 2019-09-11 | 更新于 2021-02-19 | 分类于 tools

参考地址:如何彻底关闭或删除Windows Defender

  1. 管理员身份打开终端
  2. 运行如下命令:
    1
    reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows Defender" /v "DisableAntiSpyware" /d 1 /t REG_DWORD /f

Let's Encrypt签发通配SSL证书

发表于 2019-08-27 | 更新于 2021-02-19 | 分类于 tools , linux

文中命令在ubuntu 18.04中完成验证,使用root用户

安装基础环境

1
2
apt update
curl https://get.acme.sh | sh

签发证书

此处域名解析使用DNSPod,故从DNSPod获得ApiToken进行操作,其它DNS解析服务商按照对应要求执行命令

DNSPod ApiToken获取:
https://www.dnspod.cn(用户中心 > 安全设置 > API Token)

设置环境变量:

1
2
3
export DP_Id="11****"
export DP_Key="c9a9********e46eb"
source ~/.bashrc

执行签发命令:

1
acme.sh --issue --dns dns_dp -d wg.xiidev.com -d *.wg.xiidev.com --reloadcmd "systemctl force-reload nginx" # -d 后面表示对应域名(可以指定多个域名及通配域名)

Nginx配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
server {
listen 80;
server_name agent.wg.xiidev.com;
return 301 https://$host$request_uri;
}

server {
listen 443 ssl;
listen [::]:443 ssl;
ssl_certificate /root/.acme.sh/wg.xiidev.com/fullchain.cer;
ssl_certificate_key /root/.acme.sh/wg.xiidev.com/wg.xiidev.com.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!aNULL";
ssl_prefer_server_ciphers on;
server_name agent.wg.xiidev.com;

location / {
proxy_set_header Host $http_host;
proxy_read_timeout 10;
proxy_pass http://agent.wg:8000/;
}
}

LaTeX中插入EPS图片

发表于 2019-06-14 | 更新于 2021-02-19 | 分类于 tools
1
2
3
4
5
6
7
8
9
10
11
12
13
\documentclass[lang=cn,device=normal,11pt]{elegantbook}
% 导言区
\usepackage{graphicx}
\usepackage{epstopdf}

\begin{document}
% 内容区
\begin{figure}
\centering
\includegraphics{path/to/file.eps}
\caption{EPS图片说明}
\end{figure}
\end{document}

PHP实现感知器

发表于 2019-04-09 | 更新于 2021-02-19 | 分类于 php , ml

什么是感知器

https://en.wikipedia.org/wiki/Perceptron
https://baike.baidu.com/item/感知器/16525448

基础公式

  1. 模型函数: $y = \sum\limits_{i=1}^mw_{i}x_{i} + b$ (w:权重; x:输入; b:偏置值)

  2. 训练规则: $\begin{cases}\ w_{i} = w_{i} + \eta(t-y)x_{i} \\\ b = b + \eta(t-y)\end{cases}$ ($\eta$:学习率; $t$:训练样本希望输出; $y$:感知器实际输出)

实现代码

  1. 感知器类

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    class Perceptron
    {
    /**
    * @var callable 激活函数
    */
    private static $activator = null;

    /**
    * @var double 偏置量
    */
    private static $bias = 0.0;

    /**
    * @var array 权重向量
    */
    private static $weights = [];

    /**
    * 构造函数
    * @param int $featureNums 感知器输入参数个数
    * @param callable 激活函数(double->double)
    */
    public function __construct($featureNums, $activator)
    {
    self::$activator = $activator;
    self::$bias = 0.0;
    self::$weights = array_fill(0, $featureNums, 0.0);
    }

    /**
    * 使用感知器预测结果
    * @param array 输入向量
    */
    public function predict($inputVector)
    {
    $activator = self::$activator;
    $sum = 0.0;
    foreach ($inputVector as $k => $v) {
    $sum += $v * self::$weights[$k];
    }
    $sum += self::$bias;
    return $activator($sum);
    }

    /**
    * 训练感知器
    * @param array 输入向量
    * @param array 输入向量对应的标签
    * @param int 迭代次数
    * @param float 学习率
    */
    public function train($inputVectors, $labels, $iterationNum, $learnRate)
    {
    for ($i = 0; $i < $iterationNum; $i++) {
    foreach ($inputVectors as $k => $vector) {
    $output = $this->predict($vector);
    $delta = $labels[$k] - $output;
    foreach ($vector as $p => $item) {
    self::$weights[$p] += $learnRate * $delta * $item;
    }
    self::$bias += $learnRate * $delta;
    }
    }
    }
    }
  2. 使用感知器类训练and操作

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    $activator = function($x) {
    return $x > 0 ? 1 : 0;
    }; // 定义激活函数
    $perceptron = new Perceptron(2, $activator); // and操作只有两个特征值
    $dataset = [[0, 0], [0, 1], [1, 0], [1, 1]]; // 训练集
    $labels = [0, 0, 0, 1]; // 训练集对应的labels
    $iterationNum = 10; // 迭代次数
    $learnRate = 0.011; // 学习率
    $perceptron->train($dataset, $labels, $iterationNum, $learnRate); // 用样本训练模型
    var_dump($perceptron->predict([0, 0])); // 使用训练好的样本预测数据

ECC加密算法利用私钥算出公钥

发表于 2019-04-08 | 更新于 2021-02-19 | 分类于 algorithm

问题描述

已知ECC的私钥内容,如下:

1
MHQCAQEEIIEkuYgeJcJR2P1cwdG8cY3kwj/3YiU+XwQd2uEgCyoooAcGBSuBBAAKoUQDQgAEVzHUGgk4iVYbdwiWudUf30+bP3cj7a4w2Tbl6jdfduprDTwj5nmxNziK7AcMDQcETf+gLjqkHK+JRMHzFGYouA==

使用PHP代码推算出对应的公钥。

计算过程

下面代码需要php版本7.1以上

  1. 转换ECC私钥内容为PEM格式

    1
    2
    3
    4
    5
    $private = 'MHQCAQEEIIEku...FGYouA=='; // ECC私钥内容
    $startLine = "-----BEGIN EC PRIVATE KEY-----\n"; // PEM起始行
    $endLine = "\n-----END EC PRIVATE KEY-----"; // PEM结束行
    $privKey = $startLine . implode("\n", str_split($private, 64)) . $endLine; // 内容每64个字符一行
    $privRes = openssl_pkey_get_private($privKey); // 转换私钥内容为资源
  2. 转换私钥资源到CSR

    1
    2
    3
    4
    5
    6
    $dn = [];
    $config = [
    'private_key_type' => OPENSSL_KEYTYPE_EC,
    'curve_name' => 'secp256k1', // 私钥生成时使用secp256k1曲线生成(需要设置与私钥生成对应的曲线)
    ];
    $csr = openssl_csr_new($dn, $privRes, $config);
  3. 从CSR中获取公钥

    1
    $pubKey = openssl_pkey_get_details(openssl_csr_get_public_key($csr))['key']; // 得到PEM格式的公钥内容
  4. 从PEM格式的公钥中获取字符串内容

    1
    2
    3
    4
    5
    6
    $replace = [
    '-----BEGIN PUBLIC KEY-----',
    '-----END PUBLIC KEY-----',
    "\n",
    ];
    $ripePublic = trim(str_replace($replace, '', $public)); // 得到处理后的公钥内容

Linux查看Zombie(僵尸)程序

发表于 2019-03-22 | 更新于 2021-02-19 | 分类于 linux
1
ps -A -ostat,ppid,pid,cmd | grep -e '^[Zz]'
12

xiaozan (i#xiaozan.me)

15 日志
12 分类
19 标签
© 2018 – 2022 xiaozan (i#xiaozan.me)
由 Hexo 强力驱动
|
主题 – NexT.Mist