280篇 Default中的文章

Linux 命令:flock - 对打开的文件加锁或解锁

先来看看flock -h 的用法:

Usage:
 flock [options] <file|directory> <command> [command args]
 flock [options] <file|directory> -c <command>
 flock [options] <file descriptor number>

Options:
 -s  --shared             get a shared lock
 -x  --exclusive          get an exclusive lock (default)
 -u  --unlock             remove a lock
 -n  --nonblock           fail rather than wait
 -w  --timeout <secs>     wait for a limited amount of time
 -E  --conflict-exit-code <number>  exit code after conflict or timeout
 -o  --close              close file descriptor before running command
 -c  --command <command>  run a single command string through the shell

 -h, --help     display this help and exit
 -V, --version  output version information and exit

For more details see flock(1).
More ~

go语言格式化打印fmt的参数

go 软件包fmt使用与C的printf和scanf类似的功能实现格式化的I / O。

概要:

%v	默认格式的值,打印结构时,加号(%+ v)添加字段名称
%#v	该值的Go语法表示形式
%T	值类型的Go语法表示形式
%%	文字百分号;没有任何价值

Boolean:

%t	单词true或false

Integer:

%b	2进制
%c	相应的Unicode代码点表示的字符
%d	10进制
%o	8进制
%O	以0o为前缀8进制
%q	使用Go语法安全地转义的单引号字符文字。
%x	16进制的a-f小写字母
%X	16进制的A-F大写字母
%U	Unicode格式:U + 1234;与“ U +%04X”相同
More ~

python 的subprocess 模块使用详解

一、简介

  subprocess最早在2.4版本引入。用来生成子进程,并可以通过管道连接他们的输入/输出/错误,以及获得他们的返回值。

  subprocess用来替换多个旧模块和函数:

  • os.system
  • os.spawn*
  • os.popen*
  • popen2.*
  • commands.*

运行python的时候,我们都是在创建并运行一个进程,linux中一个进程可以fork一个子进程,并让这个子进程exec另外一个程序。在python中,我们通过标准库中的subprocess包来fork一个子进程,并且运行一个外部的程序。subprocess包中定义有数个创建子进程的函数,这些函数分别以不同的方式创建子进程,所欲我们可以根据需要来从中选取一个使用。另外subprocess还提供了一些管理标准流(standard stream)和管道(pipe)的工具,从而在进程间使用文本通信。

More ~

Docker 容器的健康检查

健康检查 (HEALTHCHECK) 指令简介

健康检查 (HEALTHCHECK) 指令告诉 Docker 如何检查容器是否仍在工作。 它能够监测类似一个服务器虽然服务进程仍在运行, 但是陷入了死循环, 不能响应新的请求的情况。

当一个容器有指定健康检查 (HEALTHCHECK) 时, 它除了普通状态之外, 还有健康状态 (health status) 。 健康状态的初始状态是正在启动 (starting) , 一旦通过了一个健康检查, 它将变成健康 (healthy) (不管之前的状态是什么), 经过一定数量的连续失败之后, 它将变成不健康 (unhealthy) 。

More ~

vscode中 flake8 忽略检查项

主要是python.linting.flake8Args 中加上 --ignore参数 即可

{
    "python.linting.flake8Enabled": true,
    "python.formatting.provider": "yapf",
    "python.linting.flake8Args": [
        "--max-line-length=248",
        "--ignore=F403,F405"
    ],
    "python.linting.pylintEnabled": false

}
More ~

了解一下k3s

一句话介绍:

k3s - 轻量级的 Kubernetes,易于安装,占用内存少,安装包小于100MB。

它非常适合于以下场景:

  • Edge
  • IoT
  • CI
  • Development
  • ARM
  • Embedding k8s
  • Situations where a PhD in k8s clusterology is infeasible
More ~

vue trigger button event

如下,button1 按下后想触发 button 2 的click事件,可以这样做:

<template>
    <button type="primary" @click="event2" ref="myBtn">
        button 2
    </button>
    <button type="primary" @click="event1">
        button 1
    </button>
</template>

<script>
export default {
    methods: {
        event1($event) {
            this.$refs.myBtn.$el.click()
        }
    }
}
</script>

这里注意是用this.$refs.myBtn.$el.click(),而不是this.$refs.myBtn.click()

More ~

macos 上查看端口占用

使用命令lsof即可。
lsof -i :3306

lsof -i :3306
COMMAND PID   USER   FD   TYPE            DEVICE SIZE/OFF NODE NAME
mysqld  773 hijack   32u  IPv4 0x5273dd7b96798a1      0t0  TCP localhost:mysql (LISTEN)

也可以指定tcp 如lsof -i tcp:3306

More ~

nginx: [warn] the "ssl" directive is deprecated

当执行 nginx -s reload 时报出:

nginx: [warn] the "ssl" directive is deprecated, use the "listen ... ssl" directive instead in /etc/nginx/conf.d/xxx.conf:29

原来可能这样写:

server {
    listen       443 ssl;
    server_name  www.zixi.org;
    ssl on;
    ...

现在直接去掉ssl on; 这一行即可。

More ~