Homebrew
Homebrew 中的一些概念及配置国内镜像源方法。
安装 Homebrew
执行以下命令,脚本会提示选择国内几个比较常用的镜像,选择中科大镜像然后一路安装即可。
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
# Set Homebrew-bottles mirror
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles
IPv4/IPv6 网络
DNS
- DoH: DNS over Https
- DoT: DNS over TLS
公共 DNS 服务
DNS 服务器 | IPv4 | IPv6 | DoH | DoT |
---|---|---|---|---|
DNSPod Public DNS | 129.29.29.29 | 2402:4e00:: | https://doh.pub/dns-query | dot.pub |
阿里云 Public DNS | 223.5.5.5 | 2400:3200::1 | dns.alidns.com | dns.alidns.com |
Cloudflare DNS | 1.1.1.1 |
需要注意,DNS 能否够解析 IPv6 地址和 DNS 本身是否使用 IPv6 地址没有关系。即是说,只要 DNS 支持 IPv6 地址解析,那么访问 IPv4 的 DNS 也可以得到 IPv6 的地址。
Nginx
安装 Nginx
RHEL/CentOS
Install prerequisites
sudo yum install yum-utils
Set up the yum repository
vim /etc/yum.repos.d/nginx.repo
使用 Git LFS 存储二进制文件
Git LFS 简介
Git LFS 是由 Atlassian, GitHub 和其他开源贡献者开发的 Git 扩展,目的是减少大文件对 Git 仓库的影响,其以一种偷懒的方式下载相关版本的文件。具体来讲,就是只有在执行 checkout
命令时才会下载文件,而 clone
或 fetch
均不会下载文件。
Git LFS 通过将仓库中的大文件替换为一个 指针文件 来达到这一目的。
设置 Nodejs 环境
支持向量机(Support Vector Machine)
SVM 的决策边界(Decision Boundary)
其目标是找到一个线性函数 $\theta^Tx$,可以将样本集中的正类和负类分隔开,当 $\theta^Tx \ge 0$ 时表示正类,当 $\theta^Tx \lt 0$ 时表示负类,而 $\theta^Tx = 0$ 所代表的直线则是区分正负类的决策边界。
机器学习 - 相关概念的总结
概念解释
-
假设函数(Hypothesis Function): 用来拟合数据集,有线性函数和非线性函数。
-
正向传播(Forward Propagation): 用来计算假设函数的输出值 $h_\theta(x)$(即 $\hat{y}$)。
-
代价函数(Cost Function): 用来检验假设函数的输出值 $\hat{y}$ 与真实值 $y$ 之间的误差大小。
-
反向传播(Backpropagation): 用来计算代价函数 $J(\theta)$ 关于参数 $\theta$ 的偏导数 $\dfrac{\partial}{\partial \theta}J(\theta)$。
-
优化算法(Optimization Method): 使用参数 $\theta$ 最小化代价函数 $J(\theta)$。
机器学习 - 反向传播
反向传播(Backpropagation)
反向传播是通过计算假设函数与真实值之间的误差值($error = h_\theta(x^{(i)}) - y^{(i)}$),并反向传播这个误差值,最终用于计算参数 $\theta_{ij}$ 的偏导数。支撑这一理论的核心思想是多元复合函数的链式求导,下面通过一个简单的例子进行描述。
机器学习 - 各类函数的求导
线性函数 $z$ 对参数 $\theta_j$ 求导
线性函数 $z$:
\[z = \theta_0x_0 + \theta_1x_1 + \dots + \theta_jx_j\]其关于 $\theta_j$ 的导数:
\[\begin{aligned} \dfrac{\partial z}{\partial\theta_j} &= \dfrac{\partial}{\partial\theta_j}(\theta_0x_0) + \dfrac{\partial}{\partial\theta_j}(\theta_1x_1) + \dots + \dfrac{\partial}{\partial\theta_j}(\theta_jx_j) \\ &= 0 + 0 + \dots + x_j \\ &= x_j \end{aligned}\]机器学习 - 线性回归、逻辑回归与正则化
基本概念
假设函数 (Hypothesis Function): 根据输入的特征来预测输出结果。它是从输入变量到输出变量的函数,从输入特征空间到输出标签空间的映射,通常表示为 $h_\theta(x)$。在有监督学习中,这个函数通常是由训练数据中学习得到的,这就是为什么要叫 机器学习,所有训练出来的权重参数,都是用来逼进这个函数,我们希望通过这个学习出来的假设函数,可以从新的数据预测出想要的结果。
损失函数 (Loss Function):描述的是单个训练样本的预测值与真实值之间的误差。损失函数是关于单一训练样本的函数,它度量了一个样本的预测值与实际值的差异。例如,在回归任务中常用的损失函数是平方损失函数 $L(\theta)=(h_\theta(x)-y)^2$,其中是 $h_\theta(x)$ 预测值, $y$ 是真实值。
线性回归(Linear Regression)
假设函数(Hypothesis Function): 线性函数
\[h_\theta(x) = \theta_1x_1 + \theta_2x_2 + \cdots + \theta_nx_n + b = [\theta_1 \ \theta_2 \ \dots \ \theta_n] \begin{bmatrix} x_1 \\ x_2 \\ \vdots \\ x_n \end{bmatrix} + b = \theta^Tx+b \text{ (单个样本)}\] \[h_\theta(x) = \begin{bmatrix} h_\theta(x^{(1)}) \\ h_\theta(x^{(2)}) \\ \vdots \\ h_\theta(x^{(m)}) \end{bmatrix} = \begin{bmatrix} \theta_1x^{(1)}_1 + \theta_2x^{(1)}_2 + \dots + \theta_nx^{(1)}_n + b \\ \theta_1x^{(2)}_1 + \theta_2x^{(2)}_2 + \dots + \theta_nx^{(2)}_n + b \\ \vdots \\ \theta_1x^{(m)}_1 + \theta_2x^{(m)}_2 + \dots + \theta_nx^{(m)}_n + b \\ \end{bmatrix} = \begin{bmatrix} x^{(1)}_1 \ x^{(1)}_2 \ \dots \ x^{(1)}_n \\ x^{(2)}_1 \ x^{(2)}_2 \ \dots \ x^{(2)}_n \\ \vdots \\ x^{(m)}_1 \ x^{(m)}_2 \ \dots \ x^{(m)}_n \\ \end{bmatrix} \begin{bmatrix} \theta_1 \\ \theta_2 \\ \vdots \\ \theta_n \end{bmatrix} + \begin{bmatrix} b \\ b \\ \vdots \\ b \end{bmatrix} = X\theta + b \text{ (多个样本)}\]Docker
安装及升级 docker
RedHat/CentOS
安装仓库文件
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
安装 docker
sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
升级 docker 版本
sudo yum update 'docker-ce*'
docker system
管理 docker 系统
# 检查 docker 占用的系统空间
docker system df
# 显示 docker 系统信息
docker system info
# 删除无用的容器,网络,镜像等
docker system prune
机器学习 - 梯度下降
梯度下降(gradient descent)
定义代价函数(define a cost function)
平方代价函数(quadratic cost function)或均方误差(mean squared error or MSE)
\[C(w, b) = \frac{1}{2n}\sum_x\| y(x) - \hat{y}(x) \|^2 \tag{1}\label{eq1}\]其中,$w$ 代表网络中的全部权重值,$b$ 代表全部偏差值,$n$ 代表训练样本的总数,$\hat{y}(x)$ 是输入训练样本 $x$ 时网络的输出值,当然,$\hat{y}$ 同时依赖于 $w,b和x$,$y(x)$ 是训练样本 $x$ 对应的实际值。我们可以从平方代价函数看出两个特点:
- $C(w,b)$ 是一个非负数,因为它的每一项都是非负的。
- 当 $C(w,b)$ 变得越小,例如 $C(w,b)\approx 0$ 时,则输出值 $\hat{y}$ 越接近实际值 $y$。
所以,我们训练算法的目的就是找到合适的权重值($w$)和偏差值($b$),使得代价函数 $C(w,b)$ 尽可能的小。
SSH Tips
不重启 ssh 服务并加载新的配置
After updated /etc/ssh/sshd_config
, using below command to reload the sshd_config
without restart sshd daemon service.
systemctl reload sshd
# 或
sudo kill -SIGHUP $(pgrep -f "sshd -D")
SSH 免密登录设置
chmod 755 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
SSH 通过私钥生成公钥
ssh-keygen -y -f id_rsa > id_rsa.pub
生成 sshd 所需 host keys
启动 sshd
服务时如果没有 host keys,会报如下错误
sshd: no hostkeys available -- exiting.
执行以下命令生成所需的 host keys
ssh-keygen -A
SSH known host update
TARGET_HOST=[hostname or IP]
# Remove the old key(s) from known_hosts
ssh-keygen -R $TARGET_HOST
# Add the new key(s) to known_hosts (and also hash the hostname/address)
ssh-keyscan -H $TARGET_HOST >> ~/.ssh/known_hosts
OpenSSH Port Forwarding
以下端口转发命令都可以加上 -f
、-N
和 -T
选项,-f
表示让 ssh 进入后台执行命令,-N
表示不执行远程命令,-T
表示不分配终端。
-f
Requests ssh to go to background just before command execution. This is useful if ssh is going to ask for passwords or passphrases, but the user wants it in the background. This implies -n. The recommended way to start X11 programs at a remote site is with something like ssh -f host xterm.
-N
Do not execute a remote command. This is useful for just forwarding ports.
-T
Disable pseudo-terminal allocation.
-C
选项可以对所有转发数据进行压缩,如果转发数据大部分是文本数据,会提高转发效率,如果是二进制数据,则会降低转发效率。
See:
Groovy 语法总结
Groovysh 相关配置
Variables
Shell 变量是无类型的,即不是 def
类型也不是任何其它类型
下面定义了一个 Shell 变量
foo = "bar"
但是下面一行定义了一个本地变量,并且不会保存到 shell 环境中
def foo = "bar"
可以通过设置 :set interpreterMode
来定义有类型的变量(def
或其它类型)
OpenSSH Config
客户端配置文件 SSH_CONFIG
参考手册页了解详细内容
man 5 ssh_config
配置文件段
客户端配置文件可以划分成段,每个段包含一个或一组主机的设置。OpenSSH 以 Host
关键字开始一个新段,后面跟的字符串称为主机规范 (Host Specification)。主机规范可以是以下几种类型:
OpenSSL 常用命令
OpenSSL 简介
OpenSSL 是一个实现了 传输层安全 (Transport Layer Security, TLS v1) 网络协议和相关加密标准的加密工具箱.
openssl
是在 shell 中使用 OpenSSL 加密库中各种加密函数的命令行工具.
pyenv - Python 版本管理工具
安装 pyenv 和 pyenv-virtualenv 插件
brew update
brew install pyenv
brew install pyenv-virtualenv
Chef 学习笔记
登录 Chef Server 下载 Starter Kit
- 打开 Chef hosted 官网 注册并登录
- 在 chef server 中创建新的组织
- 选择组织并下载并解压 Starter Kit
在 Windows 系统上安装64位 Vim
- 下载 vim x64 的 zip 包
- 创建文件夹
C:\Program Files\Vim\vimxx
(xx 为 vim 版本,如 8.1 版本就是 vim81),将解压的文件复制到该文件夹
计算机代数系统(CAS) - SymPy
SymPy
是一个用来处理数学符号的 Python 库,一个计算机代数系统(Computer Algebra System, CAS)。
两个在线版本的 SymPy:
Vim 使用技巧
使用折叠
查看 :h fold.txt
手册了解 Vim 中的折叠功能。
折叠方式
Vim 的 foldmethod
有以下 6 种折叠方式
foldmethod | value | description |
---|---|---|
fold-manual | manual | 手动建立折叠。 |
fold-indent | indent | 相同缩进距离的行构成折叠。 |
fold-expr | expr | ‘foldexpr’ 给出每行的折叠级别。 |
fold-marker | marker | 标志用于指定折叠。 |
fold-syntax | syntax | 语法高亮项目指定折叠。 |
fold-diff | diff | 没有改变的文本构成折叠。 |
比如: 为 json 文本创建折叠
set ft=json
syntax on
set fdm=syntax
查看 :h 'fold-methods'
, :h 'foldmethod'
了解折叠方式的详细说明。
Windows 下创建目录链接
在 Windows 下如果通过右键菜单->创建快捷方式
生成的文件或文件夹,其实是生成了一个后辍为.lnk 的文件,在其它程序里面是不会引用到原文件或文件夹的,如果通过mklink
命令来创建快捷方式(符号链接),则其它程序会认为这就是一个真正的文件或文件夹。
Linux Commands Summary
Linux 在线手册
- 1: User commands; man-pages includes a very few Section 1 pages that document programs supplied by the GNU C library.
- 2: System calls documents the system calls provided by the Linux kernel.
- 3: Library functions documents the functions provided by the standard C library.
- 4: Devices documents details of various devices, most of which reside in
/dev
. - 5: Files describes various file formats, and includes proc(5), which documents the
/proc
file system. - 7: Overviews, conventions, and miscellaneous.
- 8: Superuser and system administration commands; man-pages includes a very few Section 8 pages that document programs supplied by the GNU C library.
Linux datetime
Unix timestamp
Unix timestamp 又称为 Unix time, POSIX time。是指从 Unix epoch 1970年1月1日 00:00:00 UTC+00:00 时刻开始,到现在经过的总秒数。一般可通过命令 date +%s
来获得。
时区
Time Zone Abbreviations – Worldwide List
-
UTC (Coordinated Universal Time)
协调世界时,是个标准时间。 -
GMT (Greenwich Mean Time)
格林威治时间,是时区时间。
Bash Colors
ANSI escape code
Bash 中使用 echo
输出颜色代码的格式
代码 | 说明 |
---|---|
\003[ or \e |
颜色起始修饰符 |
STYLE;COLORm | 样式 + ; + 颜色代码 + m |
\003[0m or \e[0m |
重置为无颜色 |
例如:
echo -e "\e[0;31mText\e[0m"
# Color Variables
NC='\003[0m'
Red='\003[0;31m'
echo -e "${Red}Text${NC}"
Iptables
Have a try
查看 nat
表中所有链上的规则
iptables -t nat -L
The following parameters make up a rule specification (as used in the add, delete, insert, replace and append commands).
-
-p, --protocol
[!] protocolProtocol can be one of tcp, udp, icmp, or all. A protocol name from
/etc/protocols
is also allowed. A “!” argument before the protocol inverts the test. The number zero is equivalent to all. Protocol all will match with all protocols and is taken as default when this option is omitted. -
-j, --jump
targetThe target can be a user-defined chain (other than the one this rule is in), one of the special builtin targets which decide the fate of the packet immediately, or an extension.
-
-i, --in-interface
[!] nameName of an interface via which a packet was received (only for packets entering the INPUT, FORWARD and PREROUTING chains). When the “!” argument is used before the interface name, the sense is inverted. If the interface name ends in a “+”, then any interface which begins with this name will match. If this option is omitted, any interface name will match.
-
-o, --out-interface
[!] nameName of an interface via which a packet is going to be sent (for packets entering the FORWARD, OUTPUT and POSTROUTING chains). When the “!” argument is used before the interface name, the sense is inverted. If the interface name ends in a “+”, then any interface which begins with this name will match. If this option is omitted, any interface name will match.
Linux File System
EXT4
Ext4是第四代扩展文件系统的缩写,它是2008年推出的。它是一个真正可靠的文件系统,它几乎在过去几年的大部分发行版中一直是默认选项,它是由比较老的代码生成的。它是一个日志文件系统,意味着它会对文件在磁盘中的位置以及任何其它对磁盘的更改做记录。如果系统崩溃,得益于journal技术,文件系统很少会损坏。
最大单个文件大小可以从16 GB到16 TB 最大文件系统大小为1EB(exabyte) 最大值包含64,000个子目录(ext3中的32,000个)
关系型数据库管理系统 (RDBMS)
第三章 SQL
3.3 SQL查询的基本结构
3.3.2 多关系查询(SQL查询的通用形式)
select
子句,from
子句,where
子句。每种子句作用如下:
select
子句用于列出查询结果中所需要的属性from
子句是需要访问的关系列表where
子句是一个作用在from
子句中关系的属性上的谓词
共计 111 篇文章,3 页。