我正在审查Scala的考试,并试图找出我错过的这个测验问题.我理解尾递归是"最后一次调用本身",但我对其中一些代码片段之间的区别感到困惑.为什么这被认为是尾递归,
def f(x: Int): Int = {
if (x % 2 == 0) {1}
else {f(x + 1)}
Run Code Online (Sandbox Code Playgroud)
但是,这不是吗?
def f(x: Int): Int = {
if (x % 2 == 0) {1}
else {1 + f(x + 1)}
Run Code Online (Sandbox Code Playgroud)
为函数添加1究竟是什么限制了它是尾递归?如果这是一个愚蠢的问题,我很抱歉,我没有看到数字的影响,并希望巩固我的理解.完全能够识别尾递归的任何其他指针也会很棒!
我正在使用 PHPUnit 运行所有测试。创建了一个包装器,用于启动 Apache 实例,然后启动 Selenium 独立服务器,然后在http://localhost:4444/wd/hub创建 Chrome Remote Webdriver 实例。这个过程在我们的开发机器上 100% 的时间有效,在测试服务器上 90% 的时间有效,但有时测试会失败,如下所示:
[exec] 1) Intranet\Pages\FinancialReportsSeleniumTest::test_changeMonthYear
[exec] Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http POST to /session with params: {"desiredCapabilities":{"browserName":"chrome","platform":"ANY","chromeOptions":{"binary":"","args":["--window-size=1400,900","--no-sandbox","--headless"]},"goog:chromeOptions":{"args":["--window-size=1400,900","--no-sandbox","--headless"]}}}
[exec]
[exec] Failed to connect to localhost port 4444: Connection refused
[exec]
[exec] C:\Jenkins\jobs\Intranet-Master\workspace\vendor\facebook\webdriver\lib\Remote\HttpCommandExecutor.php:292
[exec] C:\Jenkins\jobs\Intranet-Master\workspace\vendor\facebook\webdriver\lib\Remote\RemoteWebDriver.php:126
[exec] C:\Jenkins\jobs\Intranet-Master\workspace\phpunit\library\Intranet\Selenium.php:364
[exec] C:\Jenkins\jobs\Intranet-Master\workspace\phpunit\library\Intranet\Selenium.php:51
[exec] C:\Jenkins\jobs\Intranet-Master\workspace\phpunit\library\Intranet\SeleniumTestCase.php:9
Run Code Online (Sandbox Code Playgroud)
如果我们重新运行测试,下次就可以正常工作。
开发机器:
试验机
windows selenium phpunit google-chrome selenium-chromedriver
我得到一个数组返回给我,我需要计算其中有值的行
我试过调用arr.length,但这给了我数组的总长度
var arr = [
{ id: '1', '': '' },
{ id: '2', '': '' },
{ id: '3', '': '' },
{ id: '4', '': '' },
{ id: '', '': '' },
{ id: '', '': '' },
{ id: '', '': '' }
]
Run Code Online (Sandbox Code Playgroud)
结果应该是4.
我试图通过嵌套属性在我的数据库中找到一个对象,我似乎找不到任何方法来做到这一点。我的架构如下,我已经展示了我如何尝试查询。
var stations = {
Alpha: Number,
Beta: Number
};
var systemSchema = new mongoose.Schema({
name: String,
location: String,
nodes: {
main: stations,
secondary: stations,
tertiary: stations
}
});
var System = mongoose.model("System", systemSchema);
System.findOne({ nodes: { main: {Alpha: 23000}}}, function(err, system){
if(err){console.log(err);}
else{console.log(system);}
});
Run Code Online (Sandbox Code Playgroud)
每次我运行它时,都不会返回任何内容。我原以为我的数据库中会返回相应的对象。
升级到Cordova Android 8.0后,net::ERR_CLEARTEXT_NOT_PERMITTED尝试连接http://目标时出现错误。
为什么会这样,我该如何解决呢?
我有
BillingFlowParams purchaseParams = BillingFlowParams.newBuilder().setSku(skuId).setType(billingType).setOldSkus(oldSkus).build();
Run Code Online (Sandbox Code Playgroud)
但现在
setSku
setType
setOldSkus
Run Code Online (Sandbox Code Playgroud)
都被弃用了。
我想更新旧代码而不发布会干扰当前订阅和未来订阅的更新。我应该如何正确更新上述代码?
目前我使用aString myProduct="my_newsweek_1";
来识别购买和BillingClient.SkuType.SUBS识别类型,我只是简单地传递null给setOldSkus
文档报告说
setSku (String sku)并setType (String type)已被替换为setSkuDetails(SkuDetails)
(此SkuDetails对象String在构造函数中仅接收一个作为参数并抛出,JSONException因此似乎它不适用于旧String常量)
和
setOldSkus(ArrayList<String> oldSkus) 已被替换为 setOldSku(String)
我要求测试服务器应该使用端口范围 20000 - 22767
我kubeadm-config用命令编辑了
kubectl edit cm kubeadm-config -n kube-system
当我查看结果时,我发现更改似乎已被存储:
命令$ kubeadm config view给了我
apiServer:
extraArgs:
authorization-mode: Node,RBAC
service-node-port-range: 20000-22767
timeoutForControlPlane: 4m0s
apiVersion: kubeadm.k8s.io/v1beta1
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controlPlaneEndpoint: ""
controllerManager: {}
dns:
type: CoreDNS
etcd:
local:
dataDir: /var/lib/etcd
imageRepository: k8s.gcr.io
kind: ClusterConfiguration
kubernetesVersion: v1.13.3
networking:
dnsDomain: cluster.local
podSubnet: 10.244.0.0/16
serviceSubnet: 10.96.0.0/12
scheduler: {}
Run Code Online (Sandbox Code Playgroud)
但是当我稍后尝试在新端口范围内安装某些东西时,我收到错误
helm upgrade --install --kubeconfig /external-storage/workspace/potapi-orchestration/clusters/at/admin.conf potapi-services charts/potapi-services -f charts/potapi-services/values.at.yaml
Error: UPGRADE FAILED: Service "potapi-services" is invalid: spec.ports[0].nodePort: Invalid value: …Run Code Online (Sandbox Code Playgroud) 我正在将.NetFramework 4.6.1库迁移到.NetCore 2.2。但是我无法设置x509certificate.PrivateKey,如下所示。
我读过这可能是由于RSAServiceProvider引起的,但我不知道如何设置此属性。甚至实例化:
x509certificate.PrivateKey = new RSACryptoServiceProvider();
引发PlatformNotSupportedException。
// selfsign certificate
Org.BouncyCastle.X509.X509Certificate certificate =
certificateGenerator.Generate(signatureFactory);
// correponding private key
PrivateKeyInfo info =
PrivateKeyInfoFactory.CreatePrivateKeyInfo(subjectKeyPair.Private);
// merge into X509Certificate2
var x509certificate = new X509Certificate2(certificate.GetEncoded());
Asn1Sequence seq = (Asn1Sequence)
Asn1Object.FromByteArray(info.ParsePrivateKey().GetDerEncoded()
);
RsaPrivateKeyStructure rsa = RsaPrivateKeyStructure.GetInstance(seq);
RsaPrivateCrtKeyParameters rsaParams = new
RsaPrivateCrtKeyParameters(
rsa.Modulus,
rsa.PublicExponent,
rsa.PrivateExponent,
rsa.Prime1,
rsa.Prime2,
rsa.Exponent1,
rsa.Exponent2,
rsa.Coefficient);
x509certificate.PrivateKey = DotNetUtilities.ToRSA(rsaParams);
Run Code Online (Sandbox Code Playgroud)
在.NetCore库中,将x509certificate.PrivateKey与DotNetUtilities.ToRSA(rsaParams)中的RSA一起设置,将引发PlatformNotSupportedException。
System.PlatformNotSupportedException
HResult=0x80131539
Message=Operation is not supported on this platform.
Source=System.Security.Cryptography.X509Certificates
StackTrace:
at System.Security.Cryptography.X509Certificates.X509Certificate2.set_PrivateKey(AsymmetricAlgorithm value)
Run Code Online (Sandbox Code Playgroud) 何时应该使用以下陈述之一?
typedef struct Foo {
int a;
} Bar;
Run Code Online (Sandbox Code Playgroud)
和
typedef struct {
int a;
} Bar;
Run Code Online (Sandbox Code Playgroud)
并使用它
Bar bar1 = { 5 };
Run Code Online (Sandbox Code Playgroud)
我理解第二个是匿名结构但不确定何时应该使用另一个结构.
我正在使用Terraform在AWS中构建一些基础架构。我创建了几个S3存储桶,并希望Glue搜寻器每小时对这些存储桶进行一次爬网。我的Terraform Glue目录数据库,角色和策略都构建良好,但是当我尝试通过向爬网程序的s3_target{}一部分添加四个S3路径来创建爬网程序资源时,出现了故障:
resource "aws_glue_crawler" "datalake_crawler" {
database_name = "${var.glue_db_name}"
name = "${var.crawler_name}"
role = "${aws_iam_role.glue.id}"
s3_target {
# count = "${length(var.data_source_path)}"
path = "${var.data_source_path}"#"${formatlist("%s", var.data_source_path)}"
}
}
Run Code Online (Sandbox Code Playgroud)
这会导致错误:
Error: aws_glue_crawler.datalake_crawler: s3_target.0.path must be a single value, not a list
Run Code Online (Sandbox Code Playgroud)
我尝试在中添加一条count语句,s3_target但这失败。我也尝试添加
"${formatlist("%s", var.data_source_path)}"
Run Code Online (Sandbox Code Playgroud)
在path争论中,但这也失败了。
我可以s3使用Terraform向Glue履带添加多个路径吗?我可以通过AWS控制台实现这一点,但这需要使用基础架构作为代码来完成。
amazon-s3 amazon-web-services terraform aws-glue terraform-provider-aws