commit b1aeb6b39b55a1f2ed2bf2631c93cbc60746b256 Author: zhilv Date: Fri Nov 7 18:39:29 2025 +0800 feat(*): 代码仓库初始化 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b694934 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.venv \ No newline at end of file diff --git a/DataStructure/README.md b/DataStructure/README.md new file mode 100644 index 0000000..dd807fd --- /dev/null +++ b/DataStructure/README.md @@ -0,0 +1,17 @@ + + +## 数据结构 + +### 文件介绍 + +```sh +. +├── test1 # 实验1 +├── test2 # 实验2 +└── test3 # 实验3 +``` diff --git a/DataStructure/test1/实验一.cpp b/DataStructure/test1/实验一.cpp new file mode 100644 index 0000000..923b85f --- /dev/null +++ b/DataStructure/test1/实验一.cpp @@ -0,0 +1,229 @@ +#include +#include +#include + +typedef struct LNode +{ + int data; // ������ + struct LNode *next; // ָ���� +} LNode, *LinkList; // LinkListΪָ��LNode���͵�ָ������ + +void chushihua(LinkList &L, LinkList &M, LinkList &N, LinkList &H) // ��ʼ���ĸ�����L��M��N��H +{ + // todo list + L = (LinkList)malloc(sizeof(LNode)); + M = (LinkList)malloc(sizeof(LNode)); + N = (LinkList)malloc(sizeof(LNode)); + H = (LinkList)malloc(sizeof(LNode)); + L->next = NULL; // ֱ���ÿգ������ж� + M->next = NULL; + N->next = NULL; + H->next = NULL; +} +void Emp(LinkList &L) // �ж�����L�Ƿ�Ϊ�ձ� +{ + // if (//todo list) + if (L->next == NULL) + printf("����Ϊ�ձ���\n"); + else + printf("����Ϊ�ǿձ���\n"); +} + +void Length(LinkList L) +{ // �����������L������Ԫ�ظ��� + LNode *p; // ������ʱ����p + p = L->next; // pָ���һ�����(��Ԫ���) + int length = 0; + // todo list //����������,ͳ�ƽ���� + while (p != NULL) + { + length++; + p = p->next; + } + + printf("��������Ϊ��%d\n", length); +} + +// ��ʾ����L������Ԫ�� +void xianshi(LinkList &L) +{ + LNode *p; // ������ʱ����p //LinkList p; + p = L; + while (p->next != NULL) + { + printf("%4d", p->next->data); + p = p->next; + } + printf("\n"); // ���ӻ��У����ڲ鿴 +} + +// 1��������������������������L�в���n������������ʱ���������������ԣ���С���󣩡� +void charu_1(LinkList &L, int n) +{ + LNode *q, *p; + for (int i = 1; i <= n; i++) + { + p = L; // ��ÿ��ѭ����ʼʱ����pָ��������ͷ�ڵ�L + q = (LinkList)malloc(sizeof(LNode)); // Ϊ�µĽڵ�����ڴ棬����qָ������ڴ� + printf("�������%d����������ֵ", i); + scanf("%d", &q->data); // �������ֵ�洢��qָ��Ľڵ��data�ֶ��� + q->next = NULL; // ���½ڵ��nextָ������ΪNULL����ʾ�½ڵ㵱ǰ��ָ���κνڵ㡣 + + // ���Ҳ���λ�� + while (p->next != NULL && p->next->data < q->data) + { + p = p->next; // �ƶ�����һ���ڵ� + } + // �����½ڵ� + q->next = p->next; + p->next = q; + } +} + +// 2���ֽ⣺������L�е�Ԫ�ط�Ϊ������ż����������M��N�����ֱ���ʾ���ǡ� +void fenbiao(LinkList &L, LinkList &M, LinkList &N) +{ + LNode *j, *o, *p, *temp; + p = L; + while (p->next != NULL) + { + temp = p->next; // ���浱ǰ�ڵ� + p->next = temp->next; // ��ǰ�ƶ�p��next����ֹ���� + + if (temp->data % 2 == 0) // ż��Ԫ�أ�ǰ�巨��M + { + o = (LinkList)malloc(sizeof(LNode)); + o->data = temp->data; + o->next = M->next; + M->next = o; + } + else // ����Ԫ�أ�ǰ�巨��N + { + j = (LinkList)malloc(sizeof(LNode)); + j->data = temp->data; + j->next = N->next; + N->next = j; + } + free(temp); // �ͷ�ԭ�ڵ��ڴ� + } + printf("���Ϊ:"); + xianshi(N); // ����������Ӧ�ô����N�� + printf("ż��Ϊ:"); + xianshi(M); // ������ż��Ӧ�ô����M�� +} + +// 3���ϲ�һ���ݼ�����������������J��ż������O�ϲ�Ϊһ���µ�����H���ϲ�ʱ����Ԫ�ص������ԡ� +void hebiao(LinkList &J, LinkList &O, LinkList &H) +{ + LNode *p, *q, *t, *m; + p = J->next; // ָ����Ԫ�ڵ� + q = O->next; + m = H; // m�൱��βָ�룬��ʼָ��ͷ�ڵ� + + // ���Hԭ������ + H->next = NULL; + + while (p != NULL && q != NULL) // �ж����ż���������ݽ�� + { + if (p->data > q->data) // ��������ż����ȡ���� + { + t = (LinkList)malloc(sizeof(LNode)); + t->data = p->data; + t->next = NULL; + m->next = t; // β�� + m = t; // ����βָ�� + p = p->next; // �ƶ���������ָ�� + } + else // ȡż�� + { + t = (LinkList)malloc(sizeof(LNode)); + t->data = q->data; + t->next = NULL; + m->next = t; // β�� + m = t; // ����βָ�� + q = q->next; // �ƶ�ż������ָ�루������ԭ��������ƶ���p�� + } + } + + // ����ʣ��������ڵ� + while (p != NULL) + { + t = (LinkList)malloc(sizeof(LNode)); + t->data = p->data; + t->next = NULL; + m->next = t; + m = t; + p = p->next; + } + + // ����ʣ���ż���ڵ� + while (q != NULL) + { + t = (LinkList)malloc(sizeof(LNode)); + t->data = q->data; + t->next = NULL; + m->next = t; + m = t; + q = q->next; // ������ԭ��������ƶ���p + } + + printf("�Ӵ�С�ĵ�����Ϊ��"); + xianshi(H); // ��ʾ�ϱ�H +} + +int main() +{ + // �����½����Ϊͷ��㣬��ͷָ��ֱ�ָ���ͷ��� + LinkList head = (LinkList)malloc(sizeof(LNode)); + LinkList ji = (LinkList)malloc(sizeof(LNode)); + LinkList ou = (LinkList)malloc(sizeof(LNode)); + LinkList he = (LinkList)malloc(sizeof(LNode)); + + int choose = -1, n; + printf("*********************************************\n"); + printf("********** ʵ��һ *******\n"); + printf("*********************************************\n"); + printf("********** 1.��ʼ�������� *******\n"); + printf("********** 2.������������ *******\n"); + printf("********** 3.�ֳ���/ż������ *******\n"); + printf("********** 4.�ϲ��ɵݼ������� *******\n"); + printf("********** 5.��ʾ������(����)���������� *******\n"); + printf("********** 6.���������� *******\n"); + printf("********** 7.�жϵ������Ƿ�Ϊ�� *******\n"); + printf("********** 0.�˳� *******\n"); + printf("*********************************************\n"); + while (choose) + { + printf("���������ѡ���\n"); + scanf("%d", &choose); + switch (choose) + { + case 1: + chushihua(head, ji, ou, he); + break; + case 2: + printf("��������Ҫ�����������ĸ�����\n"); + scanf("%d", &n); + charu_1(head, n); + break; + case 3: + fenbiao(head, ou, ji); + break; + case 4: + hebiao(ji, ou, he); + break; + case 5: + xianshi(head); + break; + case 6: + Length(head); + break; + case 7: + Emp(head); + break; + case 0: + exit(0); + break; + } + } +} \ No newline at end of file diff --git a/DataStructure/test2/实验二.cpp b/DataStructure/test2/实验二.cpp new file mode 100644 index 0000000..1936e63 --- /dev/null +++ b/DataStructure/test2/实验二.cpp @@ -0,0 +1,233 @@ +#include +#include +#include + +typedef struct PNode +{ + int index; // ָ + int coe; // ϵ + struct PNode *next; // ָ +} PNode, *Polynomial; + +void chushihua(Polynomial &L, Polynomial &M, Polynomial &N) +{ + // todo list + L = (Polynomial)malloc(sizeof(PNode)); + M = (Polynomial)malloc(sizeof(PNode)); + N = (Polynomial)malloc(sizeof(PNode)); + L->next = NULL; + M->next = NULL; + N->next = NULL; +} +void Emp(Polynomial &L) +{ + if (L->next == NULL) + printf("Ϊձ\n"); + else + printf("Ϊǿձ\n"); +} + +void Length(Polynomial &L) +{ + PNode *p; + int length = 0; + // todo list //whileѭƶpָ룬length++ + p = L; + while (p->next != NULL) + { + p = p->next; + length++; + } + + printf("Ϊ%d\n", length); +} + +// 1ָڵ㣬һԪʽ +void charu_1(Polynomial &L) +{ + PNode *q, *p; + int n; + printf("ҪһԪʽ\n"); + scanf("%d", &n); + for (int i = 1; i <= n; i++) + { + p = L; + q = (Polynomial)malloc(sizeof(PNode)); + printf("%dϵָ", i); + scanf("%d%d", &q->coe, &q->index); + q->next = NULL; + while (p->next != NULL && p->next->index < q->index) + { + // todo list pָƶһλ + p = p->next; + } + // todo list *q뵽*p + q->next = p->next; + p->next = q; + } +} + +void xianshi(Polynomial &L) +{ + PNode *p; + p = L; + while (p->next != NULL) + { + printf("%4d", p->next->coe); // ϵ + printf("H"); + printf("%d", p->next->index); // ָ + p = p->next; + } +} + +// 2һԪʽ +void hebiao(Polynomial &J, Polynomial &O, Polynomial &H) +{ + PNode *p = J->next, *q = O->next, *r = H, *s; // rβָ + while (p != NULL && q != NULL) + { + if (p->index < q->index) + { + s = (Polynomial)malloc(sizeof(PNode)); + // todo list //pָϵָsָеϵָ + s->coe = p->coe; + s->index = p->index; + // todo list //sָ㵽rָĺ + s->next = NULL; + r->next = s; + + r = s; // βָ + p = p->next; // pָ + } + else if (p->index > q->index) + { + s = (Polynomial)malloc(sizeof(PNode)); + // todo list //qָϵָsָеϵָ + s->coe = q->coe; + s->index = q->index; + // todo list //sָ㵽rָĺ + s->next = NULL; + r->next = s; + + r = s; // βָ + q = q->next; // qָ + } + else + { // ָȵ + int sum = p->coe + q->coe; + if (sum != 0) + { + s = (Polynomial)malloc(sizeof(PNode)); + // todo list //pָָsָеָ + s->index = p->index; + // todo list //sumsָеϵ + s->coe = sum; + // todo list //sָ㵽rָĺ + s->next = NULL; + r->next = s; + + r = s; // βָ + } + p = p->next; // pָ + q = q->next; // qָ + } + } + while (p != NULL) + { // JǿգʣԪأʣԪز뵽ϱH + s = (Polynomial)malloc(sizeof(PNode)); + // todo list β + s->coe = p->coe; + s->index = p->index; + s->next = NULL; + r->next = s; + r = s; + + p = p->next; // pָ + } + while (q != NULL) + { // OǿգʣԪأʣԪز뵽ϱH + s = (Polynomial)malloc(sizeof(PNode)); + // todo list β + s->coe = q->coe; + s->index = q->index; + s->next = NULL; + r->next = s; + r = s; + + q = q->next; // qָ + } + xianshi(H); // +} + +int main() +{ + Polynomial head[3]; + int i; + for (i = 0; i < 3; i++) + { + head[i] = (Polynomial)malloc(sizeof(PNode)); // head[0]ʾһһԪʽhead[1]ΪڶһԪʽ + } + + int choose = -1, n; + printf("*********************************************************\n"); + printf("********** ʵ *******\n"); + printf("*********************************************\n"); + printf("********** 1.ʼ *******\n"); + printf("********** 2.(ָ) *******\n"); + printf("********** 3.ʾ *******\n"); + printf("********** 4. *******\n"); + printf("********** 5.жϵǷΪ *******\n"); + printf("********** 6.һԪʽĺ *******\n"); + printf("********** 0.˳ *******\n"); + printf("*********************************************************\n"); + while (choose) + { + printf("ѡ\n"); + scanf("%d", &choose); + switch (choose) + { + case 1: + chushihua(head[0], head[1], head[2]); + printf("Ѿʼ\n"); + break; + case 2: + for (i = 0; i < 2; i++) + { + printf("ĵ%dһԪʽ\n", i + 1); + charu_1(head[i]); // ڵ㵽ָ + } + break; + case 3: + printf("ʾ1"); + xianshi(head[0]); // ʾ1 + printf("\n"); + printf("ʾ2"); + xianshi(head[1]); // ʾ2 + printf("\n"); + // xianshi(head[2]); // ʾ3 + // printf("\n"); + break; + case 4: + printf("1ijȣ"); + Length(head[0]); // 1ij + printf("2ijȣ"); + Length(head[1]); // 2ij + // Length(head[2]); // 3ij + break; + case 5: + printf("жϵ1ǷΪգ"); + Emp(head[0]); // жϵ1ǷΪ + printf("жϵ2ǷΪգ"); + Emp(head[1]); // жϵ2ǷΪ + // Emp(head[2]); // жϵ3ǷΪ + break; + case 6: + hebiao(head[0], head[1], head[2]); + break; + case 0: + exit(0); + break; + } + } + return 0; // ˳ʱ0 +} diff --git a/DataStructure/test3/实验三.cpp b/DataStructure/test3/实验三.cpp new file mode 100644 index 0000000..295e03c --- /dev/null +++ b/DataStructure/test3/实验三.cpp @@ -0,0 +1,129 @@ +#include +#include + +#define MAXSIZE 10 +typedef struct Queue +{ + int *data; // 洢ռĻַ + int front, rear; // ͷָ롢βָ + int count; // һ countڼ¼Ԫظ +} Queue; + +// ʼ +void Init(Queue &Q) +{ + Q.data = new int[MAXSIZE]; + // todo list front, rearָ룬Լcount + Q.front = 0; + Q.rear = 0; + Q.count = 0; +} + +// +void EnQueue(Queue &Q, int e) +{ + if (Q.count >= MAXSIZE) // todo list //countж϶Ƿ + printf("\n"); // пӣ˼ + else + { + // todo list //Ԫأβָ+1 + Q.data[Q.rear] = e; + Q.rear++; + // todo list //countֵ + Q.count++; + } +} + +// +void DelQueue(Queue &Q, int &e) +{ + if (Q.count == 0) // todo list //countж϶Ƿ + printf("ӿ\n"); + else + { + // todo list //Ԫأͷָ+1 + e = Q.data[Q.front]; + Q.front++; + // todo list //countֵ + Q.count--; + printf("ԪΪ:%d\n", e); + } +} + +// ж϶ӿ +void IsNull(Queue Q) +{ + if (Q.count == 0) // todo list //countж϶Ƿ + printf("ӿ\n"); + else + printf("Ӳ\n"); +} + +// ʾ +void Display(Queue Q) +{ + while (Q.count > 0) + { + printf("%3d,", Q.data[Q.front]); + // todo list //ͷָƶ + Q.front++; + // todo list //countֵ + Q.count--; + } + printf("\n"); +} + +int main() +{ + Queue Q; + printf("------------------------------------\n"); + printf("1.ʼ\n"); + printf("2.ж϶ǷΪ\n"); + printf("3.\n"); + printf("4.\n"); + printf("5.ʾ\n"); + printf("6.˳\n"); + printf("------------------------------------\n"); + int sel; + while (1) + { + printf("ѡ:"); + scanf("%d", &sel); + // getchar(); + switch (sel) + { + case 1: + Init(Q); + printf("Ѿʼ\n"); + break; + case 2: + IsNull(Q); + break; + case 3: + { + int n, e; + printf("Ԫظ:"); + scanf("%d", &n); + printf("Ҫӵ%dԪ:", n); + for (int i = 0; i < n; i++) + { + scanf("%d", &e); + EnQueue(Q, e); + } + } + break; + case 4: + { + int e; + DelQueue(Q, e); + } + break; + case 5: + printf("Ϊ:"); + Display(Q); + break; + case 6: + exit(0); + } + } +} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d56166c --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 zhilv + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..1d50a7f --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ + + +## 在 `cqucc` 的一些代码 + +1. 目录结构 + ```sh + . + ├── DataStructure # 数据结构 + ├── Server # Node.js 从基础到项目实践 + ├── Spider # Python 网络爬虫基础教程 + └── Web # Web 前端开发技术 + ``` + +2. 目录 +- [数据结构](Web/README.md) +- [`Node.js` 从基础到项目实践](Web/README.md) +- [`Python` 网络爬虫基础教程](Spider/README.md) +- [`Web` 前端开发技术](Web/README.md) + +## 📜 License + +This project is licensed under the [MIT License](LICENSE). diff --git a/Server/1/aa.js b/Server/1/aa.js new file mode 100644 index 0000000..ecdee1f --- /dev/null +++ b/Server/1/aa.js @@ -0,0 +1,14 @@ +const fs = require("fs"); + +fs.readFile(__dirname + "/aa.txt", "utf8", (err, data) => { + if (err) return; + + const content = data + .replace(/(\d+)[、.](?=\s*)/g, "$1、 ") + .replace(/([A-D])[.、](?=\s*)/g, "$1. ") + .replace(/\r?\n([B-D]\.)/g, "\t$1"); + + fs.writeFile(__dirname + "/new.txt", content, "utf8", (err) => { + if (err) return; + }); +}); diff --git a/Server/1/aa.txt b/Server/1/aa.txt new file mode 100644 index 0000000..2917ff4 --- /dev/null +++ b/Server/1/aa.txt @@ -0,0 +1,10 @@ +1、四大名著有哪些? +A.西游记 +B.水浒传 +C.三国演义 +D.红楼梦 +2.我们的口号 +A、键盘敲烂、月薪过万 +B、键盘生灰、垃圾一堆 +C、键盘打烂 +D、键盘放烂 \ No newline at end of file diff --git a/Server/1/new.txt b/Server/1/new.txt new file mode 100644 index 0000000..2289c32 --- /dev/null +++ b/Server/1/new.txt @@ -0,0 +1,4 @@ +1、 四大名著有哪些? +A. 西游记 B. 水浒传 C. 三国演义 D. 红楼梦 +2、 我们的口号 +A. 键盘敲烂、月薪过万 B. 键盘生灰、垃圾一堆 C. 键盘打烂 D. 键盘放烂 \ No newline at end of file diff --git a/Server/2/.gitignore b/Server/2/.gitignore new file mode 100644 index 0000000..031720c --- /dev/null +++ b/Server/2/.gitignore @@ -0,0 +1 @@ +text.txt \ No newline at end of file diff --git a/Server/2/README.md b/Server/2/README.md new file mode 100644 index 0000000..8641054 --- /dev/null +++ b/Server/2/README.md @@ -0,0 +1,20 @@ + + +## `Python` 网络爬虫基础教程 + +### 文件介绍 + +```sh +. +├── 1 # 课堂作业1 +├── 2 # 课堂作业2 +└── tests # 实验文件夹 + ├── test1 # 实验一 + ├── test2 # 实验二 + └── test3 # 实验三 +``` diff --git a/Server/2/main.js b/Server/2/main.js new file mode 100644 index 0000000..88d12ca --- /dev/null +++ b/Server/2/main.js @@ -0,0 +1,6 @@ +const utils = require("./utils"); +const fs = require("fs"); + +const text = fs.readFileSync(__dirname + "/text.txt", "utf8"); + +console.log(utils.word_count(text)); diff --git a/Server/2/utils.js b/Server/2/utils.js new file mode 100644 index 0000000..5b10d28 --- /dev/null +++ b/Server/2/utils.js @@ -0,0 +1,12 @@ +const word_count = function (text) { + const text_list = text.replace(/[、\r?\n,,\s]+/g, " ").split(" "); + let word_obj = {}; + for (const word of text_list) { + word_obj[word] = (word_obj[word] || 0) + 1; + } + return word_obj; +}; + +module.exports = { + word_count, +}; diff --git a/Server/README.md b/Server/README.md new file mode 100644 index 0000000..5088f97 --- /dev/null +++ b/Server/README.md @@ -0,0 +1,18 @@ + + +## `Node.js` 从基础到项目实践 + +### 文件介绍 + +```sh +. +├── images # 图片资源 +├── test1 # 实验一 +├── test2 # 实验二 +└── test3 # 实验三 +``` diff --git a/Server/tests/test1/common.js b/Server/tests/test1/common.js new file mode 100644 index 0000000..d7f60d2 --- /dev/null +++ b/Server/tests/test1/common.js @@ -0,0 +1,133 @@ +const os = require("os"); +const path = require("path"); + +// 格式化字节数为人类可读的单位 +function formatBytes(bytes) { + const size = { + GB: 1024 * 1024 * 1024, + MB: 1024 * 1024, + KB: 1024, + B: 1, + }; + for (const key in size) { + if (bytes >= size[key]) return `${bytes / size[key]} ${key}`; + } +} + +// 工具函数:统一处理路径分隔符为正斜杠 +const formatPath = (pathStr) => { + return pathStr.replace(/\\/g, "/"); // 单个反斜杠替换为正斜杠 +}; + +// 1. 操作系统基本信息 +const getSystemInfo = () => { + return { + osType: os.type(), + osPlatform: os.platform(), + osVersion: os.release(), + osName: os.version(), + arch: os.arch(), + hostname: os.hostname(), + systemStartTime: new Date(os.uptime() * 1000).toLocaleDateString(), + systemRunningTime: `${Math.floor(os.uptime() / 3600)}小时 ${ + Math.floor(os.uptime() % 3600) / 60 + }分钟`, + }; +}; + +// 2. CPU信息 +const getCPUInfo = () => { + const cpus = os.cpus(); + return { + number: cpus.length, + model: cpus[0].model, + speed: cpus[0].speed + "MHz", + }; +}; + +// 3. 内存信息 +const getMemoryInfo = () => { + return { + total: formatBytes(os.totalmem()), + freeMemory: formatBytes(os.freemem()), + useMemory: formatBytes(os.totalmem() - os.freemem()), + useRate: `${Math.round((1 - os.freemem() / os.totalmem()) * 100)}%`, + }; +}; + +// 4. 用户信息 +const getUserInfo = () => { + const userInfo = os.userInfo(); + return { + userName: userInfo.username, + uid: userInfo.uid, + gid: userInfo.gid, + homeDir: formatPath(userInfo.homedir), + shell: userInfo.shell || "unknown", + }; +}; + +// 5. 目录信息 +const getDirInfo = () => { + return { + homeDir: formatPath(os.homedir()), + tmpDir: formatPath(os.tmpdir()), + }; +}; + +// 6. 负载信息 (仅 Unix 系统有效) +const getDutyInfo = () => { + const loadavg = os.loadavg(); + return { + min1: loadavg[0].toFixed(2), + min5: loadavg[1].toFixed(2), + min15: loadavg[2].toFixed(2), + }; +}; + +// 7. 网络接口信息 +const getNetworkInterfaceInfo = () => { + const networkInterfaces = os.networkInterfaces(); + const data = []; + for (const [interfaceName, interfaceInfo] of Object.entries( + networkInterfaces + )) { + let item; + interfaceInfo.forEach((info) => { + item = { + name: interfaceName, + family: info.family, + ip: info.address, + mac: info.mac, + localAddress: info.internal ? true : false, + netmask: info.netmask, + gateway: info.gateway, + }; + }); + data.push(item); + } + return data; +}; + +const getAll = () => { + return { + SystemInfo: getSystemInfo(), + CPUInfo: getCPUInfo(), + MemoryInfo: getMemoryInfo(), + UserInfo: getUserInfo(), + DirInfo: getDirInfo(), + DutyInfo: getDutyInfo(), + NetworkInterfaceInfo: getNetworkInterfaceInfo(), + }; +}; + +module.exports = { + getSystemInfo, + getCPUInfo, + getMemoryInfo, + getUserInfo, + getDirInfo, + getDutyInfo, + getNetworkInterfaceInfo, + getAll, +}; diff --git a/Server/tests/test1/index.html b/Server/tests/test1/index.html new file mode 100644 index 0000000..c1d8f24 --- /dev/null +++ b/Server/tests/test1/index.html @@ -0,0 +1,268 @@ + + + + + + + 系统指标详情 + + + + +
+

系统指标详情

+
+
+
+ + + + + + \ No newline at end of file diff --git a/Server/tests/test1/server.js b/Server/tests/test1/server.js new file mode 100644 index 0000000..d7363cd --- /dev/null +++ b/Server/tests/test1/server.js @@ -0,0 +1,23 @@ +const http = require("http"); +const fs = require("fs"); +const common = require(__dirname + "/common"); + +const server = http.createServer(); + +server.on("request", (req, res) => { + fs.readFile("./index.html", { encoding: "utf8" }, (err, data) => { + if (err) { + res.writeHead(500); + res.end("Error Loading File"); + } else { + res.writeHead(200, { + "content-type": "text/html", + }); + res.end(data.replace("@@@", JSON.stringify(common.getAll()))); + } + }); +}); + +server.listen(3000, () => { + console.log("server is running at http://127.0.0.1:3000"); +}); diff --git a/Server/tests/test2/index.js b/Server/tests/test2/index.js new file mode 100644 index 0000000..8f80282 --- /dev/null +++ b/Server/tests/test2/index.js @@ -0,0 +1,14 @@ +const myModule = require("./myModule"); + +console.log("Auther: ", myModule.auther); +console.log(myModule.greet("Alice")); +console.log("Sum: ", myModule.add(3, 5)); + +const lodash = require("lodash"); + +const array = [1, 2, 3, 4, 5]; +const result = lodash.reverse(array); +console.log("Reverse array: ", result); + +const gt3 = array.filter((n) => lodash.gt(n, 3)); +console.log("Greater than 3: ", gt3); diff --git a/Server/tests/test2/myModule.js b/Server/tests/test2/myModule.js new file mode 100644 index 0000000..b610f70 --- /dev/null +++ b/Server/tests/test2/myModule.js @@ -0,0 +1,15 @@ +const auther = "harry"; + +const greet = (name) => { + return `Hello, ${name}!`; +}; + +const add = (a, b) => { + return a + b; +}; + +module.exports = { + auther, + greet, + add +} diff --git a/Server/tests/test3/.gitignore b/Server/tests/test3/.gitignore new file mode 100644 index 0000000..f52e6f5 --- /dev/null +++ b/Server/tests/test3/.gitignore @@ -0,0 +1,2 @@ +node_modules +pnpm-lock.yaml \ No newline at end of file diff --git a/Server/tests/test3/index.js b/Server/tests/test3/index.js new file mode 100644 index 0000000..74e1559 --- /dev/null +++ b/Server/tests/test3/index.js @@ -0,0 +1,16 @@ +const express = require("express") +const { router } = require("./routes/useRoute") + +const app = express() + +app.use(express.json()) +app.use(router) + + +app.listen("3000", (err) => { + if (err) { + console.log(err); + return + } + console.log("server listen :3000"); +}) diff --git a/Server/tests/test3/package.json b/Server/tests/test3/package.json new file mode 100644 index 0000000..4734218 --- /dev/null +++ b/Server/tests/test3/package.json @@ -0,0 +1,18 @@ +{ + "name": "test3", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "packageManager": "pnpm@10.14.0", + "dependencies": { + "express": "^5.1.0", + "joi": "^18.0.1", + "lodash": "^4.17.21" + } +} diff --git a/Server/tests/test3/routes/useRoute.js b/Server/tests/test3/routes/useRoute.js new file mode 100644 index 0000000..72f2ccb --- /dev/null +++ b/Server/tests/test3/routes/useRoute.js @@ -0,0 +1,100 @@ +const express = require("express") +const { number } = require("joi") +const joi = require("joi") +const lodash = require("lodash") +const router = express.Router() + +router.get("/userId/:userId", (req, res) => { + const userId = req.params.userId; + const { err } = joi.number().validate(userId); + if (err) { + return res.status(400).send("Invaild UserID"); + } + res.send(`user ID is ${userId}`); +}) + +router.get("/userName", (req, res) => { + const { name } = req.query; + + const schema = joi.object({ + name: joi.string().min(2).max(20).required() + }) + const { error } = schema.validate({ name }) + if (error) { + return res.status(400).send("Invaild UserName"); + } + res.send(`User name is ${name}`) +}) + +router.get("/profile", (req, res) => { + res.send("This is the user profile page.") +}) + +router.get("/profile/setting", (req, res) => { + res.send("This is the user profile setting page.") +}) + +const data = [ + { name: 'zs', course: 'app', score: 90 }, + { name: 'zs', course: 'java', score: 80 }, + { name: 'ls', course: 'app', score: 89 }, + { name: 'ls', course: 'java', score: 99 }, + { name: 'ww', course: 'app', score: 78 }, + { name: 'ww', course: 'java', score: 88 }, +] + +router.get("/myScoure", (req, res) => { + const { name } = req.query; + const schema = joi.object({ + name: joi.string().min(2).max(20).required() + }) + const { error } = schema.validate({ name }); + if (error) { + return res.status(400).send("Invaild Name."); + } + + const dataGroup = lodash(data).groupBy("name").get(name) + res.send(dataGroup) +}) + +router.get("/showScoure", (req, res) => { + const dataOrder = lodash.orderBy(data, ["score"], orders = "desc"); + // console.log(dataOrder); + const dataGroup = lodash(data).groupBy("name").map((a) => { + return { + name: a[0].name, + avg: lodash.mean(a.map(e => e.score)), + } + }) + + res.send(dataGroup); +}) + +router.get("/mny", (_req, res) => { + const mnyData = [ + { name: '张三', mny: '9k' }, + { name: '随便', mny: 6666 }, + { name: '王五', mny: '1w' }, + { name: '李四', mny: 15000 }, + ] + const fixData = mnyData.map((d) => + typeof d.mny === "string" + ? { + name: d.name, + mny: parseInt(d.mny = d.mny.replace("w", "0000").replace("k", "000")) + } + : { + name: d.name, + mny: parseInt(d.mny) + } + ) + + const finalData = fixData.filter(d => lodash.gte(d.mny, 9000)); + + res.send(finalData) +}) + +module.exports = { + router +} + diff --git a/Spider/.gitignore b/Spider/.gitignore new file mode 100644 index 0000000..ca8bbeb --- /dev/null +++ b/Spider/.gitignore @@ -0,0 +1 @@ +data.csv \ No newline at end of file diff --git a/Spider/README.md b/Spider/README.md new file mode 100644 index 0000000..34d4d11 --- /dev/null +++ b/Spider/README.md @@ -0,0 +1,15 @@ + + +## `Python` 网络爬虫基础教程 + +### 文件介绍 + +```sh +. +└── test1.py # 获取研招网数据 +``` diff --git a/Spider/test1.py b/Spider/test1.py new file mode 100644 index 0000000..15cb266 --- /dev/null +++ b/Spider/test1.py @@ -0,0 +1,74 @@ +import csv +import requests +from lxml import etree + + +class YXZS: + def __init__(self) -> None: + self.url = "https://yz.chsi.com.cn/sch/?start={}" + self.file = open("./data.csv", "+a", encoding="utf-8", newline="") + self.file.write("学校名称,学校性质,招生简章的链接,调剂办法的链接\n") + + def get_html(self, page=1): + resp = requests.get( + self.url.format((page - 1) * 20), + headers={ + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36 Edg/140.0.0.0", + "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", + "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6", + }, + ) + if resp.status_code == 200: + return resp.text + return "" + + def parse_html(self, html_text: str): + html = etree.HTML(html_text) + schs = html.xpath('//div[@class="sch-item"]') + for sch in schs: + item = { + "name": ( + sch.xpath( + './/a[@class="name js-yxk-yxmc text-decoration-none"]/text()' + )[0].strip() + if sch.xpath( + './/a[@class="name js-yxk-yxmc text-decoration-none"]/text()' + ) + else "unkonwn" + ), + "tag": ( + sch.xpath('.//span[@class="sch-tag"]/text()')[0].strip() + if sch.xpath('.//span[@class="sch-tag"]/text()') + else "unkonwn" + ), + "href1": ( + "https://yz.chsi.com.cn" + + sch.xpath('.//div[@class="sch-link"]/a[2]/@href')[0] + if sch.xpath('.//div[@class="sch-link"]/a[2]/@href') + else "unkonwn" + ), + "href2": ( + "https://yz.chsi.com.cn" + + sch.xpath('.//div[@class="sch-link"]/a[4]/@href')[0] + if sch.xpath('.//div[@class="sch-link"]/a[4]/@href') + else "unkonwn" + ), + } + self.save_data(item) + + def save_data(self, item): + writer = csv.DictWriter(self.file, fieldnames=item.keys()) + writer.writerow(item) + + def run(self): + for i in range(0, 47): + print("正在获取第{}页".format(i + 1)) + html_text = self.get_html(page=i) + if html_text == "": + print("第{}页获取的内容为空") + continue + self.parse_html(html_text) + + +if __name__ == "__main__": + YXZS().run() diff --git a/Web/README.md b/Web/README.md new file mode 100644 index 0000000..14c9702 --- /dev/null +++ b/Web/README.md @@ -0,0 +1,18 @@ + + +## `Web` 前端开发技术 + +### 文件介绍 + +```sh +. +├── images # 图片资源 +├── test1 # 实验一 +├── test2 # 实验二 +└── test3 # 实验三 +``` diff --git a/Web/images/relax.png b/Web/images/relax.png new file mode 100644 index 0000000..ea0e237 Binary files /dev/null and b/Web/images/relax.png differ diff --git a/Web/test1/plan.html b/Web/test1/plan.html new file mode 100644 index 0000000..3416bb6 --- /dev/null +++ b/Web/test1/plan.html @@ -0,0 +1,26 @@ + + + + + + + Document + + + +

我的待办事项与学习资源

+
    +
  1. 周一: 完成工作报告
  2. +
  3. 周二: 参加项目会议
  4. +
  5. 周三: 准备新方案的资料收集
  6. +
+ +

版权所有 © zhilv

+ 图片 + + + \ No newline at end of file diff --git a/Web/test1/poem.html b/Web/test1/poem.html new file mode 100644 index 0000000..ae88723 --- /dev/null +++ b/Web/test1/poem.html @@ -0,0 +1,36 @@ + + + + + + + Document + + + + +

李白《静夜思》赏析

+

《静夜思》是唐代诗人李白的经典诗作,它短小精悍,却蕴含着深深的思乡之情。

+ +

原诗内容

+

床前明月光,
+ 疑是地上霜。
+ 举头望明月,
+ 低头思故乡。

+ +

在诗中,“床前”这个词被加粗(床前),起到了一定的强调作用,让读者首先注意到诗人所处的位置。
+ 而“疑是地上霜”这句诗,通过“霜”这个字形象地描绘出月光的皎洁清冷,仿佛地上结了一层霜,这种感觉通过简单的文字就传达给了读者。
+ 当诗人“举头①望明月”时,这里的上标数字①可以用来做注释标记,表示对“举头”这个动作可能存在的特殊解读或者引用来源等,明月成为了引发思乡之情的重要媒介。
+ 最后“低头思故乡”,诗人深沉地(用em标签表示情感上的强调)陷入对故乡的思念之中。

+ +
+

这首诗虽然没有华丽的辞藻,但每一个字都像是经过精心雕琢,强烈地(用strong标签表示语义上的强调)触动着读者内心深处的思乡情感,成为了千古流传的佳作。

+ + + \ No newline at end of file diff --git a/Web/test2/attri_practice.html b/Web/test2/attri_practice.html new file mode 100644 index 0000000..0fd77bd --- /dev/null +++ b/Web/test2/attri_practice.html @@ -0,0 +1,53 @@ + + + + + + + Document + + + + +

一个段落

+ 点击跳转到菜鸟教程 + + + + \ No newline at end of file diff --git a/Web/test2/news.html b/Web/test2/news.html new file mode 100644 index 0000000..30fa0de --- /dev/null +++ b/Web/test2/news.html @@ -0,0 +1,23 @@ + + + + + + + 新闻 + + + + +

  昨天上午,南京国际博览中心金陵会议中心内欢声笑语,春意盎然,省委、省政府在这里举行春节团拜会。 + Yesterday morning, the Jinling Conference Center of Nanjing International Expo Center was filled with laughter + and joy, and the provincial party committee and government held a Spring Festival gathering here.

+ + + \ No newline at end of file diff --git a/Web/test2/product.html b/Web/test2/product.html new file mode 100644 index 0000000..da58f97 --- /dev/null +++ b/Web/test2/product.html @@ -0,0 +1,39 @@ + + + + + + + Document + + + + +

设置文字装饰及大小写转换

+

Chongqing, abbreviated as "Yu", is a municipality directly under the central and western regions of China, famous + for its mountainous city characteristics, hotpot culture, and the beautiful scenery of the confluence of the + Yangtze River and Jialing River.

+

Sichuan, abbreviated as "Chuan" or "Shu", is located in southwestern China and is a province known for + its + magnificent natural scenery, rich cultural heritage, and spicy cuisine.

+

Guizhou, abbreviated as "Qian" or "Gui", is located in southwestern China and is a province renowned + for its + diverse ethnic cultures, spectacular karst landforms, and beautiful natural landscapes.

+ + + \ No newline at end of file diff --git a/Web/test3/table.html b/Web/test3/table.html new file mode 100644 index 0000000..aaab5c6 --- /dev/null +++ b/Web/test3/table.html @@ -0,0 +1,77 @@ + + + + + + + Document + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
简易学生表
姓名单位学号
2024-2025学年王小品商学院110204
李中财经学院120204
胡三大数据学院130504
李白人工智能学院100244
重庆城市科技学院
+ + + \ No newline at end of file diff --git a/Web/test3/tableTitle.css b/Web/test3/tableTitle.css new file mode 100644 index 0000000..643cf71 --- /dev/null +++ b/Web/test3/tableTitle.css @@ -0,0 +1,7 @@ +caption { + font-weight: bold; + font-size: 20px; + color: #0daeba; + background-color: bisque; + height: 36px; +}