我正在构建一个原型项目,它有很多 TypeScript 错误。我想尝试快速编译它,同时忽略所有错误,并在稍后修复它们。
我知道如何// @ts-ignore在文件开头添加注释,但如何对所有文件执行此操作?是否可以添加某种标志tsc,或者可以添加一些链接tsconfig.json以使其完全忽略所有错误并无论如何进行编译?
我有一个博客,使用不同比例和长宽比的图像。有的又短又宽,有的又高又窄。您可以在此处查看示例。
我希望我的图像:
就像这样:

为了使用常规img标签实现这一点,我使用以下 css:
img {
display: block;
max-width: 100%;
max-height: 350px; // to restrict the height of tall narrow images
margin: auto; // to center the tall narrow images when their width is less than 100%
}
Run Code Online (Sandbox Code Playgroud)
现在我想使用 自动缩小和优化我的图像next-image,但我似乎无法找到正确的样式和参数组合来实现相同的效果。
当我设置 时layout="responsive",图像始终填充容器宽度的 100%,忽略max-height参数。因此,如果图像非常高且非常窄,它仍然会完全拉伸到帖子,使其高得离谱。
就像这样:

当我设置时,layout="fill" objectFit="contain"我可以将图像包装在容器中并将容器的 css 设置为width:100%; height: 350px. 现在它会将高窄图像缩小到最大350px高度,但如果图像非常宽且非常短,容器的高度仍然为 350px(尽管现在应该短得多,因为图像很短) …
我想绘制一个使用导数找出函数在任何点的斜率的简单插图。它看起来有点像这样:
我已经使用以下代码绘制了一个简单的抛物线:
import numpy as np
from matplotlib import pyplot as plt
inputs = 0.2
weights = np.arange(-6,14)
target_prediction = 0.7
prediction = inputs*weights
errors = (prediction - target_prediction) ** 2
plt.xlabel("Weight")
plt.ylabel("Error")
plt.plot(weights, error)
Run Code Online (Sandbox Code Playgroud)
现在我想添加这样的东西:
current_weight = 5
# draw a short fraction of a line to represent slope
x = np.arange(optimal_weight - 3, optimal_weight + 3)
# derivative
slope = 2 * (inputs*current_weight - target_prediction)
y = slope*x # How should this equation look like?
plt.plot(x, y)
Run Code Online (Sandbox Code Playgroud)
画一条穿过 …
我想创建一个带有附加标签列表的帖子。这些模型是多对多连接的(一个帖子可以有多个标签,一个标签可以有多个帖子)。
这是我的棱镜模型:
model Post {
id String @id @default(cuid())
slug String @unique
title String
body String
tags Tag[]
}
model Tag {
id String @id @default(cuid())
posts Post[]
name String
slug String @unique
}
Run Code Online (Sandbox Code Playgroud)
这是一个突变,我试图创建一个帖子,并为其附加标签:
t.field('createPost', {
type: 'Post',
args: {
title: nonNull(stringArg()),
body: stringArg(),
tags: list(arg({ type: 'TagInput' }))
},
resolve: async (_, args, context: Context) => {
// Create tags if they don't exist
const tags = await Promise.all(
args.tags.map((tag) =>
context.prisma.tag.upsert({
create: omit(tag, "id"),
update: tag,
where: …Run Code Online (Sandbox Code Playgroud) 我想对嵌套评论进行建模,就像在 reddit 上一样。我正在使用这样的一对多自关系:
model Comment {
[...]
parentId String?
parent Comment? @relation("ParentChildren", fields: [parentId], references: [id])
children Comment[] @relation("ParentChildren")
}
Run Code Online (Sandbox Code Playgroud)
所以每个孩子都通过 与其父母相连parentId。评论可以无限嵌套,父母可以有孙子、孙子等等。
我的问题是 - 是否可以在一个查询中检索父评论的所有后代?我怎样才能做到这一点?
我的目标是获得一个看起来像这样的 json 对象:
{
comment: 'Lorem ipsum...',
children: [
{
comment: 'Lorem ipsum...',
children: [
{
comment: 'Lorem ipsum...',
children: []
},
{
comment: 'Lorem ipsum...',
children: []
},
],
},
],
},
Run Code Online (Sandbox Code Playgroud) 我是新手next-auth,我正在寻求帮助。
我已经添加了 Google OAuth 提供程序,现在当我运行时signIn("google")在前端运行函数时,它会自动将我带到 google 的登录页面,并以某种方式让我登录,而无需触摸我的数据库。
当谷歌身份验证完成后,我需要能够在我的数据库中创建一个新用户,或者检索现有用户(如果他们之前已经注册过)(因为我需要存储有关用户的各种自定义信息,而不仅仅是他们的电子邮件)。
我想让用户的信息在钩子session的对象上可用useSession()。现在我看到某种默认用户信息(带有name、email和image我未定义的 、 和字段
当我使用常规 Express 服务器和 Passport 时,代码看起来有点像这样:
const googleAuth = new GoogleStrategy(
{
clientID: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
callbackURL: "/api/v1/profiles/google/callback",
},
async (req, accessToken, refreshToken, profile, done) => {
const existingProfile = await Profile.findOne({ email: profile.emails[0].value })
/* Found user, return him and move along. */
if (existingProfile) return done(null, existingProfile)
/* Haven't found profile with this googleId, …Run Code Online (Sandbox Code Playgroud) 我需要一直抓住subreddit中的热门评论.
我已经尝试抓住所有提交内容并迭代它们,但不幸的是,您可以获得的帖子数量限制为1000.
我尝试过使用Subreddit.get_comments,但它只返回25条评论.
所以我正在寻找解决方法.
你能帮我吗?
我有一个警告框来确认用户已成功订阅:
<div className="alert alert-success">
<strong>Success!</strong> Thank you for subscribing!
</div>
Run Code Online (Sandbox Code Playgroud)
当用户发送电子邮件时,我将"订阅"状态更改为true.
我想要的是:
我怎样才能做到这一点?
我在一个网络漫画平台上工作,我需要允许用户在一个帖子中上传多张图片。
理想情况下 - 保持尽可能简单,这样人们就不必刷新页面来上传每张图片,或者在添加图片之前创建和保存帖子。
如果用户可以删除或重新排序图像,那就太好了。
此外,我需要使其具有可扩展性,以便以后不会遇到问题。
你能给我建议如何正确地做到这一点吗?
图像是否应该有自己的模型,并使用外键连接到帖子?(不确定这是否有意义,看起来有点丑)
或者我应该在帖子模型的某种类型的字段中保留一个图像网址列表,然后创建某种cdn并将其上传到那里?
任何建议都非常感谢。
python ×4
next.js ×2
prisma ×2
prisma2 ×2
dataframe ×1
django ×1
django-forms ×1
graphql ×1
matplotlib ×1
next-auth ×1
nextjs-image ×1
nexus ×1
nexus-prisma ×1
pandas ×1
plot ×1
praw ×1
reactjs ×1
reddit ×1
typescript ×1