我部署了一个AWS EC2实例,我需要找到它的公共IP.但是,要知道我必须首先知道我的实例的实例ID.
目的:
在阅读了亚马逊文档后,我想出了一个返回所有实例的IP的Java方法,但这不是我想要的,我想要一个只返回正在运行的实例的instance-id或公共IP地址的方法.
/**
* Returns a list with the public IPs of all the active instances, which are
* returned by the {@link #getActiveInstances()} method.
*
* @return a list with the public IPs of all the active instances.
* @see #getActiveInstances()
* */
public List<String> getPublicIPs(){
List<String> publicIpsList = new LinkedList<String>();
//if there are no active instances, we return immediately to avoid extra
//computations.
if(!areAnyActive())
return publicIpsList;
DescribeInstancesRequest request = new DescribeInstancesRequest();
request.setInstanceIds(instanceIds);
DescribeInstancesResult …Run Code Online (Sandbox Code Playgroud) 我正在使用文本框的summernote插件:http://summernote.org/#/getting-started#basic-api
这是我使用summmernote的形式:
<div class="modal-body" style="max-height: 600px">
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<fieldset class="form-horizontal">
<div id="textForLabelLanguage"></div>
<button type="submit" class="btn btn-primary">Save changes</button>
@Html.ActionLink("Cancel", "Index", null, new { @class = "btn " })
</fieldset>
}
</div>
<script type="text/javascript">
$(document).ready(function () {
$('#textForLabelLanguage').summernote();
});
</script>
Run Code Online (Sandbox Code Playgroud)
现在,在我的控制器中,这是我的代码:
public ActionResult Create(UserInfo newInfo , [Bind(Prefix = "textForLabelLanguage")] string textForLabelLanguage)
{
//logic here
}
Run Code Online (Sandbox Code Playgroud)
现在问题是textForLabelLanguageparam总是为null.
发生这种情况是因为我在提交$('#textForLabelLanguage').code();表单时必须传入MVC,但我不知道该怎么做!
我该如何解决我的问题?
我有一个可以使用schedule(static)或schedule(dynamic, 10)根据条件执行的for循环.目前,我的代码不是DRY(不要重复自己),为了适应以前的功能,它有以下重复:
boolean isDynamic; //can be true or false
if(isDynamic){
#pragma omp parallel for num_threads(thread_count) default(shared) private(...) schedule(dynamic, 10)
for(...){
//for code inside
}
}else{
#pragma omp parallel for num_threads(thread_count) default(shared) private(...) schedule(static)
for(...){
//SAME for code inside, in fact, this is the EXACT same for as before
}
}
Run Code Online (Sandbox Code Playgroud)
阅读完这些主题之后,我注意到openMP有一个#if(expression)pragma:
但是虽然我看到很多人遇到了我的问题,但似乎缺乏一般的解决方案.最好的解决方案是将for循环的主体转换为函数,然后调用函数,但这个解决方案对我来说还不够好.
所以我想知道,OpenMP有一种#if(expression) else实用主义吗?就像是:
#if(isDynamic )pragma omp parallel for num_threads(thread_count) default(shared)
private(...) schedule(dynamic, 10)
else …Run Code Online (Sandbox Code Playgroud) 在我们的代码库中,我们遇到了sinon的问题,可以使用下面的代码复制.事情是,它似乎是间接称为间谍回归力false,console.log明确表示该方法被称为但spy.called遗骸false.
以下CDN可用于html:
//cdnjs.cloudflare.com/ajax/libs/sinon.js/1.7.3/sinon-min.js
//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.14/require.min.js
Run Code Online (Sandbox Code Playgroud)
main.js
require(['myModule'], function(module) {
//using sinon
var methodCallerSpy = sinon.spy(module, 'methodCaller')
console.log(methodCallerSpy); // methodCaller
module.methodCaller();
console.log(methodCallerSpy.called); //true
var methodSpy = sinon.spy(module, 'method');
console.log(methodSpy); //method
module.methodCaller();
console.log(methodSpy.called); // false
module.method();
console.log(methodSpy.called); // true
});
Run Code Online (Sandbox Code Playgroud)
和模块
define(function() {
const method = () => console.log('method called by methodCaller');
const methodCaller = () => method();
return{
method,
methodCaller
}
});
Run Code Online (Sandbox Code Playgroud) 我一直都知道要在javascript中声明一个函数你应该做的事情如下:
function myfunction(fruit){
alert('I like ' + fruit + '!');
}
Run Code Online (Sandbox Code Playgroud)
或类似的东西:
var myfunction = function(fruit){
alert('I like ' + fruit + '!');
};
Run Code Online (Sandbox Code Playgroud)
但是,最近,我注意到有些人实际上将函数定义为常量:
const myfunction = fruit=> alert('I like ' + fruit + '!');
Run Code Online (Sandbox Code Playgroud)
甚至使用关键字let:
let myfunction = fruit=> alert('I like ' + fruit + '!');
Run Code Online (Sandbox Code Playgroud)
此时我很困惑.
我在Nodejs中有一个使用ECMA6类的项目,我使用JSDoc来评论我的代码,以使其更容易被其他开发人员访问.
但是,这个工具并没有很好地接受我的评论,而且我的文档是一个火车残骸.
我的问题是我不知道如何用JSDoc记录ECMA6类,我找不到任何体面的信息.
我尝试阅读官方示例,但我发现它缺乏和不完整.我的类有成员,常量变量等等,我通常不知道使用哪些标记.
我还在网上进行了广泛的搜索,但我发现的大部分信息都是在2015年之前,JSDocs还不支持ECMA6脚本.最近的文章很少,不能满足我的需求.
我发现最接近的是这个GitHub问题:
但它现在已经过时了.
我的主要目标是学习如何使用JSDoc在NodeJS中记录ECMA6类.
我有一个确切的例子,我希望看到正常工作:
/**
* @fileOverview What is this file for?
* @author Who am I?
* @version 2.0.0
*/
"use strict";
//random requirements.
//I believe you don't have to document these.
let cheerio = require('cheerio');
//constants to be documented.
//I usually use the @const, @readonly and @default tags for them
const CONST_1 = "1";
const CONST_2 = 2;
//An example class
class MyClass { …Run Code Online (Sandbox Code Playgroud) 我正在尝试优化我的移动网页的加载速度,为此我正在使用该网站:
这个网站评估我的来源并告诉我我可以改进什么.在我的网站上我下载了一个字体:
<link href="//fonts.googleapis.com/css?family=Open+Sans:400,700" rel="stylesheet">
Run Code Online (Sandbox Code Playgroud)
并且显然这阻止了我的页面的渲染.现在,如果这是JavaScript我可以使用async标签中的单词,它将解决问题,但这不是我正在加载的javascript文件!
反正有没有阻止我的浏览器阻止我的浏览器,并迫使它等待下载?
我正在net.Socket通过 TCP/IP与一台机器进行通信。
我能够建立连接并发送和接收缓冲区的数据包,这一切都很好。
问题是,如果我手动断开互联网电缆与机器的连接,我的 Node.js 连接不会触发该close事件,而且我无法知道是否出现故障!
let socket;
const start = async function ( config ) {
await connecToBarrier( config )
.then( () => console.log( "connected to barrrier" ) )
.catch( err => {
throw new Error( `Cannot connect to barrier: ${err}` );
} );
};
const connecToBarrier = function ( connectOpts ) {
return new Promise( ( resolve, reject ) => {
//connectOpts is an object with 'port' and 'host'
socket = …Run Code Online (Sandbox Code Playgroud) 我试图以纯粹的功能方式创建循环算法(https://en.wikipedia.org/wiki/Round-robin_scheduling).
该函数应该接收如下数组:
[
[ 1, 2 ],
[ 3, 4 ]
]
Run Code Online (Sandbox Code Playgroud)
并产生以下输出:
[ 1, 3, 2, 4 ]
为实现这一目标,我决定以递归方式实现循环,如下所示:
const roundRobin = (arr, results) => {
if (arr.length === 0) return results;
const newResults = arr.reduce((acc, current) => {
if (current.length > 0) {
acc.results.push(current.shift());
acc.arr.push(current);
}
return acc;
}, { arr: [], results });
return roundRobin(newResults.arr, newResults.results);
};
Run Code Online (Sandbox Code Playgroud)
在这里,我感觉到一系列结果,当我没有任何东西可以添加时,我就完成了.可以使用以下代码:
const array = [
[ 1, 2 ],
[ 3, 4 ]
];
const result …Run Code Online (Sandbox Code Playgroud) 我是一名开发人员,拥有大约9年的Java和C#背景历史.
在那些语言中,类和分类分类以及对象范例固有.
因此,当ECMA6出来时,我很高兴看到语言课程......我开始在各处使用它们.
事实证明,在JavaScript中使用类是一个陷阱.
你永远不会真正理解JavaScript.你会认为你这样做,但你没有.
很明显,在看完这个完整的会议后,我意识到我不懂JavaScript.
我的生活中我已经使用OOP格式化了类范例,现在我甚至不知道在哪里寻求帮助,甚至不知道如何开始.
非JavaScvript的一个例子:
class Animal{
constructor(aName){
this.name = aName;
}
}
class Dog extends Animal{
constructor(){
super(aName);
this.type = "Furry dog";
}
}
let myDog = new Dog("Boby");
Run Code Online (Sandbox Code Playgroud)
在这一点上,我正在寻找指导.在尝试之后我找不到任何有用的东西,主要是因为我相信我迷失了以至于我甚至都没有找到正确的东西.
提前致谢.
javascript ×7
node.js ×2
amazon-ec2 ×1
asp.net-mvc ×1
c# ×1
c++ ×1
conditional ×1
css ×1
ecmascript-6 ×1
forms ×1
function ×1
html ×1
ip ×1
java ×1
jsdoc ×1
openmp ×1
pragma ×1
render ×1
sinon ×1
sockets ×1
summernote ×1
tcp-ip ×1