dushaoshuai / dushaoshuai.github.io Goto Github PK
View Code? Open in Web Editor NEWHome Page: https://www.shuai.host
Home Page: https://www.shuai.host
If you query data and then insert or update related data within the same transaction, the regular SELECT statement does not give enough protection. Other transactions can update or delete the same rows you just queried. InnoDB supports two types of locking reads that offer extra safety:
lsof -i @localhost:http,https
lsof -i :32002
ss src = 127.0.0.1:7890
相比存储 JSON 格式的字符串,使用 MySQL JSON 数据类型有两个好处:
具体参考 rfc7396 JSON Merge Patch
主要作用是使用一个 JSON Merge Patch 格式的文档来修改服务器上的一个 JSON 文档
具体使用方法,见 JSON_MERGE_PATCH() 和 JSON_MERGE_PRESERVE() 两个修改 JSON 文档的函数
在 MySQL 8.0 中,满足下列条件,优化器可以执行 JSON 的部分、原地更新:
todo 部分更新和 binlog
JSON 值写为字符串。在需要 JSON 值的上下文中,MySQL 会解析字符串,如果不是合法的 JSON 值,会产生错误。
概念 | 解释 |
---|---|
集群(Cluster) | 集群是一组被 kubernetes 统一管理和调度的节点。集群中一部分节点作为 Master 节点,负责集群状态的管理和协调,另一部分作为 Node 节点,负责执行具体的任务,实现用户服务的启停等功能。 |
节点(Node) | 一个物理主机或者虚拟机(VM)。可以运行多个 Pod。 |
Pod | 是 k8s 中的最小调度单元,和一个节点绑定,直到结束或者删除。Pod 相当于逻辑上的主机,如同一个物理主机上运行着若干个应用,若干个容器运行在一个 Pod 里,共享网络和存储资源,被一起放置(co-located)和调度(co-scheduled)。每个 Pod 都拥有唯一的 IP 地址。 |
Deployment | Deployment 是一组 Pod 的抽象。通过 Deployment 控制器保障用户指定数量的容器副本正常运行,并且实现了滚动更新等高级功能。当需要更新业务版本时,Deployment 会按照指定策略杀死旧版本 Pod 并启动新版本 Pod。 |
StatefulSet | StatefulSet 是一组 Pod 的抽象,主要用于有状态应用的管理。StatefulSet 生成的 Pod 名称是固定且有序的,确保每个 Pod 独一无二的身份标识。 |
DaemonSet | DaemonSet 是一组 Pod 的抽象,确保每个节点上运行一个 Pod。当集群中有新加入的节点时,k8s 会自动帮助我们在新节点上运行一个 Pod。一般用于日志采集,节点监控等场景。 |
Job | Job 创建一个 Pod 并且保障 Pod 的正常退出。如果 Pod 运行过程中出现了错误,Job 控制器可以帮助我们创建新的 Pod,执行 Pod 执行成功或者达到指定重试次数。 |
Service | Service 是一组 Pod 访问配置的抽象。Service 通过在主机上配置一定的网络规则,帮助我们通过一个固定的 IP 以轮询的负载均衡策略访问一组 Pod。 |
命名空间(Namespace) | k8s 通过命名空间来实现资源的虚拟化隔离。将一组相关联的资源放到同一个命名空间内。 |
标签(Label) | Label 是一组键值对,每一个资源对象都会拥有此字段。k8s 中使用 label 对资源进行标记,根据 label 对资源进行分类和筛选。 |
ConfigMap | ConfigMap 用于存放业务的配置信息。使用 k-v 方式存储,帮助我们将配置数据和应用程序代码分开。 |
Secret | Secret 用于存放业务的敏感配置信息。使用 k-v 方式存储,主要用于存放密码和证书等敏感信息。 |
TBD | TBD |
curl
下载文件curl -LO https://github.com/containernetworking/plugins/releases/download/v1.1.1/cni-plugins-linux-amd64-v1.1.1.tgz
curl -LO https://github.com/containernetworking/plugins/releases/download/v1.1.1/cni-plugins-linux-amd64-v1.1.1.tgz.sha256
-L
: follow redirects-O
: write output to a local file in the current working directorysha256sum
校验文件$ ls
cni-plugins-linux-amd64-v1.1.1.tgz cni-plugins-linux-amd64-v1.1.1.tgz.sha256
$ cat cni-plugins-linux-amd64-v1.1.1.tgz.sha256
b275772da4026d2161bf8a8b41ed4786754c8a93ebfb6564006d5da7f23831e5 cni-plugins-linux-amd64-v1.1.1.tgz
$ sha256sum --check cni-plugins-linux-amd64-v1.1.1.tgz.sha256
cni-plugins-linux-amd64-v1.1.1.tgz: OK
--check
: read checksums from the FILEs and check themslice = append(slice[:remove_start_index], slice[remove_end_index + 1:]...)
WHERE column LIKE BINARY '%column%'
WHERE column LIKE '%column%'
interface {
... method set ...
}
// iface 是一个接口类型的变量
if foo, ok := iface.(interface { ... method set ... }); ok {
... use methods ...
}
// iface 是一个接口类型的变量
switch x := iface.(type) {
case interface{ ... method set ... }:
... use methods ...
case interface{ ... method set ... }:
... use methods ...
default:
... do something ...
}
MySQL
提供两种模式匹配:标准 SQL 模式匹配(standard SQL pattern matching)
和 基于扩展的正则表达式的模式匹配(pattern matching based on extended regular expressions)
例如,匹配以 b 开头的列 SELECT * FROM table_name WHERE column_name LIKE 'b%'
。
正则表达式语法见 Regular Expression Syntax。
使用 REGEXP_LIKE()
函数或者 REGEXP 操作符或者 RLIKE 操作符。
应该查文档就行了:5.1.9 Using System Variables
type T struct {
v int
}
func (t *T) setValue(v int) {
t.v = v
}
func (t *T) getValue() int {
return t.v
}
func Example_type_T_value_calls_methods_with_receiver_a_pointer_to_T() {
var t T
t.setValue(10)
fmt.Println(t.getValue())
// Output:
// 10
}
按照 https://go.dev/ref/spec#Method_sets 的说法,类型 T 是没有方法的,类型 *T 有两个方法 setValue 和 getValue,这里 t 的类型为 T,但却可以调用 receiver 为 *T 的两个方法 setValue 和 getValue,应该是编译器做了工作,调用方法时取了 t 的指针。
Method sets
Method sets.. Some confusion around type T values calling methods with receivers of type *T
echo 1 > /sys/class/graphics/fbcon/rotate_all
echo 2 > /sys/class/graphics/fbcon/rotate_all
echo 3 > /sys/class/graphics/fbcon/rotate_all
echo 4 > /sys/class/graphics/fbcon/rotate_all
setfont /usr/share/kbd/consolefonts/iso01-12x22.psfu.gz
curl -o /etc/pacman.d/mirrorlist https://archlinux.org/mirrorlist/all/
JSON 是一种轻量的、语言独立的数据交换格式,用于结构化数据的序列化。
JSON 可以表示 6 种数据类型:
4 种 primitive 类型
string
number
boolean
null
2 种结构化类型
object
array
value 可以是 string
、number
、boolean
、null
、object
或者 array
。
string
是由 Unicode 字符组成的序列,用 "
引用,用 \
转义。例如:
"This is an example JSON string."
"the_first_line\nthe_second_line"
字符使用单个字符组成的 string
表示,例如,字符 a 表示为:
"a"
number
可以表示整数,也可以表示浮点数。例如:
-10
10
5.6
5E10
-11e20
11.45e-13
11.45e23
boolean
值有 true
和 false
,必须小写。例如:
true
null
表示不存在,必须小写。例如:
null
object
是 name/value 对的无序集合。name 是 string
。object
以 {
开始,以 }
结束。name 和 value 用 :
分隔,name/value 对之间用 ,
分隔。例如:
{ }
{
"name": "value"
}
{
"key1": 10,
"key2": "value2",
"name3": { },
"chars": ["a", "b", "c", "d"]
}
array
是 value 的有序序列,value 的类型不必相同。以 [
开始,以 ]
结束,value 之间用 ,
分隔。例如:
[ ]
[1, "x", false, null, {"x": 0, "y": 1.1}]
kubeadm init
会报错
--ignore-preflight-errors=NumCPU
flags,kubeadm
就只会发出警告了ip link
sudo cat /sys/class/dmi/id/product_uuid
kubelet
才能正确工作
lsblk
查看交换分区sudo swapoff /dev/xxx
Installing a container runtime
Container Runtimes
kubeadm
,kubelet
,kubectl
kubeadm
,kubelet
,kubectl
不能随意升级,见 Upgrading kubeadm clusters
Skip package from being upgraded
见 Kubernetes镜像 和 Installing kubeadm, kubelet and kubectl
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl
sudo curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
sudo cat <<EOF > /etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl # pin version
容器运行时和 kubelet
需要配置相同的 cgroup driver。
kubeadm
配置sudo kubeadm init --ignore-preflight-errors=NumCPU --config=~/.kube/kubeadm_config.yaml
按照 kubeadm
的输出继续操作:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
现在 kubectl
可以和 api server 对话了,使用 kubectl
为集群安装 pod 网络:
# https://www.weave.works/docs/net/latest/kubernetes/kube-addon/#install
$ kubectl apply -f https://github.com/weaveworks/weave/releases/download/v2.8.1/weave-daemonset-k8s.yaml
serviceaccount/weave-net created
clusterrole.rbac.authorization.k8s.io/weave-net created
clusterrolebinding.rbac.authorization.k8s.io/weave-net created
role.rbac.authorization.k8s.io/weave-net created
rolebinding.rbac.authorization.k8s.io/weave-net created
daemonset.apps/weave-net created
这样控制平面就起来了,可以给集群添加更多节点了:
sudo kubeadm join a.b.c.e:6443 --token abcdef.0123456789abcdef \
--discovery-token-ca-cert-hash sha256:bdffe9db95bb85b742a8e68d5f9d3fb8e4a0e7204bbea75398054ca56eeb93d2
[preflight] Running pre-flight checks
[preflight] Reading configuration from the cluster...
[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Starting the kubelet
[kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap...
This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.
Run 'kubectl get nodes' on the control-plane to see this node join the cluster.
Kubernetes on Arch Linux
kubeadm init
Installing kubeadm
Container Runtimes
Creating a cluster with kubeadm
ITU-T E.164
DIALLING PROCEDURES
https://phonenumbers.temba.io/
https://rawgit.com/googlei18n/libphonenumber/master/javascript/i18n/phonenumbers/demo-compiled.html
The PLUS_SIGN signifies the international prefix.
+86 188 2345 6789
+86 20 1234 5678
Name | 中文名 | Length |
---|---|---|
second | 秒 | 1 s |
millisecond | 毫秒 | 10-3 s |
microsecond | 微妙 | 10-6 s |
nanosecond | 纳秒 | 10-9 s |
youtube-dl --external-downloader aria2c --external-downloader-args '-c -j 16 -x 16 -s 16 -k 20M' URL
参考
零范式是未经过范式化的数据库设计。范式化的目标是:
如果一个属性仅依赖主键的一部分,那个意味着这个主键由最少两个字段组成;如果已满足第一范式且主键仅包含一个字段,那么就自动满足了第二范式。
gRPC 的错误处理用起来不是很方便。一个 RPC 返回的错误,有时是不能展示给用户的,有时又需要展示给用户,区分起来太麻烦了。可以考虑给 Status
额外添加 error details
。
package status_test
import (
"fmt"
"google.golang.org/genproto/googleapis/rpc/errdetails"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func ExampleWithDetail() {
s := status.New(codes.ResourceExhausted, "a per-user quota has been exhausted")
var err error
s, err = s.WithDetails(
&errdetails.LocalizedMessage{
Locale: "zh-CN",
Message: "您已领取,下次再来吧",
},
&errdetails.Help{
Links: []*errdetails.Help_Link{
{
Description: "gPRC - Richer error model",
Url: "https://grpc.io/docs/guides/error/#richer-error-model",
},
{
Description: "googleapis - Error Model",
Url: "https://cloud.google.com/apis/design/errors#error_model",
},
{
Description: "googleapis - google.rpc.Status",
Url: "https://github.com/googleapis/googleapis/blob/master/google/rpc/status.proto",
},
{
Description: "googleapis - google.rpc.error_details",
Url: "https://github.com/googleapis/googleapis/blob/master/google/rpc/error_details.proto",
},
{
Description: "google.golang.org/grpc/status",
Url: "https://pkg.go.dev/google.golang.org/[email protected]/status",
},
{
Description: "google.golang.org/genproto/googleapis/rpc/errdetails",
Url: "https://pkg.go.dev/google.golang.org/genproto/googleapis/rpc/errdetails",
},
},
},
)
if err != nil {
panic(err)
}
// return error
// s.Err() returns an error
for _, detail := range s.Details() {
switch detail := detail.(type) {
case *errdetails.LocalizedMessage:
fmt.Println(detail.GetLocale(), detail.GetMessage())
case *errdetails.Help:
for _, link := range detail.GetLinks() {
fmt.Println(link.GetDescription())
fmt.Println(link.GetUrl())
}
}
}
// Output:
// zh-CN 您已领取,下次再来吧
// gPRC - Richer error model
// https://grpc.io/docs/guides/error/#richer-error-model
// googleapis - Error Model
// https://cloud.google.com/apis/design/errors#error_model
// googleapis - google.rpc.Status
// https://github.com/googleapis/googleapis/blob/master/google/rpc/status.proto
// googleapis - google.rpc.error_details
// https://github.com/googleapis/googleapis/blob/master/google/rpc/error_details.proto
// google.golang.org/grpc/status
// https://pkg.go.dev/google.golang.org/[email protected]/status
// google.golang.org/genproto/googleapis/rpc/errdetails
// https://pkg.go.dev/google.golang.org/genproto/googleapis/rpc/errdetails
}
Acronym | Full Form | Index |
---|---|---|
ARP | Address Resolution Protocol(地址解析协议) | p305 |
ARQ | Automatic repeat request(自动重传请求), also automatic repeat query | p144 |
CDMA | Code Division Multiple Access(码分多址) | p295 |
CMTS | Cable Modem Terminatin System(电缆调制调节器) | p301 |
CRC | Cyclic Redundancy Check(循环冗余检测) | p291 |
CSMA | Carrier Sense Multiple Access(载波侦听多路访问) | p295 p298 |
CSMA/CD | CSMA with Collision Detection(具有碰撞检测的 CSMA) | p298 |
EDC | Error- Detection and- Correction(差错检测和纠正) | p288 |
FDM | (频分多路复用) | p294 |
FEC | Forward Error Correction(前向纠错) | p290 |
HDLC | high-level data link control(高级数据链路控制) | p292 |
HFC | Hybrid Fiber Coaxial cable(混合光纤同轴电缆) | p285 |
MAC | Medium Access Control(媒体访问控制) | p287 |
MTU | 最大传输单元 | p308 |
NIC | Network Interface Card(网络接口卡), also network adapter(网络适配器) | p287 |
PPP | Point-to-Point Protocol(点对点协议) | p285 p292 |
SDN | Software-Defined Networking(软件定义网络) | p198 p202 |
TDM | (时分多路复用) | p294 |
使用 Raspberry Pi Imager 安装 Ubuntu Server 22.04.1 LTS 时,已经做了如下配置:
但是使用 sudo nmap -sn 192.168.0.0/24
扫描局域网时,仍未找到树莓派的 IP,一开始还以为自己配置有问题,后来在 Ubuntu 官网上找到了原因。
原来 Raspberry Pi Imager 并未正确配置网络,需要手动在 SD 卡上非启动分区上的 /etc/netplan/
文件夹下新建 50-cloud-init.yaml
文件:
wifis:
wlan0:
dhcp4: true
optional: true
access-points:
"home network":
password: "123456789"
Install Ubuntu on a Raspberry Pi
How to install Ubuntu Server on your Raspberry Pi
供应商锁定是指这么一种情况:切换到其他供应商的成本过高,客户不得不继续使用现有供应商提供的服务。
IANA Time Zone database
Wikipedia - Time zone
Wikipedia - Lists of time zones
go package - time.Location
Get Current System Time Zone in Linux
go package - tzdata
/etc/localtime
configures the system-wide timezone. It's a symlink pointing to the actual binary timezone data file in /usr/share/zoneinfo/
.
$ ls -l /etc/localtime
lrwxrwxrwx 1 root root 33 Nov 17 06:18 /etc/localtime -> /usr/share/zoneinfo/Asia/Shanghai
See man 5 localtime
for more information.
/etc/timezone
stores the timezone of the system in plain text format.
$ cat /etc/timezone
Asia/Shanghai
timedatectl
show timezone of the system.
$ timedatectl
Local time: Mon 2022-11-21 14:51:29 CST
Universal time: Mon 2022-11-21 06:51:29 UTC
RTC time: Mon 2022-11-21 06:51:29
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
See man timedatectl
for more information.
People keep referencing OCI, what is that?
CRI: the Container Runtime Interface
cgroup (control group)
cgroups
About cgroup v2
cgroup v2
Docker on Mac - How is it done ?
Configuring a cgroup driver
Configure kubelets using kubeadm
[IPAM: IP address allocation](IPAM: IP address allocation)
type | storage (bytes) | format specifier (base 10, 8, 16) | constant suffix |
---|---|---|---|
short | 2 | %hd %ho %hx | |
unsigned short | 2 | %hu | |
int | 4 | %d %o %x | |
unsigned | 4 | %u | |
long | 8 | %ld %lo %lx | l (lowercase L) or L |
unsigned long | 8 | %lu | ul, LU ... |
long long | 8 | %lld %llo %llx | ll or LL |
unsigned long long | 8 | %llu | ull, LLu ... |
base | constant prefix | example |
---|---|---|
8 | 0 | 020 |
10 | 16 | |
16 | 0x or 0X | 0x10 or 0X10 |
// bases.c -- prints 16 in decimal, octal, and hex
#include <stdio.h>
int main(void) {
int x = 16;
printf("dec = %d; octal = %o; hex = %x\n", x, x, x);
printf("dec = %d; octal = %#o; hex = %#x\n", x, x, x);
printf("dec = %d; octal = %#o; hex = %#X\n", x, x, x);
return 0;
}
// Output:
// dec = 16; octal = 20; hex = 10
// dec = 16; octal = 020; hex = 0x10
// dec = 16; octal = 020; hex = 0X10
CREATE TABLE `tb` SELECT * FROM `ta`;
OR
-- https://dev.mysql.com/doc/refman/8.0/en/create-table-select.html#:~:text=%2D%2D%2B-,mysql%3E,-CREATE%20TABLE%20tt1
CREATE TABLE `tb` TABLE `ta`;
13.2.6.1 INSERT ... SELECT Statement
CREATE TABLE `tb` LIKE `ta`;
INSERT INTO `tb` SELECT * FROM `ta`; -- Or beginning with MySQL 8.0.19: INSERT INTO `tb` TABLE `ta`;
# ~/.config/user-dirs.dirs
XDG_DESKTOP_DIR="$HOME/Desktop"
XDG_DOCUMENTS_DIR="$HOME/Documents"
XDG_DOWNLOAD_DIR="$HOME/Downloads"
XDG_MUSIC_DIR="$HOME/Music"
XDG_PICTURES_DIR="$HOME/Pictures"
XDG_PUBLICSHARE_DIR="$HOME/Public"
XDG_TEMPLATES_DIR="$HOME/Templates"
XDG_VIDEOS_DIR="$HOME/Videos"
在家目录下生成默认的目录:
$ xdg-user-dirs-update
$ ls
Desktop Documents Downloads Music Pictures Public Templates Videos
func RoundPrecision(x float64, precision int) float64 {
ratio := math.Pow10(precision)
return math.Round(x*ratio) / ratio
}
func RoundUpPrecision(x float64, precision int) float64 {
ratio := math.Pow10(precision)
return math.Ceil(x*ratio) / ratio
}
func RoundDownPrecision(x float64, precision int) float64 {
ratio := math.Pow10(precision)
return math.Floor(x*ratio) / ratio
}
原文链接
The BLOB, TEXT, GEOMETRY, and JSON data types can be assigned a default value only if the value is written as an expression, even if the expression value is a literal.
CREATE TABLE jtable (
jcol JSON DEFAULT (JSON_ARRAY())
);
原文链接
The BLOB, TEXT, GEOMETRY, and JSON data types cannot be assigned a default value.
原文链接
Prior to MySQL 8.0.13, a JSON column cannot have a non-NULL default value.
# /etc/ssh/sshd_config
# IP A.B.C.E 可以使用密码登录,也可以使用公钥登录
Match Address A.B.C.E
PasswordAuthentication yes
PubkeyAuthentication yes
AuthenticationMethods publickey password
例如,json.Marshal()
函数中:
buf := append([]byte(nil), e.Bytes()...)
再比如,append()
的注释中:
// As a special case, it is legal to append a string to a byte slice, like this:
// slice = append([]byte("hello "), "world"...)
text is a repository of text-related packages related to internationalization (i18n) and localization (l10n), such as character encodings, text transformations, and locale-specific text handling.
There is a 30 minute video, recorded on 2017-11-30, on the "State of golang.org/x/text" at https://www.youtube.com/watch?v=uYrDrMEGu58
State of golang.org/x/text
The Go Blog - Language and Locale Matching in Go
Plural Rules
Fluent
JavaScript APIs -> i18n
Tags for Identifying Languages
Picking the Right Language Identifier
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.