小编Mas*_*arz的帖子

通过 c++20 协程制作 python 生成器

假设我有这个 python 代码:

def double_inputs():
    while True:
        x = yield
        yield x * 2
gen = double_inputs()
next(gen)
print(gen.send(1))
Run Code Online (Sandbox Code Playgroud)

正如预期的那样,它打印“2”。我可以像这样在 c++20 中制作一个生成器:

#include <coroutine>

template <class T>
struct generator {
    struct promise_type;
    using coro_handle = std::coroutine_handle<promise_type>;

    struct promise_type {
        T current_value;
        auto get_return_object() { return generator{coro_handle::from_promise(*this)}; }
        auto initial_suspend() { return std::suspend_always{}; }
        auto final_suspend() { return std::suspend_always{}; }
        void unhandled_exception() { std::terminate(); }
        auto yield_value(T value) {
            current_value = value;
            return std::suspend_always{};
        }
    };

    bool next() { return coro …
Run Code Online (Sandbox Code Playgroud)

c++ python yield c++20 c++-coroutine

17
推荐指数
1
解决办法
722
查看次数

无法初始化 NVML:几个小时后 Docker 中出现未知错误

我遇到有趣而奇怪的问题。

当我使用 GPU 启动 docker 容器时,它工作正常,并且我看到 docker 中的所有 GPU。然而,几个小时或几天后,我无法在docker中使用GPU。

当我nvidia-smi在 docker 机器上做的时候。我看到这条消息

“无法初始化 NVML:未知错误”

但是,在主机中,我看到所有 GPU 都带有 nvidia-smi。另外,当我重新启动 docker 机器时。它完全工作正常并显示所有 GPU。

我的推理 Docker 机器应该一直打开,并根据服务器请求进行推理。有人有同样的问题或该问题的解决方案吗?

nvidia docker nvidia-docker nvidia-smi

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

找不到数据库,并且IFEXISTS = true,所以我们无法自动创建它

打开h2数据库控制台后出现错误。我输入数据库名称,但显示数据库未找到错误:

找不到数据库“ C:/ Users / Barlekar / onlineshoppings”,并且IFEXISTS = true,因此我们无法自动创建它[90146-199] 90146/90146(帮助)

org.h2.jdbc.JdbcSQLNonTransientConnectionException:找不到数据库“ C:/ Users / Barlekar / onlineshoppings”,并且IFEXISTS = true,因此我们无法自动创建它[90146-199]

h2 spring-boot

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

ModelState 错误:值“null”对于可为空的字段无效

ModelState 会抛出错误,因为可空字段为空。

我有一个模型:

public class PersonModel
{
    public int? ID { get; set; }

    [Required]
    [StringLength(256)]
    public string Title { get; set; }

    [Required]
    [StringLength(256)]
    public string Name { get; set; }

    [Required]
    [StringLength(256)]
    public string Lastname { get; set; }

    [StringLength(1024)]
    public string Description { get; set; }

    public int? OrganizationID { get; set; }

    public string Organization { get; set; }

}
Run Code Online (Sandbox Code Playgroud)

控制器:

var errors = ModelState.Where (c => c.Value.Errors.Count > 0).Select (c => c.Value).ToList ();

if (!errors.Any …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc asp.net-core

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

在Startup.cs的Configure中获取域名或主机名和端口

我需要帮助来获取我的应用程序的主机/域名和端口。

到目前为止,这是我的Configure方法中的示例代码Startup.cs

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    var url = ""; // something that will get the current host/domain and port of the running applicaiton.

    RecurringJob.AddOrUpdate<ISomething>(i=>i.SomethingToExecute(url), Cron.Daily);
}
Run Code Online (Sandbox Code Playgroud)

因为我需要将url字符串传递给我的SomethingToExecute方法

public class Something : ISomething 
{
    public void SomethingToExecute(string url){
        ... 
        Debug.WriteLine(url)
    }
}
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-core asp.net-core-2.0 asp.net-core-2.1

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

使用 CSS 网格创建导航栏

我正在创建一个用 CSS 网格制作的导航栏。

我决定用网格来制作它,这样我就可以在不修改html 的情况下重新排列部分(项目)(只需修改 CSS)。

然后我创建了包含 3 个区域的网格:徽标、菜单、切换器。

我添加了一点间隙,这样每个项目就不会粘在一起。

在此处输入图片说明

到目前为止一切顺利,直到我试图删除一个/某些部分,即使该部分消失了,差距仍然存在

然后我尝试消除间隙并替换为每个部分的边距。但是边距不会在网格的开始/结束处崩溃。它的行为与常规块元素不同。

我知道使用 flexbox 而不是网格更实用,但我更喜欢网格,因为可以在不修改 html 的情况下重新排列该部分。可以将徽标移动到顶部或其他位置。flex 是不可能的事情。

谁能解决我的网格间隙问题?或者您可能有不同的方法来创建导航栏?

查看我的沙箱

.navbar {
  background: pink;
  display: grid;
  grid-template-rows: auto;
  grid-template-columns: max-content auto max-content;
  grid-template-areas: "logo menus toggler";
  justify-items: stretch;
  align-items: stretch;
  column-gap: 20px;
}

.logo {
  background: green;
  grid-area: logo;
  width: 60px;
}

.menus {
  background: lightsalmon;
  grid-area: menus;
  display: flex;
  flex-direction: row;
  justify-content: start;
}

.menus * {
  padding: …
Run Code Online (Sandbox Code Playgroud)

html css css-grid

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

VS Code:方括号和圆括号保持黄色 - 无论我选择什么主题

默认深色主题的截图:

默认深色主题图片

原子一光主题:

原子一光主题

当我更改主题时,方括号和圆括号保持相同的颜色。我尝试禁用括号对着色,但黄色括号仍然存在。无论我选择什么主题,它们都会保持黄色。

根据其文档,这就是 Atom one light 主题的外观:

在此输入图像描述

themes visual-studio-code

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

DataGridView AllowUserToAddRow 属性不起作用

我有一个使用实体框架的简单项目,我有一个DataGridViewForm并将其AllowUserToAddRow属性设置为true,但我仍然无法向其中添加新行。

这是我的代码:

DBEntities context = new DBEntities();
private void Form1_Load(object sender, EventArgs e)
{
    var q = (from i in context.myTable
             select i).ToList();
    DataGridView.DataSource = q;
}

private void btnSave_Click(object sender, EventArgs e)
{
    context.SaveChanges();
    MessageBox.Show("saved successfully");
}
Run Code Online (Sandbox Code Playgroud)

如果我使用BindingSource控件,它允许我插入行,DataGridView但是在context.SaveChanges()我在数据库文件中不调用任何插入之后,使用这种方法。所以我想也许与这个问题有关,DataGridView属性true AllowUserToAddRow不允许我在 中插入行DataGridView

c# linq entity-framework datagridview bindingsource

5
推荐指数
1
解决办法
6966
查看次数

是否有获取语言环境字符串格式的 UTC 日期的函数?

我想在 JavaScript 中获取当前的 UTC 日期,但以本地日期格式显示它(就像Date.toLocaleDateString()那样)。

我首先尝试只获取当前的 UTC 日期,Date.toUTCString()但这实际上并没有以本地格式打印出来。

然后我尝试使用 中的选项配置toLocaleDateString(),但这只是打印本地日期而不是本地格式的 UTC 日期。例如新的Date().toLocaleDateString(options = {timeZone: "UTC"})

然后我尝试使用 格式化Intl.DateTimeFormat(),但这只是给出了相同的结果Date.toLocaleDateString()

如果有办法获取语言环境格式,那么我很乐意使用该格式来格式化 UTC 日期,但据我所知,没有。

例如,new Date("Sat, 30 Mar 2019 00:27:19 GMT")对于每个支持的语言环境,在美国,我应该打印出“3/30/2019”,在欧洲,我应该打印出“30/3/2019”,依此类推。

但是,new Date("Sat, 30 Mar 2019 00:27:19 GMT").toLocaleDateString(options = {timeZone: "UTC"})将改为打印“3/29/2019”。

javascript date

5
推荐指数
2
解决办法
4141
查看次数

我收到错误 importerror /lib/arm-linux-gnueabihf/libm.so.6 version glibc_2.29' not found 我该怎么办?

当我在 raspberry pi 3b+ 中运行 python 代码时,我得到:

导入错误 /lib/arm-linux-gnueabihf/libm.so.6 版本 glibc_2.29' 未找到

错误我该怎么办?

#beginner

pi@raspberrypi:~/Desktop/Mirror-Interface-Auth/RaspberryPi-Module $ python3 main.py
Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.7/site-packages/firebase_admin/firestore.py", line 22, in <module>
    from google.cloud import firestore # pylint: disable=import-error,no-name-in-module
  File "/home/pi/.local/lib/python3.7/site-packages/google/cloud/firestore/__init__.py", line 18, in <module>
    from google.cloud.firestore_v1 import __version__
  File "/home/pi/.local/lib/python3.7/site-packages/google/cloud/firestore_v1/__init__.py", line 30, in <module>
    from google.cloud.firestore_v1._helpers import GeoPoint
  File "/home/pi/.local/lib/python3.7/site-packages/google/cloud/firestore_v1/_helpers.py", line 22, in <module>
    from google.api_core import gapic_v1
  File "/home/pi/.local/lib/python3.7/site-packages/google/api_core/gapic_v1/__init__.py", line 16, in <module>
    from google.api_core.gapic_v1 import config
  File "/home/pi/.local/lib/python3.7/site-packages/google/api_
Run Code Online (Sandbox Code Playgroud)

raspberry-pi raspberry-pi3

5
推荐指数
1
解决办法
3126
查看次数