我有一个文件,其唯一目的是在对象中提供大量的键/值对.它看起来像这样:
var myobj = {
some_key: 'some value',
another_key: 'another value',
// thousands of other key/value pairs...
some_key: 'accidental duplicate key with different value'
};
Run Code Online (Sandbox Code Playgroud)
现在,当我引用该文件并引用some_key时,我得到了意外的重复值,因为JavaScript将存储最后声明的密钥.
我想编写一个单元测试,检查此对象是否有意外的重复键.问题是JavaScript已经删除了重复项.我如何通过单元测试完成此检查?
(一个答案是使用字符串解析手动解析文件以找到重复项.这很脆弱,我想远离这个.)
#include <array>
#include <vector>
#include <cinttypes>
#include <iostream>
using namespace std;
template<size_t N>
struct item_t {
array<uint32_t, N> weight = {0};
};
int main(void) {
vector<item_t<3>> items;
items.emplace_back({{9,2,3}});
cout << items[0].weight[0] << endl;
return 0;
};
Run Code Online (Sandbox Code Playgroud)
我在这里有点不知所措。错误在 emplace_back 线上,不知道如何解决。任何帮助或提示将不胜感激,谢谢。
编辑
gcc 版本 4.8.2
$ g++ -std=c++11 test.cpp
test.cpp: In function ‘int main()’:
test.cpp:16:30: error: no matching function for call to ‘std::vector<item_t<3ul> >::emplace_back(<brace-enclosed initializer list>)’
items.emplace_back({{9,2,3}});
^
test.cpp:16:30: note: candidate is:
In file included from /usr/include/c++/4.8/vector:69:0,
from test.cpp:2:
/usr/include/c++/4.8/bits/vector.tcc:91:7: note: void …
Run Code Online (Sandbox Code Playgroud) 我正在尝试获取输入文本字段的值并将其乘以数量并显示在总列上.
这是jsfiddle
HTML
Price: <input id="price" type="text"/>
<table id="my-table">
<tr>
<td>Quantity</td>
<td>Total</td>
</tr>
<tr>
<td class="quantity">15,447.84</td>
<td class="total"></td>
</tr>
<tr>
<td class="quantity">89.28</td>
<td class="total"></td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
Srript
$(document).ready(function () {
$('#price').on('change', calTotal);
function calTotal() {
var p = $('#price').val();
var q = $('.quantity').text();
alert(q);
}
});
Run Code Online (Sandbox Code Playgroud)
var q = $('.quantity').text();
给我输出为15,447.8489.28
.
我如何乘以每个quantity
价格并在总列上打印?
我正在Mac上运行boot2docker.OSX版本10.9.3 boot2docker版本4.3.12 Docker版本0.12.0
boot2docker映像是一个使用virtualbox的vagrant box.我尝试过一些流浪盒(例如stigkj/boot2docker).所有人都表现出这个问题.
如果我ssh到boot2docker映像并查看/etc/resolv.conf它使用的是nameserver 10.0.2.3.
我使用以下命令启动一个简单的docker镜像:
docker run -i -t ubuntu /bin/sh
Run Code Online (Sandbox Code Playgroud)
查看该容器中的/etc/resolv.conf,它使用8.8.8.8和8.8.4.4作为名称服务器.
在docker.log
boot2docker vm 的文件中,有这一行:
2014/06/30 15:25:01 Local (127.0.0.1) DNS resolver found in resolv.conf and containers can't use it. Using default external servers : [8.8.8.8 8.8.4.4]
Run Code Online (Sandbox Code Playgroud)
根据我的理解,docker应该使用主机的名称服务器.仅当主机使用127.0.0.1作为其名称服务器时,它才应默认为google名称服务器作为备份.
主机没有使用127.0.0.1作为名称服务器,但似乎docker认为它是.有关如何让它正确检测名称服务器的任何建议?
我不知道如何用它来表达它或它实际上被称为什么,但我知道在Objective-C中你可以有多个构造函数可以连续相互调用,原谅任何代码错误,我有一段时间没有这样做,但这个想法就在那里.
- (id)initWithTitle:(NSString *)_title;
- (id)initWithTitle:(NSString *)_title page:(NSString *)_page;
-----------------------------------
- (id)initWithTitle:(NSString *)_title {
return [self initWithTitle:_title page:nil];
}
- (id)initWithTitle:(NSString *)_title page:(NSString *)_page {
if(self = [super init]) {
self.title = _title;
self.page = _page;
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
我只是想知道在c ++中是否有相同的东西;
我尝试通过PHP GD来制作Captcha。但是不幸的是我遇到了一个问题!PHP告诉我:
The image “http://127.0.0.1/par.php” cannot be displayed because it contains errors.
Run Code Online (Sandbox Code Playgroud)
我的代码是这样
<?php
header ('Content-Type: image/png');
$im = @imagecreatetruecolor(120, 20)
or die('Cannot Initialize new GD image stream');
$text_color = imagecolorallocate($im, 233, 14, 91);
$red = imagecolorallocate($im, 255, 0, 0);
for ($i=0;i<=120;$i=$i+1){
for ($j=0;$j<=20;$j=$j+1){
imagesetpixel($im, $i,$j,$red);
}
}
imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color);
imagepng($im);
imagedestroy($im);
?>
Run Code Online (Sandbox Code Playgroud) 我想在视图控制器弹出或推送导航控制器堆栈时收到通知。我试着用
- (void)setViewControllers:(NSArray *)viewControllers
Run Code Online (Sandbox Code Playgroud)
但我失败了。而且我不想使用委托方法来实现这一点......
在scala源代码中,我发现:
case object Nil extends List[Nothing] {
...
}
Run Code Online (Sandbox Code Playgroud)
我不明白为什么它被宣布为case object
而不是object
?
我发现这个问题[ 案例对象和对象之间的区别 ]是有用的,我猜这个原因是关键:
序列化的默认实现
因为我们经常将数据列表发送给另一个actor,所以Nil必须是可序列化的,对吧?
通过提供的答案(谢谢),我尝试编写一些代码来验证它:
trait MyList[+T]
object MyNil extends MyList[Nothing]
val list: MyList[String] = MyNil
list match {
case MyNil => println("### is nil")
case _ => println("### other list")
}
Run Code Online (Sandbox Code Playgroud)
你可以看到MyNil
不是case object
,但我仍然可以在模式匹配中使用它.这是输出:
### is nil
Run Code Online (Sandbox Code Playgroud)
我误解了什么吗?
我正在尝试设置一个概念证明,以便将我们的表单身份验证与SQL成员资格提供程序一起转移到代理身份验证过程中.为了做到这一点,我计划利用Thinktecture的Identity Server 2作为身份提供者.
我已经下载了IdentityServer 2并安装了它并尝试按照此处的说明进行操作:http: //www.cloudidentity.com/blog/2014/02/20/ws-federation-in-microsoft-owin-componentsa-quick-start/
但是,每当我尝试访问受AuthorizeAttribute限制的控制器操作时,我得到一个401的HttpResponse而不是重定向到IdentityServer的登录页面.Startup.Auth.cs设置如下:
public partial class Startup
{
public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(WsFederationAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = WsFederationAuthenticationDefaults.AuthenticationType
});
app.UseWsFederationAuthentication(new WsFederationAuthenticationOptions
{
MetadataAddress = "https://dvancuykidstrial.cloudapp.net/FederationMetadata/2007-06/FederationMetadata.xml"
,Wtrealm = "http://owin2.testing.com/"
,AuthenticationMode = AuthenticationMode.Passive
,BackchannelCertificateValidator = new FakeCertificateValidator()
});
}
}
Run Code Online (Sandbox Code Playgroud)
顺便提一下,FakeCertificateValidator只是ICertificateValidator的一个实现,它只在调用Validate函数时返回true.这只是让我通过我用于PoC的自签名证书.
public class FakeCertificateValidator : ICertificateValidator
{
public bool Validate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
谁能看到我在这里做错了什么?
我定义了一个类成员如下:
private static List abc = Collections.synchronizedList(new ArrayList());
Run Code Online (Sandbox Code Playgroud)
但Eclipse给了我警告:
Type safety: Unchecked invocation synchronizedList(ArrayList) of the generic method synchronizedList(List<T>) of type Collections
Run Code Online (Sandbox Code Playgroud)
是否有另一种方法来编写此声明语句以避免警告?