我遇到了这个没有主要方法的小quine程序:
enum f {
f;
System z;
String s="enum f{f;System z;String s=%c%s%1$c;{z.out.printf(s,34,s);z.exit(0);}}";
{z.out.printf(s,34,s);
z.exit(0);}
}
Run Code Online (Sandbox Code Playgroud)
有人可以解释这是如何工作的?谢谢.
我有一个休息应用程序,其中一个资源可以更新.以下是负责实现此任务的两种方法:
updateWithRelatedEntities(String,Store):接收通过反序列化PUT请求实体构造的id和新对象Store,在新对象上设置版本(用于乐观锁定)并在事务中调用update.
public Store updateWithRelatedEntities(String id, Store newStore) {
Store existingStore = this.get(id);
newStore.setVersion(existingStore.getVersion());
em.getTransaction().begin();
newStore = super.update(id, newStore);
em.getTransaction().commit();
return newStore;
}
Run Code Online (Sandbox Code Playgroud)update(String,T):进行更新的通用方法.检查id是否匹配并执行合并操作.
public T update(String id, T newObj) {
if (newObj == null) {
throw new EmptyPayloadException(type.getSimpleName());
}
Type superclass = getClass().getGenericSuperclass();
if (superclass instanceof Class) {
superclass = ((Class) superclass).getGenericSuperclass();
}
Class<T> type = (Class<T>) (((ParameterizedType) superclass).getActualTypeArguments()[0]);
T obj = em.find(type, id);
if (!newObj.getId().equals(obj.getId())) {
throw new IdMismatchException(id, newObj.getId());
}
return em.merge(newObj);
}
Run Code Online (Sandbox Code Playgroud)问题是这个调用:T …
当用户与自定义共享按钮共享内容时,有没有办法添加回调?
目前我在弹出窗口中打开一个共享对话框:
<a data-height="600" data-title="Google+" class="popup" href="https://plus.google.com/share?url=MY_URL">Share</a>
$('.popup').click(function(event) {
var width = 575,
height = $(this).data('height'),
left = ($(window).width() - width) / 2,
top = ($(window).height() - height) / 2,
url = this.href,
opts = 'status=1' +
',width=' + width +
',height=' + height +
',top=' + top +
',left=' + left;
window.open(url, $(this).data('title'), opts);
event.preventDefault();
});
Run Code Online (Sandbox Code Playgroud)
在文档中:https://developers.google.com/+/web/share/他们说,我们可以在使用js api时使用data-onendinteraction指定回调.找不到使用自定义共享链接的方法.
我想检查iframe是否加载了以下代码:
$(document).ready(function() {
jQuery('#iframeID').ready(somefunction);
}
Run Code Online (Sandbox Code Playgroud)
似乎在加载iframe之前调用了'somefunction'(iframe为空 - 只是空的html-head-body).
知道为什么会这样吗?
谢谢.
是否可以在运行时更改字段注释值?
我可以访问这些值,但无法找到更改它们的方法.
可以访问:
Article.class.declaredFields.find {it.name="annotatedField"}.declaredAnnotations
Run Code Online (Sandbox Code Playgroud) 这是我的映射器:
@Mapper
public interface ProductMapper {
ProductClassification toProductClassification(ProductTypes pisType);
}
Run Code Online (Sandbox Code Playgroud)
其中ProductTypes和ProductClassification是枚举。我希望它在无法映射枚举时抛出异常,但出现编译器错误:
The following constants from the source enum have no corresponding constant in the target enum and must be be mapped via adding additional mappings: EXTERNAL, UNKNOWN.
我尝试使用@ValueMappings注释,但只能将其配置为将值设置为 null,这是不够的:
@ValueMappings({
@ValueMapping(source = MappingConstants.ANY_REMAINING, target = MappingConstants.NULL)
})
Run Code Online (Sandbox Code Playgroud)
将 MapStruct 映射器配置为在无法映射枚举常量时抛出异常的正确方法是什么?
我有一个字符串数组,实际上是数据集的名称.我对每个数据集执行几个度量,并在矩阵中获得每个度量的结果.
我想在一些数据结构中保存一个数据集的结果.
所以,例如:
我们有一个字符串"玻璃".根据数据集"玻璃"的测量结果,得到3个矩阵a,b,c.我如何在一个结构中保存a,b,c?
谢谢.
我有2个数据帧 - 用L行学习数据和用T行测试数据.
我想计算一个L*T矩阵,其中包含相应元素之间的距离(欧几里德,曼哈顿,余弦......).
这是我的看法:
distance2 <- function (x1, x2) {
temp <- x1 - x2
sum(temp * temp)
}
m <- matrix(0,nrow(learnData),nrow(testData))
for(td in 1:nrow(testData)) {
for(ld in 1:nrow(learnData)) {
m[ld,td] <- distance2(testData[td,],learnData[ld,])
}
}
Run Code Online (Sandbox Code Playgroud)
我认为这可以用更紧凑的"R"方式完成.有任何想法吗?谢谢.
我正在编写一个从(简化的)Pascal到ARM asm的编译器.我正处于这个过程的第二步 - 在编写词法分析器之后,我正在使用java cup进行语法分析.
我写了我的语法,但有5个S/R冲突,这些都非常相似.例:
Warning : *** Shift/Reduce conflict found in state #150
between assign_stmt ::= val_expr ASSIGN val_expr (*)
and val_expr ::= val_expr (*) LBRACKET val_expr RBRACKET
under symbol LBRACKET
Resolved in favor of shifting
Run Code Online (Sandbox Code Playgroud)
我这节的语法:
assign_stmt ::=
val_expr ASSIGN val_expr;
val_expr ::=
NIL | BOOL_CONST | INT_CONST | CHAR_CONST | PTR val_expr %prec MEM | ADD val_expr %prec UADD |
SUB val_expr %prec USUB | NOT val_expr | val_expr PTR %prec VAL | val_expr …Run Code Online (Sandbox Code Playgroud) 我正在使用nginx模块进行文件拍,以将日志数据发送到elasticsearch。这是我的文件拍配置:
output:
logstash:
enabled: true
hosts:
- logstash:5044
timeout: 15
filebeat.modules:
- module: nginx
access:
enabled: true
var.paths: ["/var/log/nginx/access.log"]
error:
enabled: true
var.paths: ["/var/log/nginx/error.log"]
Run Code Online (Sandbox Code Playgroud)
问题是未解析日志。这是我在Kibana中看到的:
{ "_index": "filebeat-2017.07.18", "_type": "log", "_id": "AV1VLXEbhj7uWd8Fgz6M", "_version": 1, "_score": null, "_source": {
"@timestamp": "2017-07-18T10:10:24.791Z",
"offset": 65136,
"@version": "1",
"beat": {
"hostname": "06d09033fb23",
"name": "06d09033fb23",
"version": "5.5.0"
},
"input_type": "log",
"host": "06d09033fb23",
"source": "/var/log/nginx/access.log",
"message": "10.15.129.226 - - [18/Jul/2017:12:10:21 +0200] \"POST /orders-service/orders/v1/sessions/update/FUEL_DISPENSER?api_key=vgxt5u24uqyyyd9gmxzpu9n7 HTTP/1.1\" 200 5 \"-\" \"Mashery Proxy\"",
"type": "log",
"tags": [
"beats_input_codec_plain_applied"
] }, …Run Code Online (Sandbox Code Playgroud) 我有一个像这样的二维数组(它代表一个时间表):
替代文字http://www.shrani.si/f/28/L6/37YvFye/timetable.png
橙色细胞是讲座,白色是空闲时间.我如何计算同一天讲座之间的免费小时数?(列是天,行是小时)
例如,在此表中,结果应为:
2表示第二列
0表示第二列
- >函数返回2(因为2 + 0 = 2)
如何编写一个countTo(n)从1到n计数的函数并打印每个数字而不使用显式循环(仅递归)?
解决方案必须在空间和时间上渐近最优,即使没有尾调用优化,任意大n.
注意:最佳时间复杂度为O(1),而最佳空间复杂度为O(log n) - 即使在迭代情况下,因为需要打印(任意大的)数字.
问题来自lesswrong.com,相关细节来自那里的讨论(否则问题变得无法回答,因为他们的原始陈述会产生误导性的假设).