/images/avatar.png

^_^

C++互斥锁

std::mutex

最简单的互斥锁

 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
// mutex example
#include <iostream>       // std::cout
#include <thread>         // std::thread
#include <mutex>          // std::mutex

std::mutex mtx;           // mutex for critical section

void print_block (int n, char c) {
    // critical section (exclusive access to std::cout signaled by locking mtx):
    // mtx.lock();
    for (int i=0; i<n; ++i) { std::cout << c; }
    std::cout << '\n';
    // mtx.unlock();
}

int main ()
{
    std::thread th1 (print_block,50,'*');
    std::thread th2 (print_block,50,'$');

    th1.join();
    th2.join();

    return 0;
}

输出

C++类继承和可见性

三种继承方式,是否真正继承了,子类可访问吗,外部可访问吗

三种可见性,类自己可访问吗,外部可访问吗

继承默认是private继承

继承和可见性问题

private、protected、public

shell三剑客

grep

Global Regular Expression Print

用正则表达式查找文本

grep [-option] {pattern} {file}

-A<行数> 除了显示匹配 pattern 的那一行外,显示该行之后的内容
-B<行数> 除了显示匹配 pattern 的那一行外,显示该行之前的内容
-C<行数> 除了显示匹配 pattern 的那一行外,显示该行前、后的内容
-c 统计匹配的行数
-e 同时匹配多个pattern
-i 忽略字符的大小写
-n 显示匹配的行号
-o 只显示匹配的字符串
-v 显示没有匹配pattern的那一行,相当于反向匹配
-w 匹配整个单词

sed

stream editor

Linux输入输出

万物皆文件 – Linus Torvalds

重定向

标准输入流stdin的文件描述符是0,标准输出流stdout的文件描述符是1,标准错误流的文件描述符是2

标准输入流一般是键盘在终端的输入,标准输出流和错误输出流一般显示在终端屏幕上

mysql

基础

SQL

SQL语言分类

https://img-blog.csdnimg.cn/2afe0b4cdc0245b98d53514141396a15.png

DDL

数据类型

数值型

https://img-blog.csdnimg.cn/1148cd5ca9e743c0a5fe8a5853ab8af6.png

字符串类型

https://img-blog.csdnimg.cn/aa69d47a96fb4404a688d71fdb51c6d9.png

日期和时间型

https://img-blog.csdnimg.cn/5fe2320a10ca4bc0bbfe6ea349d4bec7.png

数据库

查数据库show databases;

查当前数据库select database();

蛋炒饭

蛋炒饭需要使用隔夜饭,所以提前一天把饭拿到冰箱中

拿出隔夜饭,打两个蛋

https://img-blog.csdnimg.cn/d40b7a9c3f6048e892579e5e87d1b707.png

切两根火腿

https://img-blog.csdnimg.cn/cd01d088d8f7426c9ee61c20d04edc10.png

鸡蛋液倒四分之一到米饭中

https://img-blog.csdnimg.cn/76f7a3ce41b144e2829b9a2deed1b623.png

protobuf

protobuf是一个类似于用来定义网络传输过程中数据包格式的东西,有点像json

它可以被序列化和反序列化,从而用于传输

参考链接

gflags

文档链接

gflags相当于代码中的常量

gflags读取命令行的flags,然后修改代码中相应名字的“常量”

主要有三个函数

git补充

参考资料

问题

如果已经推到远程仓库,该怎么撤销

其他

从工作目录git add提交到暂存区后,想撤销

注意如果在工作目录创建文件,撤销操作只是不跟踪该文件,并不会把文件删掉

GO利用ftp服务器进行文件上传和下载

购买云服务器,这个云服务器将作为ftp服务器

假设云服务器是centos系统

先安装vsftpd

输入以下命令

1
sudo yum install vsftpd

启动vsftpd服务

1
sudo systemctl start vsftpd

确认 vsftpd 服务已启动及其状态是否为“active”

GO与测试

参考

单元测试

规则

  • 所有测试文件以_test.go结尾

  • func TestXxx(*testing.T)

  • 初始化逻辑放到TestMain中

例子

文件名为nihao_test.go

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
package hello

import "testing"

func HelloTom() string {
	return "Jerry"
}

func TestHelloTom(t *testing.T) {
	output := HelloTom()
	expectOutput := "Tom"
	if output != expectOutput {
		t.Errorf("Expect %s do not match actual %s", expectOutput, output)
	}
}

在命令行输入`go test nihao_test.go``