/images/avatar.png

^_^

gdb基础使用

gdb安装

Linux版本 CentOS Linux release 7.9.2009

1
2
yum install gdb
gdb --version

基础命令简介

查看gdb的命令

man gdb

以下三种使用gdb调试的方式

gdb program 调试可执行文件

gdb program core 调试corefile

gdb -p 1234 调试正在运行的程序,1234为pid

使用ASAN和Valgrind调试C++内存问题

以下针对C++中常见的内存问题,使用Address Sanitizer和Valgrind进行调试

Linux环境 CentOS 7.9

Valgrind安装

1
2
yum install valgrind
valgrind --version

ASAN安装

1
yum install libasan

Valgrind的使用

valgrind是一套工具集,最常用的工具是memcheck

panic, log.Fatal, os.Exit, runtime.Goexit的区别

panic()如果在本协程里没有recover捕获,则会异常终止程序

在本协程里没有recover,在别的协程中recover是捕获不到的

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package main

import (
	"fmt"
	"time"
)

func main() {
	defer func() {	// 捕获不到
		if r := recover(); r != nil {
			fmt.Println("Recovered in main", r)
		}
	}()
	go func() {
		defer func() {	// 能捕获到
			if r := recover(); r != nil {
				fmt.Println("Recovered in f", r)
			}
		}()
		panic("hello world")
	}()
	time.Sleep(3 * time.Second)
}

os.Exit()会立刻按退出码来终止程序,不会执行defer

软件工程6大原则

宗旨:高内聚、低耦合、好扩展、好维护

六大设计原则

  • 单一职责原则(Single Responsibility Principle, SRP)
  • 开放封闭原则(Open-Closed Principle, OCP)
  • 里氏替换原则(Liskov Substitution Principle, LSP)
  • 接口隔离原则(Interface Segregation Principle, ISP)
  • 依赖倒置原则(Dependency Inversion Principle, DIP)
  • 迪米特法则(Law of Demeter, LoD)

单一职责原则(Single Responsibility Principle, SRP)

一个类或函数,只做一件事情

vim指令速查

vim有三种模式,命令模式(command line),输入模式(insert mode),命令行模式(command-line mode) https://i-blog.csdnimg.cn/img_convert/b2615e7cc613c7bad43a20d6b4819cf9.png#pic_center

广告基本术语

角色

角色 作用
用户 看广告
流量主 提供广告位
广告主 投放广告
需求方平台DSP 为广告主提供服务,相当于中介
供给方平台SSP 为流量主提供服务,相当于中介
广告交易平台 类似拍卖场,对接DSP和SSP,可以对广告位竞价
数据管理平台 对接DSP,拥有用户数据、画像、标签
/images/ad_terms/IMG792.jpg

指标

一般按某个广告位来讲

CS2游戏内设置对应指令

打游戏时突然蓝屏,然后电脑强制更新,重启后设置全变成默认。。。

为了后续方便在不同电脑上玩且在重装系统后能一键恢复设置,所以将原来的设置保存到cfg文件,最后加载cfg文件即可

balisong

开刀

  • 正手风车
  • 正手快开
  • 反手快开
  • 八字开刀
  • 垫指开刀
  • 后甩开刀
  • tweak fan

绕指

  • y2k
  • 反y2k
  • 正反y2k
  • 短停
  • 食指 + 拇指 同向 正
  • 食指 + 拇指 异向 反
  • 阶梯
  • 8ball
  • ufo
  • helix
  • 食指无限转
  • 拇指无限转
  • y3k
  • 三指转
  • xo2
  • 下平y2k
  • 四指转
  • 吻别
  • 水平四指

搓柄

  • 正搓
  • 反搓
  • 下搓

抛接

  • 颠刀
  • 正手抛接
  • 反手抛接

连招

  • y2k + 8ball + ufo + helix
  • 正搓 + 下搓 + 后甩 + 反搓
  • 后甩 + 反搓
  • y2k + 正手抛接 + 绕指 + 八字收刀 + 8ball + ufo + helix + 颠刀 + 反手收刀 + 反搓 + xo2 + 四指转 + tweak fan

装机

记录一下第一次装机,好玩,就是有点麻烦,特别是理线,而且我装了9把风扇,理线理到爆炸,最后还是一坨直接塞到看不见的地方得了

最后成功点亮,烤鸡

带灯的好,但是平时还是不要开了

hotcode

912. 排序数组

题意

题解

改进版快排,针对数据重复问题,荷兰国旗问题 如果数据是有序的,直接随机洗牌就行

 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
26
27
28
func sortArray(nums []int) []int {
	n := len(nums)
	var quickSort func([]int, int, int)
	quickSort = func(nums []int, l int, r int) {
		if l >= r {
			return
		}
		pivot := nums[l + rand.Intn(r-l+1)]
		samel, samer := l, r
		cur := l
		for cur <= samer {
			if nums[cur] < pivot {
				nums[cur], nums[samel] = nums[samel], nums[cur]
				samel++
				cur++
			} else if nums[cur] > pivot {
				nums[cur], nums[samer] = nums[samer], nums[cur]
				samer--
			} else {
				cur++
			}
		}
		quickSort(nums, l, samel-1)
		quickSort(nums, samer+1, r)
	}
	quickSort(nums, 0, n-1)
	return nums
}

103. 二叉树的锯齿形层序遍历

题意

题解

和层序遍历差不多

git补充2

如何更优雅地使用git,包含merge,pull,合并commit

实验工具是gitlab

pre

gitlab上登录,只能免费试用一个月

C++ IPC

管道

 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
26
27
28
#include <iostream>
#include <unistd.h>
int main() {
    int fd[2];
    if (pipe(fd) == -1) {
        perror("pipe");
        return 1;
    }
    // create child process
    pid_t pid = fork();
    char buf[256];
    if (pid == -1) {
        perror("fork");
        return 1;
    } else if (pid > 0) { // parent process
        close(fd[0]);   // close read end
        std::string info = "hello world";
        write(fd[1], info.c_str(), info.length());
        close(fd[1]);
        wait(nullptr);  // block until one child end
    } else {    // pid == 0 is child process
        close(fd[1]);   // close write end
        read(fd[0], buf, sizeof buf);
        close(fd[0]);
        std::cout << "content is: " << buf << '\n';
    }
    return 0;
}

共享内存

 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
26
27
28
29
30
31
32
33
34
35
#include <sys/mman.h> // shm_open mmap
#include <fcntl.h> // for constants
#include <cstdio>
#include <unistd.h>
#include <iostream>

int main() {

    const int SIZE = 1024;

    // open a shared memory object which is a file located in /dev/shm/
    // "my_shm" is file name
    int fd = shm_open("my_shm", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); // -1 error

    // truncate or extend a file to a specified length
    ftruncate(fd, SIZE);    // -1 error

    int* shared_memory = static_cast<int *>(mmap(nullptr, SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)); // MAP_FAILED error

    pid_t pid = fork(); // -1 error
    if (pid > 0) {
        shared_memory[32] = 1000;
        sleep(2);
        std::cout << pid << ' ' << shared_memory[32] << '\n';
        wait(nullptr);
        munmap(shared_memory, SIZE);
        shm_unlink("my_shm");
        close(fd);
    } else if (pid == 0) {
        sleep(1);
        std::cout << pid << ' ' << shared_memory[32] << '\n';
        shared_memory[32] = 2000;
    }
    return 0;
}

to be continued

参考

https://blog.csdn.net/weixin_44014982/article/details/130241892