Blog

20230826日志

2023年8月26日
2023
202308, C++

caution # int guess(12) 与 int guess{12} 的区别 在C++中,这两种方式的区别是: int guess(32); 是使用构造函数初始化 int guess{32}; 是使用统一初始化语法 构造函数初始化方式调用int的构造函数,使用括号中的值32来初始化guess。 统一初始化语法不需要调用构造函数,直接使用大括号{}初始化guess为32。 两者的结果是相同的,都将guess初始化为整数32。 主要区别在于: 构造函数初始化只适用于有构造函数的类类型,而统一初始化语法可以用于任何类型。 统一初始化语法可以防止隐式类型转换。例如int guess(3.14)会把3.14转为3,而int guess{3.14}在编译时会报错。 统一初始化语法在某些情况下会进行值初始化(将变量初始化为类型的默认值),构造函数初始化则总是直接初始化。 统一初始化语法可以初始化数组和聚合类型。 所以通常来说,统一初始化语法更为通用和安全,C++11后推荐使用统一初始化语法,而不是构造函数初始化 强制类型转化 (type) expression type(expression) static_cast<type>(expression) auto 含义转变 C 中表示内存自动分配释放 C++ 中表示类型自动推导 基本类型 整型从小到大, bool, char, signed char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, long long, unsigned long long ...

英语音标

2023年7月12日
202307
202307, prompt

l 和 r # l 发音 # 分为light l 和 dark l light l 用舌尖抵住上齿龈,气流从舌尖两侧流出,发出清辅音 l dark l 舌头抵住下齿龈,然后抬到上齿龈 r 发音 # 方法1:舌头向上缩 方法2:舌根后缩

prompt总结

2023年6月1日
202306
202306, prompt

原则 # write clear and specific instructions use delimiters " ' ` <> <tag> summarize the text delimeted by triple backticks into a single sentence. \``{text}```` ask for structrued output json xml generate a list of three made-up book titles along with their authors and genres. Provide them in JSON format with the following keys: book_id, title, author, genre check wheather conditions are satisfied ...

密码学

2023年5月20日
202305
202305, cryptography

reference # cryptography https://learn-cryptography.readthedocs.io/zh/latest/basic/ https https://www.bilibili.com/video/BV1KY411x7Jp/?spm_id_from=333.337.search-card.all.click&vd_source=dfa9bf517c1718c832302c15f80df948 密码学 # 凯撒密码: 平移 置换密码: 替换 通过letter frequency分析, 可以破解 one-time pad: 一次性密码本 import random def generate_key(n): return bytes([random.randrange(0, 256) for i in range(n)]) def xor(key, message): return bytes([key[i % len(key)] ^ message[i] for i in range(len(message))]) message = b"ATTACK" key = generate_key(len(message)) print("Key: ", key) cipher = xor(key, message) print(cipher) plain_text = xor(key, cipher) print(plain_text) # 伪随机(线性同余) m = 2 ** 31 a = 1103515245 c = 12345 def lcg(a, c, m, seed): return (a * seed + c) % m seed = 1 for _ in range(10): seed = lcg(a, c, m, seed) print(seed) 流密码 ...

react

2023年5月1日
202305
202305, react

react基本原理 # https://www.bilibili.com/video/BV1be411w7iF/?spm_id_from=333.999.0.0&vd_source=dfa9bf517c1718c832302c15f80df948 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="short icon" href="#"> <script crossorigin src="https://unpkg.com/react@18/umd/react.development.js"></script> <script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script> <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script> <title>Document</title> </head> <body> <div id="root"> </div> <script type="text/babel"> const root = ReactDOM.createRoot(document.getElementById("root")); // root.render(<h1>宝可梦</h1>); // const pokemons = ["皮卡丘", "杰尼龟", "小火龙"]; // 类/函数的方式写组件 class App extends React.Component { // 构造函数->渲染->组件已挂载->渲染 constructor() { console.log("构造函数"); super(); // 动态页面用state保存状态 this. ...

docker命令行

2023年4月25日
202304
202304, docker

重要 # image是静态文件,container是运行在内存中的进程 容器内程序必须前台运行 网络 Bridge: default, single host, DNS, 因为有DNS,可以通过catainer name通讯 Host: only Linux, direct attach Overlay: multiple host 小部分容器管理可以使用compose,大规模使用k8s compose生产案例: http://github.com/datastaxdevs/docker-learning-path/tree/master/week-2 通过容器ID找到了容器在宿主机中的pid cat /sys/fs/cgroup/memory/docker/<containerId>/cgroup.procs 查看windows tcp端口限制 netsh interface ipv4 show excludedportrange protocol=tcp docker build # docker build . 构建image docker build -t <image-name>/<repo-name>:<tagname> . docker run # -publish/-p 开启host与容器内端口映射 docker run --publish 80:80/tcp <image> 前台运行 docker run --publish 80:80/tcp --detach <image> docker run --publish 80:80/tcp --d <image> -e ...

Dockerfile 常用指令

2023年4月24日
202304
202304, docker

Comment # #开头的为注释 Parse Directive # # directive=value1 不添加layer,影响Dockerfile 行的执行顺序 放在最开头 # escape=` 用在windows环境下解决反斜杠是路径分隔符的问题 FROM # FromImagename FROM [--platform=<platform>] <image> [AS <name>] FROM [--platform=<platform>] <image>[:<tag>] [AS <name>] FROM [--platform=<platform>] <image>[@<digest>] [AS <name>] ARG 可以出现在FROM前 FROM可以出现多次 ARG VERSION=latest # outside of build stageFROMbusybox:$VERSIONARG VERSION # 要使用FROM前的ARG,需要再像此一样重新声明一次RUN echo $VERSION > image_versionENV # ENV <key>=<value> 使用环境变量 ${variable} 或者 $variable, ${variable}_name更通用 ${variable:-word}, ${variable:+word} ...

wsl端口windows访问

2023年4月23日
202304
202304, wsl

wsl端口在windows通过localhost访问 # Now Microsoft will forward ports in linux by wslhost.exe when .wslconfig includes localhostForwarding=true (which is ture by default), see wsl-config. But, all those ports will only listen at local network on windows host, which means you can't access them from other devices in the same network. For now, wslpp will still open a same port listening at all interfaces, but if you don't need network access at this, you probably don't need wslpp at all, wslhost. ...

gdb

2023年4月2日
gdb
202304, gdb

gdb概览 # x/gx: 表示在以16进制方式查看内存时,以64位为单位(即8个字节)显示地址中的内容。例如,使用命令"x/gx 0x7fffffff"可以查看地址0x7fffffff处的8个字节内容 x/c: 表示在以16进制方式查看内存时,以字符形式显示地址中的内容。例如,使用命令"x/c 0x7fffffff"可以查看地址0x7fffffff处的一个字符内容 参考: https://github.com/fucking-translation/blog/blob/main/src/lang/rust/14-%E4%BD%BF%E7%94%A8GDB%E8%B0%83%E8%AF%95Rust%E5%BA%94%E7%94%A8.md