小编Ray*_*lez的帖子

如何在忽略所有错误的情况下编译 TypeScript 项目?

我正在构建一个原型项目,它有很多 TypeScript 错误。我想尝试快速编译它,同时忽略所有错误,并在稍后修复它们。

我知道如何// @ts-ignore在文件开头添加注释,但如何对所有文件执行此操作?是否可以添加某种标志tsc,或者可以添加一些链接tsconfig.json以使其完全忽略所有错误并无论如何进行编译?

typescript

12
推荐指数
2
解决办法
1万
查看次数

为了清楚起见,如何在 pandas DataFrame 中“命名”列/行?

为了清楚起见,我试图弄清楚如何“命名”pandas DataFrame 中的行和列。我不确定它叫什么,但我正在尝试创建一个像这样的表: 在此输入图像描述

有没有一种简单的方法可以在列名称顶部添加“实际类别”,在行名称左侧添加“预测类别”,只是为了澄清?

python dataframe pandas

7
推荐指数
1
解决办法
2万
查看次数

如何使用下一个图像将图像缩小到“最大宽度”和“最大高度”?

我有一个博客,使用不同比例和长宽比的图像。有的又短又宽,有的又高又窄。您可以在此处查看示例。

我希望我的图像:

  • 最多与帖子一样宽(不大于其容器的 100% 宽度),以便当图像又宽又短时,它会填充帖子宽度的 100%。
  • 高度最多为 350 像素,这样当图像又高又窄时,它的大小就会受到其高度的限制 - 它将是 350 像素高,并位于帖子中间的中心。

就像这样:

为了使用常规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(尽管现在应该短得多,因为图像很短) …

next.js nextjs-image

7
推荐指数
1
解决办法
1万
查看次数

如何在任意点绘制抛物线的斜率(切线)?

我想绘制一个使用导数找出函数在任何点的斜率的简单插图。它看起来有点像这样:

我已经使用以下代码绘制了一个简单的抛物线:

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)

画一条穿过 …

python plot matplotlib

6
推荐指数
1
解决办法
5868
查看次数

Prisma2 错误:“prisma.post.create()”调用无效:PostUncheckedCreateInput 类型的 data.tags 中的参数“tags”未知

我想创建一个带有附加标签列表的帖子。这些模型是多对多连接的(一个帖子可以有多个标签,一个标签可以有多个帖子)。

这是我的棱镜模型:

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)

nexus graphql prisma nexus-prisma prisma2

6
推荐指数
1
解决办法
7707
查看次数

我想使用 Prisma 存储嵌套评论(就像在 reddit 上一样)。如何检索所有嵌套评论?

我想对嵌套评论进行建模,就像在 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)

prisma prisma2

6
推荐指数
1
解决办法
1576
查看次数

将 next-auth 与 Google OAuth 和存储在数据库中的用户一起使用的正确方法是什么?

我是新手next-auth,我正在寻求帮助。

我已经添加了 Google OAuth 提供程序,现在当我运行时signIn("google")在前端运行函数时,它会自动将我带到 google 的登录页面,并以某种方式让我登录,而无需触摸我的数据库。

当谷歌身份验证完成后,我需要能够在我的数据库中创建一个新用户,或者检索现有用户(如果他们之前已经注册过)(因为我需要存储有关用户的各种自定义信息,而不仅仅是他们的电子邮件)。

我想让用户的信息在钩子session的对象上可用useSession()。现在我看到某种默认用户信息(带有nameemailimage我未定义的 、 和字段

当我使用常规 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)

next.js next-auth

3
推荐指数
1
解决办法
4427
查看次数

如何在PRAW的subreddit中列出顶级评论?

我需要一直抓住subreddit中的热门评论.

我已经尝试抓住所有提交内容并迭代它们,但不幸的是,您可以获得的帖子数量限制为1000.

我尝试过使用Subreddit.get_comments,但它只返回25条评论.

所以我正在寻找解决方法.

你能帮我吗?

python reddit praw

2
推荐指数
1
解决办法
1690
查看次数

反应 - 如何等待和淡出?

我有一个警告框来确认用户已成功订阅:

<div className="alert alert-success">
    <strong>Success!</strong> Thank you for subscribing!
</div>    
Run Code Online (Sandbox Code Playgroud)

当用户发送电子邮件时,我将"订阅"状态更改为true.

我想要的是:

  • 订阅状态为true时显示警告框
  • 等待2秒钟
  • 让它淡出

我怎样才能做到这一点?

reactjs

1
推荐指数
2
解决办法
1万
查看次数

将多个图像附加到帖子的正确方法是什么?[姜戈]

我在一个网络漫画平台上工作,我需要允许用户在一个帖子中上传多张图片。

  • 理想情况下 - 保持尽可能简单,这样人们就不必刷新页面来上传每张图片,或者在添加图片之前创建和保存帖子。

  • 如果用户可以删除或重新排序图像,那就太好了。

  • 此外,我需要使其具有可扩展性,以便以后不会遇到问题。

你能给我建议如何正确地做到这一点吗?

图像是否应该有自己的模型,并使用外键连接到帖子?(不确定这是否有意义,看起来有点丑)

或者我应该在帖子模型的某种类型的字段中保留一个图像网址列表,然后创建某种cdn并将其上传到那里?

任何建议都非常感谢。

python django django-models django-forms

0
推荐指数
1
解决办法
2290
查看次数