主页

Homebrew

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 的地址。

阅读更多

使用 Git LFS 存储二进制文件

Git LFS 简介

Git LFS 是由 Atlassian, GitHub 和其他开源贡献者开发的 Git 扩展,目的是减少大文件对 Git 仓库的影响,其以一种偷懒的方式下载相关版本的文件。具体来讲,就是只有在执行 checkout 命令时才会下载文件,而 clonefetch 均不会下载文件。

Git LFS 通过将仓库中的大文件替换为一个 指针文件 来达到这一目的。

阅读更多

设置 Nodejs 环境

Linux 系统下手工安装 Nodejs

从官方下载 Nodejs 安装包

解压安装包到 /usr/local/lib/nodejs

VERSION=v10.16.0
DISTRO=linux-x64
sudo mkdir -p /usr/local/lib/nodejs
sudo tar -xvJf node-$VERSION-$DISTRO.tar.xz -C /usr/local/lib/nodejs

阅读更多

支持向量机(Support Vector Machine)

SVM 的决策边界(Decision Boundary)

其目标是找到一个线性函数 $\theta^Tx$,可以将样本集中的正类和负类分隔开,当 $\theta^Tx \ge 0$ 时表示正类,当 $\theta^Tx \lt 0$ 时表示负类,而 $\theta^Tx = 0$ 所代表的直线则是区分正负类的决策边界。

阅读更多

线性代数 (Linear Algebra)

一、线性方程组

行初等变换

  1. 倍加变换:把某一行的倍数加到另一行上。
  2. 对换变换:把两行对换。
  3. 倍乘变换:把某一行的所有元素乘以同一个非零数。

阅读更多

机器学习 - 相关概念的总结

概念解释

  • 假设函数(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 参考文档

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)$ 尽可能的小。

阅读更多

Git Proxy 配置

git://协议或ssh://协议添加代理

修改 SSH 配置文件,使用 ProxyCommand 添加代理

阅读更多

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 加密库中各种加密函数的命令行工具.

阅读更多

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 在线手册

阅读更多

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 [!] protocol

    Protocol 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 target

    The 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 [!] name

    Name 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 [!] name

    Name 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个)

阅读更多

分屏神器 TMUX

在 Linux 终端下工作,没有一个好用的分屏工具的话,码农的生产力可是要大打折扣的,一个好用的分屏工具,可以保持工作的连贯性,随时可恢复上次离开时的工作环境,而 tmux 就是分屏工具中的翘楚。

阅读更多

关系型数据库管理系统 (RDBMS)

第三章 SQL

3.3 SQL查询的基本结构

3.3.2 多关系查询(SQL查询的通用形式)

select子句,from子句,where子句。每种子句作用如下:  

  • select子句用于列出查询结果中所需要的属性
  • from子句是需要访问的关系列表
  • where子句是一个作用在from子句中关系的属性上的谓词

阅读更多

Xargs 命令

Xargs 简介

xargs 的作用是将参数列表转换成小块分段传递给其他命令,以避免参数列表过长的问题

xargs [options] [command]

xargs 从标准输入读取数据,将数据转换为 command 命令的参数来执行该命令。如果没有指定命令,使用/bin/echo作为默认命令。

阅读更多

Git 常用命令

查看 Git 自带文档

Git 帮助命令,以下三个命令结果相同

git help help

git help --help

man git-help

阅读更多

Awk 命令

Have a try

awk -F: '{print $1, $NF}' /etc/passwd
part of command Meaning
-F: Colon as a separator
{…} Awk program
print Prints the current record
$1 First field
$NF Last field
/etc/passwd Input data file

Awk syntax:

awk [options] '[/pattern/] {action}' [input-file]

阅读更多