npm-run-all 使用实践
参考: npm-run-all
背景
在前端开发中,你是否存在以下烦恼:
- 写 package.json 的 scripts 命令时,命令太过冗长,例如编译命令
build
需要执行清理clean
, 编译cssbuild:css
, 编译jsbuild:js
, 编译htmlbuild:html
命令,则build
命令需要写成build: npm run clean && npm run build:css && npm run build:js && npm run build:html
,这个命令太过冗长,npm run
都是重复的,能不能写成build: clean build:css build:js build:html
,甚至能不能更简单地写成build: clean build:*
。 - 通常
build
的过程是先进行类型检查,后进行编译:build: npm run typecheck && vite build
,两者是串行的关系,能不能使两个命令并行执行以加快编译速度?
如果你也有类似烦恼,相信这篇文章对你有用。
安装
# npm 安装
$ npm install npm-run-all --save-dev
# yarn 安装
$ yarn add npm-run-all --dev
# pnpm 安装
$ pnpm add -D npm-run-all
使用
npm-run-all
包提供了3个命令:npm-run-all
, run-s
, run-p
。
最主要的命令是 npm-run-all
,我们可以使用该命令创建复杂的命令计划。run-s
和 run-p
是简写命令,run-s
用于串行任务,run-p
用于并行任务。
npm-run-all
创建一个文件夹,并通过 pnpm init
将该文件夹初始化为一个项目。在该项目下创建4个脚本文件:
- clean.sh:
echo "$(date): start clean"
sleep 1
echo "$(date): clean finished!"
- build-css.sh
echo "$(date): start build:css"
sleep 1
echo "$(date): build:css finished!"
- build-js.sh
echo "$(date): start build:js"
sleep 3
echo "$(date): build:js finished!"
- build-html.sh
echo "$(date): start build:html"
sleep 1
echo "$(date): build:html finished!"
串行执行多个命令
为 package.json 添加脚本命令:
{"scripts": {"clean": "./clean.sh","build:css": "./build-css.sh","build:html": "./build-html.sh","build:js": "./build-js.sh","build": "npm-run-all clean build:css build:js build:html"}
}
使用 npm-run-all 后 build 命令简化了很多,执行 pnpm build
结果为:
> t1@1.0.0 build /Users/foolishflyfox/Code/Year2024/Mon10/day14/t1
> npm-run-all clean build:css build:js build:html> t1@1.0.0 clean /Users/foolishflyfox/Code/Year2024/Mon10/day14/t1
> ./clean.sh2024年10月14日 星期一 17时35分17秒 CST: start clean
2024年10月14日 星期一 17时35分18秒 CST: clean finished!> t1@1.0.0 build:css /Users/foolishflyfox/Code/Year2024/Mon10/day14/t1
> ./build-css.sh2024年10月14日 星期一 17时35分18秒 CST: start build:css
2024年10月14日 星期一 17时35分19秒 CST: build:css finished!> t1@1.0.0 build:js /Users/foolishflyfox/Code/Year2024/Mon10/day14/t1
> ./build-js.sh2024年10月14日 星期一 17时35分19秒 CST: start build:js
2024年10月14日 星期一 17时35分22秒 CST: build:js finished!> t1@1.0.0 build:html /Users/foolishflyfox/Code/Year2024/Mon10/day14/t1
> ./build-html.sh2024年10月14日 星期一 17时35分23秒 CST: start build:html
2024年10月14日 星期一 17时35分24秒 CST: build:html finished!
可以看到 clean
, build:css
, build:js
, build:html
串行执行了。
用通配符简化命令
将 build
命令修改为 npm-run-all clean build:*
,执行 pnpm build
结果为:
> t1@1.0.0 build /Users/foolishflyfox/Code/Year2024/Mon10/day14/t1
> npm-run-all clean build:*> t1@1.0.0 clean /Users/foolishflyfox/Code/Year2024/Mon10/day14/t1
> ./clean.sh2024年10月14日 星期一 17时39分45秒 CST: start clean
2024年10月14日 星期一 17时39分46秒 CST: clean finished!> t1@1.0.0 build:css /Users/foolishflyfox/Code/Year2024/Mon10/day14/t1
> ./build-css.sh2024年10月14日 星期一 17时39分46秒 CST: start build:css
2024年10月14日 星期一 17时39分47秒 CST: build:css finished!> t1@1.0.0 build:html /Users/foolishflyfox/Code/Year2024/Mon10/day14/t1
> ./build-html.sh2024年10月14日 星期一 17时39分48秒 CST: start build:html
2024年10月14日 星期一 17时39分49秒 CST: build:html finished!> t1@1.0.0 build:js /Users/foolishflyfox/Code/Year2024/Mon10/day14/t1
> ./build-js.sh2024年10月14日 星期一 17时39分49秒 CST: start build:js
2024年10月14日 星期一 17时39分52秒 CST: build:js finished!
可以看到 clean
, build:css
, build:html
, build:js
串行执行了。执行 build:*
时,执行顺序按命令定义的先后顺序进行。
多个命令并行执行
将 build
命令修改为 npm-run-all --parallel clean build:*
,执行结果为:
pnpm build> t1@1.0.0 build /Users/foolishflyfox/Code/Year2024/Mon10/day14/t1
> npm-run-all --parallel clean build:*> t1@1.0.0 build:css /Users/foolishflyfox/Code/Year2024/Mon10/day14/t1
> ./build-css.sh> t1@1.0.0 clean /Users/foolishflyfox/Code/Year2024/Mon10/day14/t1
> ./clean.sh> t1@1.0.0 build:html /Users/foolishflyfox/Code/Year2024/Mon10/day14/t1
> ./build-html.sh> t1@1.0.0 build:js /Users/foolishflyfox/Code/Year2024/Mon10/day14/t1
> ./build-js.sh2024年10月14日 星期一 17时49分47秒 CST: start build:css
2024年10月14日 星期一 17时49分47秒 CST: start build:html
2024年10月14日 星期一 17时49分47秒 CST: start clean
2024年10月14日 星期一 17时49分47秒 CST: start build:js
2024年10月14日 星期一 17时49分48秒 CST: build:html finished!
2024年10月14日 星期一 17时49分48秒 CST: build:css finished!
2024年10月14日 星期一 17时49分48秒 CST: clean finished!
2024年10月14日 星期一 17时49分50秒 CST: build:js finished!
可以看到4个命令已经并行执行了。上面 build
命令在 linux 可以写成 npm run clean & npm run build:css & npm run build:js & npm run build:html
,执行结果为:
> t1@1.0.0 build /Users/foolishflyfox/Code/Year2024/Mon10/day14/t1
> npm run clean & npm run build:css & npm run build:js & npm run build:html> t1@1.0.0 clean
> ./clean.sh> t1@1.0.0 build:js
> ./build-js.sh> t1@1.0.0 build:html
> ./build-html.sh> t1@1.0.0 build:css
> ./build-css.sh2024年10月14日 星期一 19时21分14秒 CST: start build:css
2024年10月14日 星期一 19时21分14秒 CST: start build:js
2024年10月14日 星期一 19时21分14秒 CST: start build:html
2024年10月14日 星期一 19时21分14秒 CST: start clean
2024年10月14日 星期一 19时21分15秒 CST: build:html finished!
2024年10月14日 星期一 19时21分15秒 CST: build:css finished!
2024年10月14日 星期一 19时21分15秒 CST: clean finished!
2024年10月14日 星期一 19时21分17秒 CST: build:js finished!
也有并行执行的效果,不过问题在于 Windows 下的 cmd.exe 并不能识别 &
,跨平台存在问题。
另外,因为 &
表示命令后台运行,因此并不是在 build 执行完以后才退出命令行。因为最后一条命令 npm run build:html
不是后台执行,因此命令行退出时间取决于该命令的执行时间,该命令延时1s,而执行时间最长的 npm run build:js
延时3s,因此在命令行退出时,npm run build:js
并没有执行完毕,会导致在 pnpm build
命令结束2s后才在终端输出 2024年10月14日 星期一 19时21分17秒 CST: build:js finished!
的问题。
多命令并行时一个命令执行失败
并行执行时,如果某个命令执行的退出码不是0,则正在执行的命令将被杀死。例如,我们将 build-html.sh
修改为:
echo "$(date): start build:html"
sleep 2
exit 1
echo "$(date): build:html finished!"
则执行 pnpm build
的结果为:
> t1@1.0.0 build /Users/foolishflyfox/Code/Year2024/Mon10/day14/t1
> npm-run-all --parallel clean build:*> t1@1.0.0 clean /Users/foolishflyfox/Code/Year2024/Mon10/day14/t1
> ./clean.sh> t1@1.0.0 build:css /Users/foolishflyfox/Code/Year2024/Mon10/day14/t1
> ./build-css.sh> t1@1.0.0 build:html /Users/foolishflyfox/Code/Year2024/Mon10/day14/t1
> ./build-html.sh> t1@1.0.0 build:js /Users/foolishflyfox/Code/Year2024/Mon10/day14/t1
> ./build-js.sh2024年10月14日 星期一 19时32分48秒 CST: start clean
2024年10月14日 星期一 19时32分48秒 CST: start build:css
2024年10月14日 星期一 19时32分48秒 CST: start build:html
2024年10月14日 星期一 19时32分48秒 CST: start build:js
2024年10月14日 星期一 19时32分49秒 CST: clean finished!
2024年10月14日 星期一 19时32分49秒 CST: build:css finished!ELIFECYCLE Command failed with exit code 1.ELIFECYCLE Command failed.
ERROR: "build:html" exited with 1.ELIFECYCLE Command failed with exit code 1.
可以看到,在 build:html
错误退出前执行完毕的 clean
, build:css
都输出完成信息,而执行时间比 build:html
长的 build:js
因为 build:html
的错误退出,导致无法继续执行,没有输出完成信息。
串行与并行混合执行
上面并行的例子中存在一个问题,因为 clean
和其他编译命令并行,可能导致刚编译好的文件被清理掉,我们要的结果是先执行 clean
命令,执行完成后再并行执行3个编译命令。可以将 build
命令修改为 npm-run-all --silent clean --parallel build:*
,执行结果为:
> t1@1.0.0 build /Users/foolishflyfox/Code/Year2024/Mon10/day14/t1
> npm-run-all clean --silent --parallel build:*2024年10月14日 星期一 21时38分20秒 CST: start clean
2024年10月14日 星期一 21时38分21秒 CST: clean finished!
2024年10月14日 星期一 21时38分21秒 CST: start build:html
2024年10月14日 星期一 21时38分21秒 CST: start build:js
2024年10月14日 星期一 21时38分21秒 CST: start build:css
2024年10月14日 星期一 21时38分22秒 CST: build:html finished!
2024年10月14日 星期一 21时38分22秒 CST: build:css finished!
2024年10月14日 星期一 21时38分25秒 CST: build:js finished!
如果希望执行顺序为: 先执行 clean
, 再并行执行 build:css build:js
, 最后执行 build:html
,可以将 build
命令改为: npm-run-all --silent clean --parallel build:css build:js --sequential build:html
, 执行结果为:
> t1@1.0.0 build /Users/foolishflyfox/Code/Year2024/Mon10/day14/t1
> npm-run-all --silent clean --parallel build:css build:js --sequential build:html2024年10月14日 星期一 21时42分49秒 CST: start clean
2024年10月14日 星期一 21时42分50秒 CST: clean finished!
2024年10月14日 星期一 21时42分50秒 CST: start build:js
2024年10月14日 星期一 21时42分50秒 CST: start build:css
2024年10月14日 星期一 21时42分51秒 CST: build:css finished!
2024年10月14日 星期一 21时42分53秒 CST: build:js finished!
2024年10月14日 星期一 21时42分54秒 CST: start build:html
2024年10月14日 星期一 21时42分55秒 CST: build:html finished!
--sequential
可以改为 --serial
。
例如: npm-run-all a b --parallel c d --sequential e f --parallel g h i
或 npm-run-all a b --parallel c d --serial e f --parallel g h i
的执行步骤为:
- 串行执行,先执行a,再执行b
- b 执行完后,并行执行 c 和 d
- c 和 d 都执行完后,串行执行 e 和 f
- f 执行完后,并行执行 g、h 和 i
通配符
之前我们看到 npm-run-all build:*
,其中 *
就是一个通配符,并且分隔符不一定是冒号,例如我们将 package.json 中的 scripts
改为:
{"scripts": {"clean": "./clean.sh","build_css": "./build-css.sh","build_html": "./build-html.sh","build_js": "./build-js.sh","build": "npm-run-all --silent build_*"}
}
执行 pnpm build
的结果为:
> t1@1.0.0 build /Users/foolishflyfox/Code/Year2024/Mon10/day14/t1
> npm-run-all --silent build_*2024年10月14日 星期一 21时44分45秒 CST: start build:css
2024年10月14日 星期一 21时44分46秒 CST: build:css finished!
2024年10月14日 星期一 21时44分47秒 CST: start build:html
2024年10月14日 星期一 21时44分48秒 CST: build:html finished!
2024年10月14日 星期一 21时44分48秒 CST: start build:js
2024年10月14日 星期一 21时44分51秒 CST: build:js finished!
也是可以正常执行的。
甚至 *
也不一定在最后,例如 build
改为 npm-run-all --silent build_*s
,将只执行 build:css
和 build:js
,执行结果为:
> t1@1.0.0 build /Users/foolishflyfox/Code/Year2024/Mon10/day14/t1
> npm-run-all --silent build_*s2024年10月14日 星期一 21时45分53秒 CST: start build:css
2024年10月14日 星期一 21时45分54秒 CST: build:css finished!
2024年10月14日 星期一 21时45分54秒 CST: start build:js
2024年10月14日 星期一 21时45分57秒 CST: build:js finished!
传入参数
新建两个脚本用于接收命令行参数:
- foo.sh:
echo "foo: [1]=$1, [2]=$2, [3]=$3, [4]=$4, [5]=$5, [6]=$6"
- bar.sh:
echo "bar: [1]=$1, [2]=$2, [3]=$3, [4]=$4, [5]=$5, [6]=$6"
为 scripts 添加如下内容:
{"scripts": {"test:foo": "./foo.sh","test:bar": "./bar.sh","test": "npm-run-all --parallel \"test:* 1 abc\"",}
}
则执行的结果为:
> t1@1.0.0 test /Users/foolishflyfox/Code/Year2024/Mon10/day14/t1
> npm-run-all --parallel "test:* 1 abc"> t1@1.0.0 test:foo /Users/foolishflyfox/Code/Year2024/Mon10/day14/t1
> ./foo.sh "1" "abc"> t1@1.0.0 test:bar /Users/foolishflyfox/Code/Year2024/Mon10/day14/t1
> ./bar.sh "1" "abc"foo: [1]=1, [2]=abc, [3]=, [4]=, [5]=, [6]=
bar: [1]=1, [2]=abc, [3]=, [4]=, [5]=, [6]=
上述的 test
命令改为 "test": "npm-run-all --parallel \"test:foo 1 abc\" \"test:bar 1 abc\""
也是相同的效果。
参数占位符
如果我们希望在执行命令时,再通过命令行传入参数,可以使用参数占位符。下面的例子演示了参数占位符的使用:
{"test2": "npm-run-all \"test:foo {1}\" \"test:foo {1} {2}\" \"test:foo {@}\" \"test:foo {*}\" --"
}
注意,最后的 --
不可少,否则参数会被作为命令,例如没有 --
时执行 pnpm test2 a
,结果为:
> t1@1.0.0 test2 /Users/foolishflyfox/Code/Year2024/Mon10/day14/t1
> npm-run-all "test:foo {1}" "test:foo {1} {2}" "test:foo {@}" "test:foo {*}" "a"ERROR: Task not found: "a"ELIFECYCLE Command failed with exit code 1.
可以看到 a 被当做了一个任务。
加上 --
后,执行 pnpm test2 1 aaa 1xy
的结果为:
> t1@1.0.0 test2 /Users/foolishflyfox/Code/Year2024/Mon10/day14/t1
> npm-run-all "test:foo {1}" "test:foo {1} {2}" "test:foo {@}" "test:foo {*}" -- "1" "aaa" "1xy"> t1@1.0.0 test:foo /Users/foolishflyfox/Code/Year2024/Mon10/day14/t1
> ./foo.sh "1"foo: [1]=1, [2]=, [3]=, [4]=, [5]=, [6]=> t1@1.0.0 test:foo /Users/foolishflyfox/Code/Year2024/Mon10/day14/t1
> ./foo.sh "1" "aaa"foo: [1]=1, [2]=aaa, [3]=, [4]=, [5]=, [6]=> t1@1.0.0 test:foo /Users/foolishflyfox/Code/Year2024/Mon10/day14/t1
> ./foo.sh "1" "aaa" "1xy"foo: [1]=1, [2]=aaa, [3]=1xy, [4]=, [5]=, [6]=> t1@1.0.0 test:foo /Users/foolishflyfox/Code/Year2024/Mon10/day14/t1
> ./foo.sh "1 aaa 1xy"foo: [1]=1 aaa 1xy, [2]=, [3]=, [4]=, [5]=, [6]=
在例子中可以很清楚的看出不同占位符的区别:
{1}
,{2}
, … : 表示一个参数,{1}
表示第一个参数,{2}
表示第二个参数;{@}
: 表示所有参数;{*}
: 将所有参数合并为一个参数;
run-s / run-p
run-s
是 npm-run-all -s
或 npm-run-all --series
或 npm-run-all --sequential
的简写,表示串行执行命令。
run-p
是 npm-run-all -p
或 npm-run-all --parallel
的简写,表示并行执行命令。
scripts 中添加命令 "build-s": "run-s --silent build:*"
,执行结果为:
> t1@1.0.0 build-s /Users/foolishflyfox/Code/Year2024/Mon10/day14/t1
> run-s --silent build:*2024年10月14日 星期一 21时24分26秒 CST: start build:css
2024年10月14日 星期一 21时24分27秒 CST: build:css finished!
2024年10月14日 星期一 21时24分27秒 CST: start build:html
2024年10月14日 星期一 21时24分28秒 CST: build:html finished!
2024年10月14日 星期一 21时24分29秒 CST: start build:js
2024年10月14日 星期一 21时24分32秒 CST: build:js finished!
可以看到3个build命令是串行的。这里使用了 --silent
参数,减少系统的日志输出。
添加命令 "build-p": "run-p --silent build:*"
,执行结果为:
> t1@1.0.0 build-p /Users/foolishflyfox/Code/Year2024/Mon10/day14/t1
> run-p --silent build:*2024年10月14日 星期一 21时26分48秒 CST: start build:html
2024年10月14日 星期一 21时26分48秒 CST: start build:js
2024年10月14日 星期一 21时26分48秒 CST: start build:css
2024年10月14日 星期一 21时26分49秒 CST: build:html finished!
2024年10月14日 星期一 21时26分49秒 CST: build:css finished!
2024年10月14日 星期一 21时26分51秒 CST: build:js finished!
可以看到3个命令是并行执行的。
相关文章:
npm-run-all 使用实践
参考: npm-run-all 背景 在前端开发中,你是否存在以下烦恼: 写 package.json 的 scripts 命令时,命令太过冗长,例如编译命令 build 需要执行清理 clean, 编译css build:css, 编译js build:js, 编译html build:html 命令,则 bui…...
【CCPC】The 2021 CCPC Guilin Onsite (XXII Open Cup, Grand Prix of EDG) K
Tax #图论 #最短路 #搜索 #暴力 题目描述 JB received his driver’s license recently. To celebrate this fact, JB decides to drive to other cities in Byteland. There are n n n cities and m m m bidirectional roads in Byteland, labeled by 1 , 2 , … , n 1,…...
selenium的实际使用
1.标签页的切换 #获取当前所有的窗口 curdriver.window_handles #根据窗口索引进行切换 driver.switch_to.window(cur[1]) from selenium import webdriverimport timedriver webdriver.Chrome()driver.get(http://www.baidu.com)time.sleep(1)eledriver.find_element_by…...

OpenShift 4 - 云原生备份容灾 - Velero 和 OADP 基础篇
《OpenShift 4.x HOL教程汇总》 说明: 本文主要说明能够云原生备份容灾的开源项目 Velero 及其红帽扩展项目 OADP 的概念和架构篇。操作篇见《OpenShift 4 - 使用 OADP 对容器应用进行备份和恢复(附视频) 》 Velero 和 OADP 包含的功能和模…...

javaWeb项目-Springboot+vue-校园论坛系统功能介绍
本项目源码(点击下方链接下载):java-springbootvue-xx学校校园论坛信息系统实现源码(项目源码-说明文档)资源-CSDN文库 项目关键技术 开发工具:IDEA 、Eclipse 编程语言: Java 数据库: MySQL5.7 框架:ssm、Springboot…...

centors7升级GLIBC2.18
错误来源:找不到GLIBC2.18,因为glibc的版本是2.17 网上大多教程方法,反正我是行不通: 方法1:更新源,然后使用yum安装更新 方法2:下载源码,configrue,make执行 wget h…...
基于深度学习的异常检测
基于深度学习的异常检测是一项重要的研究领域,主要用于识别数据中的异常样本或行为。异常检测广泛应用于多个领域,如网络安全、金融欺诈检测、工业设备预测性维护、医疗诊断等。传统的异常检测方法通常依赖于统计分析或规则,但随着数据复杂性…...
深入理解 SQL 中的高级数据处理特性:约束、索引和触发器
在 SQL(Structured Query Language)中,除了基本的查询、插入、更新和删除操作外,还有一些高级的数据处理特性,它们对于确保数据的完整性、提高查询性能以及实现自动化的数据处理起着至关重要的作用。这些特性包括约束、…...
IC验证面试中常问知识点总结(七)附带详细回答!!!
15、 TLM通信 15.1 实现两个组件之间的通信有哪几种方法?分别什么特点? 最简单的方法就是使用全局变量,在monitor里对此全局变量进行赋值,在scoreboard里监测此全局变量值的改变。这种方法简单、直接,不过要避免使用全局变量,滥用全局变量只会造成灾难性的后果。 稍微复…...

【前端】如何制作一个自己的网页(8)
以下内容接上文。 CSS的出现,使得网页的样式与内容分离开来。 HTML负责网页中有哪些内容,CSS负责以哪种样式来展现这些内容。因此,CSS必须和HTML协同工作,那么如何在HTML中引用CSS呢? CSS的引用方式有三种࿱…...
Java之模块化详解
Java模块化,作为Java 9引入的一项重大特性,通过Java Platform Module System (JPMS) 实现,为Java开发者提供了更高级别的封装和依赖管理机制。这一特性旨在解决Java应用的封装性、可维护性和性能问题,使得开发者能够构建更加结构化…...

HTB:Knife[WriteUP]
目录 连接至HTB服务器并启动靶机 1.How many TCP ports are open on Knife? 2.What version of PHP is running on the webserver? 并没有我们需要的信息,接着使用浏览器访问靶机80端口 尝试使用ffuf对靶机Web进行一下目录FUZZ 使用curl访问该文件获取HTTP头…...

MOE论文详解(4)-GLaM
2022年google在GShard之后发表另一篇跟MoE相关的paper, 论文名为GLaM (Generalist Language Model), 最大的GLaM模型有1.2 trillion参数, 比GPT-3大7倍, 但成本只有GPT-3的1/3, 同时效果也超过GPT-3. 以下是两者的对比: 跟之前模型对比如下, 跟GShard和Switch-C相比, GLaM是第一…...
LeetCode322:零钱兑换
题目链接:322. 零钱兑换 - 力扣(LeetCode) 代码如下 class Solution { public:int coinChange(vector<int>& coins, int amount) {vector<int> dp(amount 1, INT_MAX);dp[0] 0;for(int i 0; i < coins.size(); i){fo…...
速盾:高防 cdn 提供 cc 防护?
在当今网络环境中,网站面临着各种安全威胁,其中 CC(Challenge Collapsar)攻击是一种常见的分布式拒绝服务攻击方式。高防 CDN(Content Delivery Network,内容分发网络)作为一种有效的网络安全防…...
【大数据应用开发】2023年全国职业院校技能大赛赛题第10套
如有需要备赛资料和远程培训,可私博主,详细了解 目录 任务A:大数据平台搭建(容器环境)(15分) 任务B:离线数据处理(25分) 任务C:数据挖掘(10分) 任务D:数据采集与实时计算(20分) 任务E:数据可视化(15分) 任务F:综合分析(10分) 任务A:大数据平台搭…...

【源码部署】解决SpringBoot无法加载yml文件配置,总是使用8080端口方案
打开idea,file ->Project Structure 找到Modules ,在右侧找到resource目录,是否指定了resource,点击对应文件夹会有提示...

2010年国赛高教杯数学建模B题上海世博会影响力的定量评估解题全过程文档及程序
2010年国赛高教杯数学建模 B题 上海世博会影响力的定量评估 2010年上海世博会是首次在中国举办的世界博览会。从1851年伦敦的“万国工业博览会”开始,世博会正日益成为各国人民交流历史文化、展示科技成果、体现合作精神、展望未来发展等的重要舞台。请你们选择感兴…...
使用nginx配置静态页面展示
文章目录 前言正文安装nginx配置 前言 目前有一系列html文件,比如sphinx通过make html输出的文件,需要通过ip远程访问,这就需要ngnix 主要内容参考:https://blog.csdn.net/qq_32460819/article/details/121131062 主要针对在do…...
[IOI2018] werewolf 狼人(Kruskal重构树 + 主席树)
https://www.luogu.com.cn/problem/P4899 首先,我们肯定要建两棵Kruskal重构树的,然后判两棵子树是否有相同编号节点 这是个经典问题,我们首先可以拍成dfs序,然后映射过去,然后相当于是判断一个区间是否有 [ l , r …...

(LeetCode 每日一题) 3442. 奇偶频次间的最大差值 I (哈希、字符串)
题目:3442. 奇偶频次间的最大差值 I 思路 :哈希,时间复杂度0(n)。 用哈希表来记录每个字符串中字符的分布情况,哈希表这里用数组即可实现。 C版本: class Solution { public:int maxDifference(string s) {int a[26]…...

中南大学无人机智能体的全面评估!BEDI:用于评估无人机上具身智能体的综合性基准测试
作者:Mingning Guo, Mengwei Wu, Jiarun He, Shaoxian Li, Haifeng Li, Chao Tao单位:中南大学地球科学与信息物理学院论文标题:BEDI: A Comprehensive Benchmark for Evaluating Embodied Agents on UAVs论文链接:https://arxiv.…...
大学生职业发展与就业创业指导教学评价
这里是引用 作为软工2203/2204班的学生,我们非常感谢您在《大学生职业发展与就业创业指导》课程中的悉心教导。这门课程对我们即将面临实习和就业的工科学生来说至关重要,而您认真负责的教学态度,让课程的每一部分都充满了实用价值。 尤其让我…...

C++使用 new 来创建动态数组
问题: 不能使用变量定义数组大小 原因: 这是因为数组在内存中是连续存储的,编译器需要在编译阶段就确定数组的大小,以便正确地分配内存空间。如果允许使用变量来定义数组的大小,那么编译器就无法在编译时确定数组的大…...

推荐 github 项目:GeminiImageApp(图片生成方向,可以做一定的素材)
推荐 github 项目:GeminiImageApp(图片生成方向,可以做一定的素材) 这个项目能干嘛? 使用 gemini 2.0 的 api 和 google 其他的 api 来做衍生处理 简化和优化了文生图和图生图的行为(我的最主要) 并且有一些目标检测和切割(我用不到) 视频和 imagefx 因为没 a…...
LangChain知识库管理后端接口:数据库操作详解—— 构建本地知识库系统的基础《二》
这段 Python 代码是一个完整的 知识库数据库操作模块,用于对本地知识库系统中的知识库进行增删改查(CRUD)操作。它基于 SQLAlchemy ORM 框架 和一个自定义的装饰器 with_session 实现数据库会话管理。 📘 一、整体功能概述 该模块…...

Linux 中如何提取压缩文件 ?
Linux 是一种流行的开源操作系统,它提供了许多工具来管理、压缩和解压缩文件。压缩文件有助于节省存储空间,使数据传输更快。本指南将向您展示如何在 Linux 中提取不同类型的压缩文件。 1. Unpacking ZIP Files ZIP 文件是非常常见的,要在 …...

手机平板能效生态设计指令EU 2023/1670标准解读
手机平板能效生态设计指令EU 2023/1670标准解读 以下是针对欧盟《手机和平板电脑生态设计法规》(EU) 2023/1670 的核心解读,综合法规核心要求、最新修正及企业合规要点: 一、法规背景与目标 生效与强制时间 发布于2023年8月31日(OJ公报&…...

【堆垛策略】设计方法
堆垛策略的设计是积木堆叠系统的核心,直接影响堆叠的稳定性、效率和容错能力。以下是分层次的堆垛策略设计方法,涵盖基础规则、优化算法和容错机制: 1. 基础堆垛规则 (1) 物理稳定性优先 重心原则: 大尺寸/重量积木在下…...
第八部分:阶段项目 6:构建 React 前端应用
现在,是时候将你学到的 React 基础知识付诸实践,构建一个简单的前端应用来模拟与后端 API 的交互了。在这个阶段,你可以先使用模拟数据,或者如果你的后端 API(阶段项目 5)已经搭建好,可以直接连…...