小编Ant*_*ong的帖子

terraform import 为字符串键值引发“需要索引值”错误

如果它是由 terraform 从头开始​​创建的,那么它在状态文件中的样子:

{
  "module": "module.rds",
  "mode": "managed",
  "type": "aws_cloudwatch_log_subscription_filter",
  "name": "rds_logs_delivery",
  "each": "map",
  "provider": "provider.aws",
  "instances": [
    {
      "index_key": "prod-service-master.audit",
      "schema_version": 0,
      "attributes": {
        "destination_arn": "arn:aws:firehose:us-east-5:9999999999:deliverystream/prod-rds-logs",
        "distribution": "ByLogStream",
        "filter_pattern": "",
        "id": "cwlsf-9999999999",
        "log_group_name": "/aws/rds/instance/prod-service-master/audit",
        "name": "rds-logs-delivery-prod-service-master",
        "role_arn": "arn:aws:iam::9999999999:role/cloudwatch-logs-to-kinesis"
      },
      "private": "abcdefg",
      "depends_on": [
        "data.aws_caller_identity.current",
        "data.aws_partition.current",
        "data.terraform_remote_state.kinesis_delivery_stream"
      ]
    },
Run Code Online (Sandbox Code Playgroud)

由于某些原因,我需要将其导入另一个 tf 状态文件。所以我运行了这个命令:

 terraform import module.rds.aws_cloudwatch_log_subscription_filter.rds_logs_delivery["prod-service-reports.audit"] rds-logs-delivery-prod-service-master
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

Error: Index value required

  on <import-address> line 1:
   1: module.rds.aws_cloudwatch_log_subscription_filter.rds_logs_delivery[prod-service-reports.audit]

Index brackets must contain either a literal number or a literal string.
Run Code Online (Sandbox Code Playgroud)

我该如何解决?我试过了 …

terraform

3
推荐指数
4
解决办法
1408
查看次数

当相应状态在一段时间不活动后被视为“关闭”时,如何取消设置 Redis 位集中的某个位?

我发现使用以下方法很容易计算活动连接数

redis_sip = redis.Redis(host="localhost", port=6379, db=0)
redis_sip.setbit(skey, 1, 1)
redis_sip.setbit(skey, 2, 1)
redis_sip.setbit(skey, 3, 0)
redis_sip.setbit(skey, 4, 1)
print(redis_sip.bitcount(skey)) # shows me 3 connections
Run Code Online (Sandbox Code Playgroud)

但为了实现这一点,我需要能够为每个单独的位设置一个 TTL。

即当远程代理建立连接时,我可以将该位设置为 1。如果支持按位到期,则在一段不活动时间后该位将被翻转。

这在Redis中可行吗?如果不是,有什么替代方案?

redis

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

RuntimeError: 堆栈期望每个张量大小相等,但在条目 0 处得到 [32, 1],在条目 1 处得到 [32, 0]

我有一个非常大的形状张量(512,3,224,224)。我将其以 32 个批次输入到模型中,然后保存与目标标签相对应的分数2。在每次迭代中,在每个切片之后,形状都会发生scores变化。这会导致以下错误。我做错了什么以及如何解决它。 label = torch.ones(1)*2

def sub_forward(self, x):
    x = self.vgg16(x)
    x = self.bn1(x)
    x = self.linear1(x)
    x = self.linear2(x)
    return x
Run Code Online (Sandbox Code Playgroud)

def get_scores(self, imgs, targets):
    b, _, _, _ = imgs.shape
    batch_size = 32
    total_scores = []
    for i in range(0, b, batch_size):
      scores = self.sub_forward(imgs[i:i+batch_size,:,:,:])
      scores = F.softmax(scores)
      labels = targets[i:i+batch_size]
      labels = labels.long()
      scores = scores[:,labels]
      print(i," scores: ", scores)
      total_scores.append(scores)
      print(i," total_socres: ", total_scores)
    total_scores = torch.stack(total_scores)
    return scores …
Run Code Online (Sandbox Code Playgroud)

python deep-learning pytorch tensor

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

Python属性和方法覆盖问题:为什么子类属性仍然调用基类的方法

这是一个例子

class A(object):
        def f1(self):
                return []
        test1 = property(f1)


class B(A):
        def f1(self):
                return [1, 2]

if __name__ == "__main__":
        b = B()
        print b.test1
Run Code Online (Sandbox Code Playgroud)

我希望输出为[1,2],但它会打印[].

这与我的期望相反.

我在代码中犯了什么错误吗?如果没有,我认为它是这样工作的,因为当创建属性test1时,它被绑定到基类A的f1函数.有什么可能的替代实现来实现我想要的?

python inheritance properties

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

python:如何重写SimpleHTTPServer以在目录列表中显示时间戳?

我在用

 python -m SimpleHTTPServer
Run Code Online (Sandbox Code Playgroud)

作为一个非常简单的Web服务器,供内部用户访问测试服务器上的数据文件.

默认列表SimpleHTTPServer 非常简单.它只显示文件链接.

如何让它显示文件时间戳?我很乐意写一个自定义类来扩展SimpleHTTPServer

我目前正在使用python 2.4.3

python

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

Erlang调试器错误:找不到'wxe_driver.so'

启动调试器时,我可以看到以下错误报告.

2> debugger:start().

=ERROR REPORT==== 23-Jan-2014::11:59:08 ===
ERROR: Could not find 'wxe_driver.so' in: /usr/local/Cellar/erlang/R16B03/lib/erlang/lib/wx-1.1.1/priv
{ok,<0.42.0>}
Run Code Online (Sandbox Code Playgroud)

尽管有错误报告,调试器窗口仍会启动.

为什么错误?它会导致调试器问题吗?

Erlang运行时由homebrew安装.版本号为R16B03

macos erlang homebrew osx-mavericks

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

为什么这行NSNotificationCenter.defaultCenter().postNotificationName(...)抛出SIGABRT

我在swift中玩NSNotificationCenter.这是我的代码main.swift

进口基金会

class T: NSObject {

    func someAction(notification: NSNotification) {
        println(notification.userInfo)
    }
}

var dataDict = Dictionary<String, String>()
dataDict["test"] = "test"
dataDict["test1"] = "test1"


var t = T();
NSNotificationCenter.defaultCenter().addObserver(t, selector:"someAction", name: "someAction", object:nil)



NSNotificationCenter.defaultCenter().postNotificationName("someAction", object:nil, userInfo:dataDict)

let runloop = NSRunLoop.currentRunLoop();
runloop.run();

println("Done");
Run Code Online (Sandbox Code Playgroud)

在线postNotification,我有一个例外:

在此输入图像描述

这是一些堆栈跟踪:

2014-07-24 08:58:59.959 testswiftcli2[2171:303] -[_TtC13testswiftcli21T someAction]: unrecognized selector sent to instance 0x1005005a0
2014-07-24 08:58:59.961 testswiftcli2[2171:303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_TtC13testswiftcli21T someAction]: unrecognized selector sent to instance 0x1005005a0'
Run Code Online (Sandbox Code Playgroud)

当我试图检查实例时,我得到了这个:

(lldb) …
Run Code Online (Sandbox Code Playgroud)

nsnotificationcenter swift xcode6

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

Cocoapod:不可能快进,中止

这是我的podfile的内容:

platform :ios, '7.0'
pod 'RedditKit', '~> 1.3' 
Run Code Online (Sandbox Code Playgroud)

它位于我的iOS项目的根目录(即不是工作区)

当我运行时,pod install我收到此错误消息:

$ pod install
Analyzing dependencies
[!] An error occurred while performing `git pull` on repo `master`.
[!] /usr/bin/git pull --ff-only

fatal: Not possible to fast-forward, aborting.
Run Code Online (Sandbox Code Playgroud)

我已经运行gem update --system更新我的ruby安装

有关我的cocoapod安装的更多信息

$ gem which cocoapods
/Users/antkong/.rvm/gems/ruby-2.1.2@global/gems/cocoapods-0.33.1/lib/cocoapods.rb
Run Code Online (Sandbox Code Playgroud)

ruby rvm cocoapods redditkit

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

erlang异常错误:未定义函数lhttpc:start/0

我得到一个noproc例外,当我尝试调用httpc:request(get, ...)一个geturl/1函数

** exception exit: {noproc,{gen_server,call,
                                   [httpc_manager,
                                    {request,{request,undefined,<0.54.0>,0,http,
Run Code Online (Sandbox Code Playgroud)

为了解决这个问题,starttesturl/0根据这个答案接听了我的电话:https: //stackoverflow.com/a/14553219/58129

testurl() ->
    ssl:start(),
    lhttpc:start(),
    geturl("http://www.cnn.com").
Run Code Online (Sandbox Code Playgroud)

它失败并出现此错误:

so1:testurl().
** exception error: undefined function lhttpc:start/0
     in function  so1:testurl/0 (so1.erl, line 7)
Run Code Online (Sandbox Code Playgroud)

我谷歌,我找不到一个称为的模块lhttpc.什么是正确的httpc:request工作方式?

erlang

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

如何引用reactjs/JSX中的局部变量?

这是我的功能:

  import styles from '../common.css'

  class A extends Component {

  ...

    renderBtn(expanded) {
      let btnStyle = expanded ? 'icon-circle-up' : 'icon-circle-down'
      return (
          <button className={`$styles.icon $btnStyle`}> Hi</button>

      );
    }

  }
Run Code Online (Sandbox Code Playgroud)

不知怎的,HTML 的结果是这样的:

 <button class='_dqwdqweqwefvasdasdas $btnStyle'> Hi</button>
Run Code Online (Sandbox Code Playgroud)

$btnStyle上面未解析为存储在变量中的值btnStyle

我怎样才能让它发挥作用?

javascript reactjs

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