假设我有以下代码:
const id = '1'
const arrayOfIds = ['1', '2', '3']
Run Code Online (Sandbox Code Playgroud)
我想检查id是否在 arrayOfIds
像这样的东西
expect(id).toBeIn(arrayOfIds)
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点Jest?
我在本地运行此命令以构建 PDF 文件:
docker run -it -v $PWD:/doc/ -v $PWD/fonts/:/usr/share/fonts/external/ thomasweise/texlive sh -c 'xelatex *.tex'
Run Code Online (Sandbox Code Playgroud)
我有一个cloudbuild.yaml要在 Google Cloud 上构建的文件
docker run -it -v $PWD:/doc/ -v $PWD/fonts/:/usr/share/fonts/external/ thomasweise/texlive sh -c 'xelatex *.tex'
Run Code Online (Sandbox Code Playgroud)
但我的构建失败了,因为我需要安装额外的卷:-v $PWD/fonts/:/usr/share/fonts/external/
如何将上面的命令翻译为cloudbuild.yaml?
我有下表的值:
scores = {
"proxy": 300,
"vpn": 500,
"tor": 900,
"recent_abuse": 1000,
}
Run Code Online (Sandbox Code Playgroud)
和这个带有布尔值的数据
data = {
"proxy": False,
"vpn": True,
"tor": False,
"recent_abuse": False,
}
Run Code Online (Sandbox Code Playgroud)
我想知道是否可以在一行中(可能使用 itertools)计算一个基于 data
我目前的代码是这样的:
if data["proxy"]:
score += 300
if data["vpn"]:
score += 500
if data["tor"]:
score += 900
if data["recent_abuse"]:
score += 1000
Run Code Online (Sandbox Code Playgroud) 我试图获取我的页面的路径getServerSideProps,但类型params是对象
我需要做什么才能得到字符串?
export const getServerSideProps: GetServerSideProps = async (context) => {
const { slug } = context.params // Property 'slug' does not exist on type 'ParsedUrlQuery | undefined'.ts(2339)
return {
props: {
},
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个pages/404.ts包含以下内容的自定义:
export default function NotFound() {
return <h1>404 - Page Not Found</h1>
}
Run Code Online (Sandbox Code Playgroud)
我还有另一个页面,当某个组织为空时显示 404:
import Error from 'next/error'
const Slug: NextPage<SlugProps> = ({ organization }) => {
if (!organization) {
return <Error statusCode={404} />
}
return <h1>{organization.name}</h1>
}
Run Code Online (Sandbox Code Playgroud)
我想要 NextJS 显示我的自定义 404 页面,而不是显示默认页面
我需要做什么才能显示我的404 页面?
我有以下文件
pages/api/[slug]/[uid].ts
我想把 和slug放在uid我的处理程序的身上,我该怎么做?
我有以下代码
func (r *WorkspaceRepository) Delete(id any) (bool, error) {
if err := r.db.Where("id = ?", id).Delete(&model.Workspace{}).Error; err != nil {
return false, err
}
return true, nil
}
Run Code Online (Sandbox Code Playgroud)
当我传递一个不存在的ID时,不会返回任何错误,就好像该记录存在一样!
删除之前我需要做什么检查,是否需要先进行SELECT?
显然,template_file 已被弃用,我需要迁移到templatefile
我有以下 YAML 需要填充两个变量
data "template_file" "user_data" {
template = file("cloud-init.yaml")
vars = {
user = var.USER
tskey = var.TAILSCALE_AUTHKEY
}
}
Run Code Online (Sandbox Code Playgroud)
下面使用
user_data = data.template_file.user_data.rendered
Run Code Online (Sandbox Code Playgroud)
如何使用模板文件以新的方式做到这一点?
我想知道如何将跟随mongodb查询转换为pymongo语法
db.articles.find(
{ $text: { $search: "cake" } },
{ score: { $meta: "textScore" } }
).sort( { score: { $meta: "textScore" } } ).limit(3)
Run Code Online (Sandbox Code Playgroud)
我试过这个:
results = \
mongo.db.products.find({ '$text': { '$search': 'cake' } }, { 'score': { '$meta': 'textScore' } }) \
.sort({ 'score': { '$meta': 'textScore' } }) \
.limit(3)
Run Code Online (Sandbox Code Playgroud)
但是我在排序时遇到了以下错误:
raise TypeError("second item in each key pair must be 1, -1, "
TypeError: second item in each key pair must be 1, -1, '2d', 'geoHaystack', or …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 kubectl 修补秘密
kubectl patch secret operator-secrets --namespace kube-system --context=cluster1 --patch "'{\"data\": {\"FOOBAR\": \"$FOOBAR\"}}'"
Run Code Online (Sandbox Code Playgroud)
但我收到错误
来自服务器的错误 (BadRequest): json: 无法将字符串解组为类型为 map[string]interface {} 的 Go 值
如果我使用 echo 运行命令,它似乎是一个有效的 JSON
$ echo "'{\"data\": {\"FOOBAR\": \"$FOOBAR\"}}'"
'{"data": {"FOOBAR": "value that I want"}}'
Run Code Online (Sandbox Code Playgroud)
可以是什么?
javascript ×4
next.js ×3
python ×2
typescript ×2
go ×1
go-gorm ×1
jestjs ×1
kubectl ×1
kubernetes ×1
mongodb ×1
pymongo ×1
reactjs ×1
terraform ×1