The Hump

前一阵偶尔看到一个介绍驼峰航线的视频,想起了我的姥爷。 1942年5月,日军切断滇缅公路, 这是中国最后一条陆上联外交通线,中美两国被迫在印度东北部的阿萨姆邦和中国云南昆明之间开辟了一条转运战略物资的空中通道,这条空中通道就叫驼峰航线。 我的姥爷,谢自熬,老家陕西长武县,他小时候上过两年私塾, 后来充壮丁参了军。 他很少主动给我讲他当兵时候的事情,我上初中的时候问到他的时候, 他给我讲了他在印度经历,当时坐了很长时间的飞机,飞机颠簸的很厉害, 后来飞到了印度。 当时给他们发的杯子上都印着摩登女郎, 平时训练完还可以去酒吧, 当时他还给我秀了两句英文, “a cup of coffee”。开始他是在高炮旅(不知道准不准确), 做过后勤的司务长,后来他回了国,从云南到内蒙,后来进了傅作义的部队, 一直到和平解放。 我们上学的历史书上也没有介绍过这段历史, 后来翻阅了相关资料,确实有这部分记载, “根据中美协议,远征军第一路司令长官部撤销,改称为中国驻印军总指挥部。史迪威为总指挥,罗卓英为副总指挥。同时,国民政府利用驼峰空运飞机回航的机会,每天空运几百名士兵到印度”(wiki) 我小时候跟着姥姥姥爷长大, 姥爷是一个非常乐观的老头, 姥姥暴躁脾气, 不过对我很好,现在他们都已经不在了, 今年春节回家找出来和他们合影。 姥姥、姥爷:我很想念你们。

2023-01-30 · 1 min · 26 words

Why does calloc exist?

 原文链接:https://vorpus.org/blog/why-does-calloc-exist/ ...

2023-01-29 · 3 min · 598 words

leetcode - Monotonic Array

问题: An array is monotonic if it is either monotone increasing or monotone decreasing. An array nums is monotone increasing if for all i <= j, nums[i] <= nums[j]. An array nums is monotone decreasing if for all i <= j, nums[i] >= nums[j]. Given an integer array nums, return true if the given array is monotonic, or false otherwise. 解答: 单调数组,当数组个数大于2时, 遍历数组, 通过比较当当前值与前一个值的,确定其是递增还是递减, 遍历过程中,如果有变化那么则不满足单调性。 def isMonotonic(array): if len(array) <= 2: return True direction = array[1] - array[0] for i in range(2, len(array)): if direction == 0: direction = array[i] - array[i-1] continue if breakDirection(direction , array[i], array[i-1]): return False; return True; def breakDirection (direction, val, preval): diff = val - preval if direction > 0: return diff < 0 else: return diff > 0 ...

2023-01-23 · 1 min · 161 words

Linux sed 中的&

 一次使用sed 替换操作,替换后的字符串包含 **&,**替换文本如下 $ cat test.txt key=hello & 替换命令 $ sed 's/^key=.*$/key=world & /' test.txt 结果 key=world key=hello & sed 中 s 指令语法: ‘s/regexp/replacement/flags & 符号是代表 regexp 匹配的全部。所以又将原有匹配内容打印了一遍, 可以通过增加 \,将&按照普通字符处理 $ sed 's/^key=.*$/key=world \& /' test.txt key=world & 也可以使用 c 命令, 他之后的所有字符都被认为文本处理 $ sed '/^key=.*$/ckey=world & ' test.txt key=world & 参考及引用 更加详细使用 https://www.gnu.org/software/sed/manual/sed.html#Programming-Commands https://www.grymoire.com/Unix/Sed.html https://likegeeks.com/sed-linux/ 图片from 机滄泳

2022-12-03 · 1 min · 57 words

ubuntu 忘记密码

...

2022-12-03 · 1 min · 37 words

window下查找监听端口进程并关闭

问题: 测试mock服务程序在windows下运行,强制关闭后终端cmd后再次启动时发现, 端口已经被占用。 F:\mock\server1>go run server.go Starting server... listen tcp :60001: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted. panic: runtime error: invalid memory address or nil pointer dereference [signal 0xc0000005 code=0x0 addr=0x18 pc=0xc6f2a0] goroutine 1 [running]: main.main() F:/mock/server1/server.go:163 +0x260 exit status 2 解决: 可以用下面方式查找并删除 F:\mock\server1>netstat -ano|findstr 60001 TCP 0.0.0.0:60001 0.0.0.0:0 LISTENING 25768 TCP [::]:60001 [::]:0 LISTENING 25768 F:\mblb\mock\server1>tasklist|findstr 25768 server.exe 25768 RDP-Tcp#40 1 7,280 K F:\mblb\mock\server1>taskkill /f /pid 25768 成功: 已终止 PID 为 25768 的进程。 F:\mblb\mock\server1>tasklist|findstr 25768 参考及引用: 关于taskkill 和 netstat 可以通过 /? 方式查看 ...

2022-11-29 · 2 min · 414 words

Nginx Development guide

这篇文章来自nginx document /http://nginx.org/en/docs/dev/development_guide.html nginx的开发指南 ...

2022-11-15 · 60 min · 12572 words

python tuple 一个元素时需要增加逗号

项目中使用python tuple时如果是一个元素一定要增加一个逗号,使用python3看下输出。 >>> t(0) Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 't' is not defined >>> t=(0) >>> print(type(t)) <class 'int'> >>> print(t) 0 >>> t=(0,) >>> print(type(t)) <class 'tuple'> >>> print(t) (0,) 官方文档中描述: Note that it is actually the comma which makes a tuple, not the parentheses. The parentheses are optional, except in the empty tuple case, or when they are needed to avoid syntactic ambiguity. For example, f(a, b, c) is a function call with three arguments, while f((a, b, c)) is a function call with a 3-tuple as the sole argument. ...

2022-05-08 · 1 min · 139 words

单元测试

单元测试 单元测试的目的并不是查找bug,而是帮助我们更好的设计我们的代码,如何合理的来拆分我们的代码。 单元测试vs集成测试 集成测试检查各个组件间协作运行是否正常,单元测试检查应用程序中的一个某一个小的功能模块。 相关工具 以python为例 unittest nose or nose2 pytest 其中,nose和nose2基于unittest, 如果使用python2可以使用前两中,pytest要求python3.7+。pytest有较多插件, 显示内容更为丰富一些。 用官方例子比较一下: # content of test_sample.py def inc(x): return x + 1 def test_answer(): assert inc(3) == 5 直接运行pytest [garlic@centos8 pytest]$ pytest ========================================= test session starts ========================================= platform linux -- Python 3.6.8, pytest-7.0.1, pluggy-1.0.0 rootdir: /home/garlic/pytest/pytest collected 1 item test_sample.py F [100%] ============================================== FAILURES =============================================== _____________________________________________ test_answer _____________________________________________ def test_answer(): > assert inc(3) == 5 E assert 4 == 5 E + where 4 = inc(3) test_sample.py:7: AssertionError ======================================= short test summary info ======================================= FAILED test_sample.py::test_answer - assert 4 == 5 ========================================== 1 failed in 0.03s ========================================== [garlic@centos8 pytest]$ cat test_sample.py # content of test_sample.py def inc(x): return x + 1 def test_answer(): assert inc(3) == 5 如果用unittest要写成下面的样子: ...

2022-05-08 · 2 min · 375 words

Non-Constructible Change

问题: 给定一系列正整数,代表硬币的面值,找到无法从这些整数组连续组合成的最小值。比如 coins=[1,2,5], 最小不能组合成的值为4. 解答: 如果下一个整数大于前面所有值的累积和 + 1,那么就知道最小值,如果能被组合范围[0, sum], 下一个数据为y, 如果能构造出联系数据 sum+1 要在 [y,sum+y]范围内。也就是y<=sum+1<=sum+y。 由于排序数组 y>=1, 也就是满足y>sum+1。就可以找到最小组合值。 def nonConstructibleChange(coins): # Write your code here. coins.sort() currentChangeCreated = 0 for coin in coins: if coin > currentChangeCreated + 1: return currentChangeCreated + 1 currentChangeCreated += coin return currentChangeCreated + 1 时间复杂度O(nlogn) 排序, 实际nlogn(排序)+n(遍历求和), 空间复杂度O(1) 参考及引用 https://www.algoexpert.io/questions/Non-Constructible%20Change 使用数学方法表示https://leetcode-cn.com/problems/maximum-number-of-consecutive-values-you-can-make/solution/ni-neng-gou-zao-chu-lian-xu-zhi-de-zui-d-hlxf/ 图片from 陳丁光

2022-05-04 · 1 min · 58 words