排序算法

冒泡排序

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
const main = () => {
let count = 0;
let length = arr.length - 1;
let pos = 0;
for (let i = 0; i < arr.length - 1; i++) {
let swap = false;
for (let j = 0; j < length; j++) {
count += 1;
if (arr[j] > arr[j + 1]) {
const temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
swap = true;
pos = j;
}
}
length = pos
if (!swap) {
break;
}
}
console.log(count, arr);
};

main();

快速排序

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
36
37
38
const arr = [3, 7, 8, 4, 5, 1, 2, 6, 9];

const main = () => {
quickSort(arr, 0, arr.length - 1);
console.log(arr);
};

function quickSort(arr, left, right) {
if (left < right) {
let splitIndex = split(arr, left, right);
quickSort(arr, left, splitIndex - 1);
quickSort(arr, splitIndex + 1, right);
}
return arr;
}

function split(arr, left, right) {
const temp = left;
let index = left + 1;

for (let i = index; i <= right; i++) {
if (arr[i] < arr[temp]) {
swap(arr, i, index);
index++;
}
}

swap(arr, temp, index - 1);
return index - 1;
}

function swap(arr, i, j) {
const temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}

main();

插入排序

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
const arr = [3, 7, 8, 4, 5, 1, 2, 6, 9];

const main = () => {
insertionSort(arr);
console.log(arr);
};

const insertionSort = (arr) => {
for (let i = 1; i < arr.length; i++) {
let j = i;
while (j > 0 && arr[j] < arr[j - 1]) {
swap(arr, j, j - 1);
j--;
}
}
};

const swap = (arr, i, j) => {
const temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
};

main();

链表算法

删除链表的第 N 个节点

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
var removeNthFromEnd = function (head, n) {
let newList = new ListNode(0, head);
let first = newList;
let second = head;
let index = 1;

while (second != null) {

second = second.next;

if (index < n) {
index += 1;
} else {
if (second) {
first = first.next;
}
}
}
first.next = first.next.next;

return newList.next;
};

递归算法

Error Debug

Cmake GLFW Error

$\color{red}{Could not find any instance of Visual Studio.}$

  • Visual Studio Installer 安装 单个组件 -> 用于Cmake的工具、工作负载 -> Visual Studio 扩展开发

$\color{red}{No CMAKE_C_COMPILER could be found.}$

  • Visual Studio Installer 安装 单个组件 -> windows SDK

Mac

Git

  • 查看 ts 文件增删记录

    1
    2
    date="2025-04-29";authorName=$(git config user.name);git log --all --author=${authorName} --since="${date} 00:00:00" --until="${date} 23:59:59" --pretty=tformat: --numstat | awk '$3 ~ /\.ts$/ { add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }'

  • 查看所有提交记录

    1
    date="2025-02-20";authorName=$(git config user.name);git log --source --all --author="${authorName}" --since="${date}" --until="${date} 23:59:59" --oneline --graph --decorate

System

  • 查看应用内存使用
    1
    ps -axo rss,comm | grep 'Google Chrome' | awk '{sum+=$1} END {print sum/1024 " MB"}'

Ubuntu

Certbot

  • 自动部署,添加nginx配置
    1
    2
    sudo apt install certbot python3-certbot-nginx -y
    sudo certbot --nginx -d {url}
  • 只生成证书
    1
    sudo certbot certonly --standalone -d dice.dogeggs.cn

零食

饼干

  • 法丽兹曲奇饼干

    不要买抹茶的。

  • 费列罗榛子巧克力夹心威化饼干

    最好吃的威化。

  • 费列罗能多益榛子巧克力夹心饼干

    不如夹心威化。

  • 煌记黑松露火腿苏打饼干

    好吃,偏咸口。

  • Aji 惊奇脆片饼干

肉类

  • 京东京造 超干风干牛肉片麻辣味

    好吃,品控不稳定,遇到过怪味的,发霉的。

豆干

  • 源氏香菇豆干
  • 大话三国张飞豆干夹心脆笋豆卷

巧克力

  • Lindt 瑞士莲巧克力软心夹心黑巧克力

    量大好吃

菌菇

  • 滇二娃云南即食菌菇

即食

  • 思念猪肉豆角焖面

    味正,口感也可以

  • 金拉面

    面口感號

  • 悦味纪 全麦荠菜膳食包

    健康

  • 正宗建德豆腐包

    好吃

Mac

音频

  • 库乐队

    剪音频

  • ffmpeg

    转格式

    1
    2
    // mp3
    ffmpeg -i ${file} -acodec libmp3lame -b:a 320k -vn ${output} -y -loglevel quiet
Read more »
0%