小编Chr*_*now的帖子

如何让远程执行配置程序在磁盘附件后应用?

我有一个脚本,需要在配置实例并附加卷后运行:

resource "aws_instance" "controller" {
  ...

  provisioner "remote-exec" {
    connection {
      type     = "ssh"
      user     = "centos"
    }
    inline = [
      "download and run script to verify environment"
    ]
  }
}

resource "aws_ebs_volume" "controller-ebs-sdb" {
  ...
}

resource "aws_volume_attachment" "controller-volume-attachment-sdb" {
  device_name = "/dev/sdb"
  volume_id   = "${aws_ebs_volume.controller-ebs-sdb.id}"
  instance_id = "${aws_instance.controller.id}"
}
Run Code Online (Sandbox Code Playgroud)

目前,该脚本使环境失败,因为它运行时尚未附加卷。

是否可以仅在附加卷后运行远程执行脚本?

terraform

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

MEF最佳实践:在应用程序中我在哪里创建容器以及在哪里调用Compose()?

我已经决定使用MEF作为我拥有的插件模式,并且发现MEF易于拾取而且根本没有侵入性.我查看了样品,发现它们非常容易使用.

然而,一旦开始实施,我开始苦苦于构图.假设我有一个属于其中[ImportMany]一个属性的类.我看到的所有例子中,他们在具有导入的类中创建了Container(让我们称之为可组合的),并且基本上该类组成了自己.对于一个例子来说这可能是好的,但是确定地知道插件如何被填充对于组合物来说知道太多了.

我可以愉快地创建一个单例容器并在我的可编组中访问它,但是另外,composable必须显式调用Compose()自己,我不满意,因为它就像一个依赖注入场景,类主动调用Resolve()容器.所以,我并不想用它只是服务地点.

为了使事情变得更糟,我也使用温莎城堡进行DI,我不确定MEF和Windsor如何一起工作.

我真的环顾四周,无法找到任何有关如何正确做MEF的指导和示例.现在可能是我没有环顾四周或者我不太了解MEF(这是真的)但是会从实际在现实世界中使用它的经验中重视你的观点.

.net c# mef

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

如何使ImageButton在点击时直接打开电子邮件作曲家?

我已经为epaper/emagazine制作了一个应用程序,其中我想为电子邮件作曲家提供一个图像按钮,如果我点击该按钮,它将直接打开电子邮件作曲家,将该页面的所有数据插入电子邮件作曲家消息正文,仅询问收件人地址.

我有输出,但它打开弹出列表,而不是电子邮件,询问消息和蓝牙.

这是我的代码:

final Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "lets.think.android@gmail.com" });
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "App Error Report");
emailIntent.putExtra(Intent.EXTRA_TEXT, "stacktrace");
activity(Intent.createChooser(emailIntent, "Send error report..."));
Run Code Online (Sandbox Code Playgroud)

email android imagebutton

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

How can I compose variables names through loop in C#?

I have rewritten this question because not everyone understood. Hope it's ok, it's the same main problem.Very sorry

我有一个带有 15 个进度条的 winform,名为:“baraClasa1”、“baraClasa2”、“baraClasa3”...“baraClasa15”。我必须从一些数据库记录中将 .VALUE 属性(如int)分配给所有这些。(记录访问来自不同时间段的不同值)我在想,也许可以通过执行以下操作来使用循环将 .Value 属性分配给所有这些:

for(int i=0; i<value; i++)
{
   "baraClasa+i".Value = 20 + i;  
}
Run Code Online (Sandbox Code Playgroud)

是否可以像这样组成变量的名称?

我不太了解字典,列表,但正在研究。如果没有任何效果,我只会做丑陋的:

int value = 20;
baraClasa1 = value;
baraClasa2 = value +1;....
Run Code Online (Sandbox Code Playgroud)

谢谢大家的帮助

c# variables loops winforms

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

compose(*)函数如何在Ruby中工作(来自Ruby编程语言)?

摘录Ruby编程语言:

module Functional
  def compose(f)
    if self.respond_to?(:arity) && self.arity == 1
      lambda {|*args| self[f[*args]] }
    else
      lambda {|*args| self[*f[*args]] }
    end
  end
  alias * compose
end

class Proc; include Functional; end
class Method; include Functional; end

f = lambda {|x| x * 2 }
g = lambda {|x, y| x * y}
(f*g)[2, 3] # => 12
Run Code Online (Sandbox Code Playgroud)

if/else子句中f和*f有什么区别?

ruby functional-programming

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

重构PHP类

我正在玩重构PHP类.我的原始类有一个构造函数和一个大型方法,它通过各种操作运行字符串并在结尾处吐出结果.

class String
{
    public function __contstruct()
    {
        // a couple of initialisation things
    }

    public function make($string)
    {
        // very large method that does lots of different types of filtering to an input string
    }
}
Run Code Online (Sandbox Code Playgroud)

我的类通过scrutinizer-ci运行,其中一个建议是使用Composer方法模式将大方法重构为较小的自包含方法.

https://scrutinizer-ci.com/docs/refactorings/compose-method

我做了这个,看起来更整洁,但这是我的问题/查询......

我的新课程现在看起来像这样

class String
{
    public function __construct()
    {
        // a couple of initialisation things
    }

    public function make($string)
    {
        $string = $this->smallMethodOne($string);
        $string = $this->smallMethodTwo($string);
        $string = $this->smallMethodThree($string);
        $string = $this->smallMethodFour($string);
        $string = $this->smallMethodFive($string);
    }

    private function smallMethodOne($string) {
        // …
Run Code Online (Sandbox Code Playgroud)

php methods refactoring class

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

错误:无法使用R函数转换:as.data.frame

我正在尝试用C++读取文本文件并将其作为DataFrame返回.我创建了一个用于读取文件并返回它的框架方法:

// [[Rcpp::export]]
DataFrame rcpp_hello_world(String fileName) {

    int vsize = get_number_records(fileName);
    CharacterVector field1 = CharacterVector(vsize+1);

    std::ifstream in(fileName);

    int i = 0;
    string tmp;
    while (!in.eof()) {
      getline(in, tmp, '\n');
      field1[i] = tmp;
      tmp.clear( ); 
      i++;
    }
    DataFrame df(field1);
    return df;
}
Run Code Online (Sandbox Code Playgroud)

我在R中运行使用:

> df <- rcpp_hello_world( "my_haproxy_logfile" )
Run Code Online (Sandbox Code Playgroud)

但是,R返回以下错误:

Error: could not convert using R function : as.data.frame
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

非常感谢.

r rcpp

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

在DataFrame :: create(vec1,vec2 ...)中可以添加多少个向量?

我正在创建一个DataFrame来保存已解析的haproxy http日志文件,其中包含相当多的字段(25+).

如果我添加超过20个向量(每个字段一个),我得到编译错误:

no matching function call to 'create'
Run Code Online (Sandbox Code Playgroud)

创建方法:

    return DataFrame::create(
      _["clientIp"]     = clientIp,
      _["clientPort"]   = clientPort,
      _["acceptDate"]   = acceptDate,
      _["frontendName"] = frontendName,
      _["backendName"]  = backendName,
      _["serverName"]   = serverName,
      _["tq"]           = tq,
      _["tw"]           = tw,
      _["tc"]           = tc,
      _["tr"]           = tr,
      _["tt"]           = tt,
      _["status_code"]  = statusCode,
      _["bytes_read"]   = bytesRead,

#if CAPTURED_REQUEST_COOKIE_FIELD == 1
      _["capturedRequestCookie"]   = capturedRequestCookie,
#endif     

#if CAPTURED_REQUEST_COOKIE_FIELD == 1
      _["capturedResponseCookie"]   = capturedResponseCookie,
#endif    

      _["terminationState"] = terminationState,
      _["actconn"]          = actconn,
      _["feconn"]           = feconn,
      _["beconn"]           = beconn,
      _["srv_conn"] …
Run Code Online (Sandbox Code Playgroud)

rcpp

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

bookmarklet将参数添加到url并重新提交?

书签是否可以实现以下功能?

  1. 向URL添加其他参数(include_docs = true)
  2. 重新提交URL

我有这个但它在firefox上无声地失败了.我没有尝试过其他浏览器:

javascript:(

   function()
   {
      key = encodeURI('include_docs'); value = encodeURI('true');

      var kvp = document.location.search.substr(1).split('&');

      var i=kvp.length; var x; while(i--) 
      {
        x = kvp[i].split('=');

        if (x[0]==key)
        {
            x[1] = value;
            kvp[i] = x.join('=');
            break;
        }
      }
      if(i<0) {kvp[kvp.length] = [key,value].join('=');}

      //this will reload the page, it's likely better to store this until finished
      document.location.search = kvp.join('&'); 
  }()
);
Run Code Online (Sandbox Code Playgroud)

javascript bookmarklet

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

暂时禁用bash中的'set-e'/'set -o errexit'?

我有一个脚本用于killall确保应用程序在启动之前尚未运行:

#!/bin/bash

set -e

some_command
another_command

sudo killall myapp # this causes the script to fail if myapp isn't running
sleep 10
myapp start
Run Code Online (Sandbox Code Playgroud)

但是,如果myapp未运行,killall将退出脚本,因为它返回错误.

解决此问题的一个选项是暂时禁用set -o errexit:

#!/bin/bash

set -e

some_command
another_command

set +e
sudo killall myapp # this causes the script to fail if myapp isn't running
set -e
sleep 10
myapp start
Run Code Online (Sandbox Code Playgroud)

但是,上述方法相当混乱.还有哪些其他选项暂时禁用set -e

linux bash ubuntu

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