小编Eva*_*tis的帖子

为什么std :: exception在std :: bad_alloc之前捕获我的异常?

问题:我使用std :: exception和std :: bad_alloc来捕获异常.我正在使用的try catch的顺序有问题.我附上了示例代码以供参考.

预期:如果我的错误是bad_alloc,则抛出bad_alloc异常.

观察:我的错误是bad_alloc,但抛出了异常.

示例代码:

#include "stdafx.h"
#include <iostream>
#include <exception>

using namespace std;

void goesWrong()
{
    bool error1Detected = true;
    bool error2Detected = false;

    if (error1Detected)
    {
        throw bad_alloc();
    }

    if (error2Detected)
    {
         throw exception();
    }
}

int main()
{
    try
    {
        goesWrong();
    }
    catch (exception &e)
    {
        cout << "Catching exception: " << e.what() << endl;
    } 
    catch (bad_alloc &e)
    {
        cout << "Catching bad_alloc: " << e.what() << endl; …
Run Code Online (Sandbox Code Playgroud)

c++ exception

13
推荐指数
1
解决办法
1288
查看次数

计算2 ^ n的理论时间与实际时间复杂度

我正在尝试计算时间复杂度,并将其与实际计算时间进行比较。

如果我没记错的话,时间复杂度是O(log(n)),但是从实际的计算时间来看,它看起来更像O(n)甚至O(nlog(n))。

造成这种差异的原因可能是什么?

def pow(n):
    """Return 2**n, where n is a nonnegative integer."""
    if n == 0:
        return 1
    x = pow(n//2)
    if n%2 == 0:
        return x*x
    return 2*x*x
Run Code Online (Sandbox Code Playgroud)

理论时间复杂度

在此处输入图片说明

实际运行时间

在此处输入图片说明

python time-complexity pow

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

消息:会话未创建:此版本的 ChromeDriver 仅支持 Chrome 版本 94 当前浏览器版本为 93.0.4577.82

编写一个简单的 selenium 脚本来单击网站上的链接。脚本是这样写的:

from selenium import webdriver
import time

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")
browser = webdriver.Chrome(options=chrome_options)

try:
    browser.get("https://www.google.com")
    print("Page title was '{}'".format(browser.title))

finally:
    browser.quit()
Run Code Online (Sandbox Code Playgroud)

现在的问题是实际的 chrome 驱动程序本身我得到以下异常

selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 94
Current browser version is 93.0.4577.82 with binary path /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
Run Code Online (Sandbox Code Playgroud)

我去了 chromedriver 下载网站。但我仍然遇到同样的错误。

selenium

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

MongoDB指南针超时

我正在使用MongoDB Compass通过SSH隧道对相当大的数据集(约2,000,000个文档,300MB)执行聚合。

它连接正常,我可以查询,但是管道中的阶段似乎超时operation exceeded time limit

在此处输入图片说明

我知道可以通过命令行使用maxTimeMs 设置查询的最长时间(以毫秒为单位),$maxTimeMS但是可以在MongoDB Compass中应用此时间吗?

我也一直在寻找连接超时设置,但在GUI中找不到与此相关的任何内容。

mongodb mongodb-compass

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

在迭代器上调用erase(),但不删除正确的元素

我正在学习c ++,我正在以双链表的方式工作,但是当我试图从列表中删除元素时,我注意到了一些非常奇怪的东西.

问题:我在列表中的值2之前插入一个元素,数字,然后我试图删除任何值为1的元素.

预期:在我的第一个循环中的条件语句中调用erase()后,我的列表中的数字应该被调整.数字应该包含的唯一值应该包含0,1234,2,3.

观察到:我的列表编号包含值0,1,1234,2,3.好像什么都没有被删除.

代码示例:

#include "stdafx.h"
#include <iostream>
#include <list>

using namespace std;

int main()
{
   list<int> numbers; 

   numbers.push_back(1);
   numbers.push_back(2);
   numbers.push_back(3);
   numbers.push_front(0);

   list<int>::iterator it = numbers.begin();
   it++;
   numbers.insert(it, 100);
   cout << "Element: " << *it << endl;

   list<int>::iterator eraseIt = numbers.begin();
   eraseIt++;
   eraseIt = numbers.erase(eraseIt);
   cout << "Element: " << *eraseIt << endl;

   for (list<int>::iterator it = numbers.begin(); it != numbers.end(); it++)
   {
      if (*it == 2)
      {
         numbers.insert(it, 1234);
      }

      if (*it == …
Run Code Online (Sandbox Code Playgroud)

c++ list erase

4
推荐指数
1
解决办法
57
查看次数

Terraform 错误 该值没有任何索引

我正在从 tf 11 升级到 tf 12,我刚刚遇到了这个问题。这曾经在 tf 11 中工作,现在在 tf 12 中被破坏。有人可以帮我解决这个问题吗?

data "aws_subnet_ids" "private" {
  vpc_id = data.aws_ssm_parameter.vpc_id.value

  tags = {
    tier = "private"
  }
}

data "aws_subnet" "private" {
  count = length(data.aws_subnet_ids.private.ids)
  id    = data.aws_subnet_ids.private.ids[count.index]
}
Run Code Online (Sandbox Code Playgroud)
27:   id    = data.aws_subnet_ids.private.ids[count.index]
    |----------------
    | count.index is 0
    | data.aws_subnet_ids.private.ids is set of string with 3 elements

This value does not have any indices.
Run Code Online (Sandbox Code Playgroud)

terraform

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

在centos 7 dockerfile中安装java 8

我刚刚看了这个问题:How to Define OpenJDK 8 in CentOS based Dockerfile?

我尝试了建议的答案,但没有得到预期的结果。这是我的 DockerFile 的内容

FROM centos:7

RUN yum install -y \
       java-1.8.0-openjdk \
       java-1.8.0-openjdk-devel

ENV JAVA_HOME /etc/alternatives/jre
RUN yum install maven
RUN yum install curl 
RUN yum install -y unzip

Run Code Online (Sandbox Code Playgroud)

我通过以下方式构建图像:docker build -t container_image:latest -f DockerFile.build . 然后,当我运行docker run -it {image_id} /bin/bash 并执行时java --version,我得到bash: java: command not found. 有人可以帮我看看我在这里做错了什么吗?

另外,当我尝试通过容器内安装 jdk 时,yum install java-1.8.0-openjdk我得到以下信息

java --version
Unrecognized option: --version
Error: Could not …
Run Code Online (Sandbox Code Playgroud)

centos java-8 docker

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

Terraform 属性“子网”的值不合适:元素 0:需要字符串

我正在从 tf 11 升级到 tf 12。我遇到了terraform plan产生以下错误的问题:

Error: Incorrect attribute value type

   4:   subnets         = ["${var.alb_subnets}"]

Inappropriate value for attribute "subnets": element 0: string required.
Run Code Online (Sandbox Code Playgroud)

该错误的代码片段是:

resource aws_alb "alb" {
  name            = "ecs-${var.app_name}"
  internal        = "${var.internal}"
  subnets         = ["${var.alb_subnets}"]
  security_groups = ["${var.security_groups}"]
  count           = "${var.do_module}"
}
Run Code Online (Sandbox Code Playgroud)

如果有人可以帮助我,我将不胜感激。

terraform

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

术语“Register-AzResourceProvider”未被识别为 cmdlet 的名称

您好,我正在尝试自学 Azure,并且正在遵循本指南: https: //learn.microsoft.com/en-us/learn/modules/intro-to-governance/2-azure-policy。我使用的是 Windows 10 $PSVersionTable.PSEdition=Desktop我向 Microsoft 支持发送了消息,但没有人回复。当我尝试跑步时

# Register the resource provider if it's not already registered
Register-AzResourceProvider -ProviderNamespace 'Microsoft.PolicyInsights'
Run Code Online (Sandbox Code Playgroud)

我明白了

Register-AzResourceProvider : The term 'Register-AzResourceProvider' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that
the path is correct and try again.
Run Code Online (Sandbox Code Playgroud)

我已检查是否已安装 Azure powershell

if ($PSVersionTable.PSEdition -eq 'Desktop' -and (Get-Module -Name AzureRM -ListAvailable)) …
Run Code Online (Sandbox Code Playgroud)

powershell azure azure-powershell

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

如何在 Terraform 中使用条件计数语句

给定一个像这样的模块

\n
module us-west-2 {\n    count          = "${local.environments[terraform.workspace] ==  "logging" ? true : false}"\n    source = "./modules/flow_log"\n    providers = {\n        aws = aws.us-west-2\n    }\n    log_destination = module.nf_cis_benchmark.aws_s3_bucket_vpc_flow_log\n    log_destination_type = "s3"\n    traffic_type = "REJECT"\n    depends_on = [ module.nf_cis_benchmark.raws_s3_bucket_vpc_flow_log_arn ]\n    aws_vpc_ids = data.aws_vpcs.us-west-2.ids\n}\n\n
Run Code Online (Sandbox Code Playgroud)\n

我们如何根据返回值有条件地创建这个模块local.environments[terraform.workspace]

\n

预期:\n当用户运行时,terraform apply将根据所选工作区有条件地创建资源。

\n

实际的:

\n
330:     count          = length("${local.environments[terraform.workspace] ==  "logging" ? true : false}")\n\xe2\x94\x82     \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\n\xe2\x94\x82     \xe2\x94\x82 local.environments is object with 9 attributes\n\xe2\x94\x82     \xe2\x94\x82 terraform.workspace is "nf-logging"\n\xe2\x94\x82 \n\xe2\x94\x82 Call to function "length" …
Run Code Online (Sandbox Code Playgroud)

terraform

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

使用 Terraform 创建 StringLike 条件

我正在尝试为 aws IAM 策略生成一些 terraform。政策中的条件如下所示

"StringLike": {
 "kms:EncryptionContext:aws:cloudtrail:arn": [
 "arn:aws:cloudtrail:*:aws-account-id:trail/*"
 ]
Run Code Online (Sandbox Code Playgroud)

我正在查看以下文档aws_iam_policy_documenthttps://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document,但我不清楚如何在 terraform 中编写此文档。任何帮助将不胜感激。这是我的尝试

condition {
        test = "StringLike"
        variable = "kms:EncryptionContext:aws:cloudtrail:arn"

        values = [
            "arn:aws:cloudtrail:*:aws-account-id:trail/*"
        ]
    }
Run Code Online (Sandbox Code Playgroud)

amazon-web-services terraform

-1
推荐指数
1
解决办法
5642
查看次数