小编Nat*_*rot的帖子

Eunit超时不起作用

我试图在文件夹中使用eunit运行所有单元测试,但似乎超时总是重置为5秒.

例如

模块:

-module(example).
-include_lib("eunit/include/eunit.hrl").

main_test() ->
    % sleep for 10 seconds
    ?assertEqual(true, begin timer:sleep(10000), true end).
Run Code Online (Sandbox Code Playgroud)

命令行:

Eshell V5.7.3  (abort with ^G)
1> c(example).
{ok,example}
2> eunit:test({timeout, 15, example}).
  Test passed.
ok
3> eunit:test({timeout, 15, {dir, "."}}).
example: main_test (module 'example')...*timed out*
undefined
=======================================================
  Failed: 0.  Skipped: 0.  Passed: 0.
One or more tests were cancelled.
error
Run Code Online (Sandbox Code Playgroud)

如你所见,运行{timeout, 15, example}但不是{timeout, 15, {dir, "."}}.有人有线索吗?

erlang unit-testing

2
推荐指数
1
解决办法
2147
查看次数

在运行时重新安排Quartz

在我的项目中,我们是Quartz用户的新手,编写我们的第一个Quartz任务.我们的任务正在运行,但显然我们想要了解如何管理它们.我们在Spring中配置它们就像这样:

<bean name="enoteExpirationTask"    class="org.springframework.scheduling.quartz.JobDetailBean">
    <property name="jobClass" value="gov.usdoj.afms.enote.job.DailyExpirationJob" />
    <property name="jobDataAsMap">
        <map>
            <entry key="messageService" value-ref="enoteMessageService" />
            <entry key="logicalDeleteAge" value="${expiryProcess.logical.age}" />
            <entry key="physicalDeleteAge" value="${expiryProcess.physical.age}" />
        </map>
    </property>
</bean>
<bean id="cronEnoteExpirationTaskTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
    <property name="jobDetail" ref="enoteExpirationTask" />
    <property name="cronExpression" value="0 0 7 * * ?" />
</bean>
Run Code Online (Sandbox Code Playgroud)

问题1:我可以让Quartz重新读取这个配置,这样如果我在运行时改变它,它会改变它的时间表吗?这将是最简单的解决方案,但我们没有看到任何内容.我希望我们错过了一些东西.

问题2:如果没有,我理解应该有第三方工具来做到这一点,Teracotta就是其中之一.是否有任何开源或免费软件实用程序可以让您非常简单地更改计划?

问题3:如果没有,编写一个小Java实用程序会涉及到什么?写一个是值得的吗?或者Teracotta是否有足够的增值值,你会建议买它?如果是这样,我可以向管理层出售的功能有何不同?

java spring quartz-scheduler

2
推荐指数
1
解决办法
3940
查看次数

如何从.sikuli文件夹中检索代码?

当我打开.sikuli文件夹时,它只有图像.所以我想知道是否有任何方法可以在不使用Sikuli IDE的情况下查看或检索Sikuli代码.

我可以从.sikuli文件夹中找到它吗?

sikuli

2
推荐指数
1
解决办法
580
查看次数

Erlang - 如何返回元素数/元素数

这是我的第一个Erlang项目.基本上,我必须编写一个函数,它将整数列表作为参数,并返回列表中小于1的整数.到目前为止,我所拥有的函数只返回列表中的整数.我不确定在哪里/我是否应该将if语句和计数器仅返回多少个整数小于1.

-export([num/1]).

num([]) -> 0 ;
num(L) -> num(L,0).

num([],Len) -> Len;
num([_|T],Len) ->
    num(T,Len+1).
Run Code Online (Sandbox Code Playgroud)

erlang

2
推荐指数
2
解决办法
6770
查看次数

添加笔划时,文本变为不可见

我有下一个问题(下面的示例代码):
我正在使用CATextLayerNSAttributedString显示风格化的文本.一切正常,直到我为属性添加笔划.当我添加笔划时 - 文本变得不可见并且在显示中我只能看到笔划.拜托,我无法理解会发生什么,为什么我不能同时使用文字和笔画?谢谢.

UIFont* font = [UIFont fontWithName: size:];
UIColor* strokeColor = [UIColor colorWithRed: green: blue: alpha:1.f];
UIColor* foregroundColor = [UIColor colorWithRed: green: blue: alpha:1.f];
CTFontDescriptorRef fontDescriptor = CTFontDescriptorCreateWithNameAndSize(...);
CTFontRef ctFont = CTFontCreateWithFontDescriptor(...);

NSDictionary* attributes = [NSDictionary dictionaryWithObjectsAndKeys:
                            strokeWidth, kCTStrokeWidthAttributeName,
                            [strokeColor CGColor], kCTStrokeColorAttributeName,
                            ctFont, kCTFontAttributeName,
                            [foregroundColor CGColor], kCTForegroundColorAttributeName,
                            nil];

NSAttributedString* attributedText = 
[[NSAttributedString alloc] initWithString:text attributes:attributes];

CATextLayer* infoTextLayer = [[[CATextLayer alloc] init] autorelease];
infoTextLayer.string = attributedText;
...
infoTextLayer.frame = frame;
[self.layer addSublayer:infoTextLayer];
Run Code Online (Sandbox Code Playgroud)

quartz-graphics core-text ios

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

解释为什么这段代码不起作用

我有两个相互引用的类:

class B{
  A obj;
  B(A obj){
    this.obj=obj;
  }
  void display(){
    System.out.println(obj.data);//using data member of A class
  }
}

class A{
  int data=10;

  A(){
   B b =new B(new A());  //  THIS LINE GENERATES AN ERROR
   b.display();
  }
  public static void main(String args[]){
   A a=new A();
  }
}
Run Code Online (Sandbox Code Playgroud)

如果我更改违规行以阅读

   B b =new B(this);
Run Code Online (Sandbox Code Playgroud)

然后它工作.我认为这两条线做同样的事情.为什么一个工作而另一个工作?

此外,第一个版本的编译器错误读取

A.<init><A.java:15>
Run Code Online (Sandbox Code Playgroud)

这是什么意思?

java

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

将二进制值解释为整数

我有一个似乎期望一个整数的函数,但我有一个二进制值.我可以告诉Erlang将二进制解释为整数吗?

我怎么能让这个代码工作(在REPL中)?

Binary = <<"hello world">>.
Integer = binary_to_integer(Binary).  % fix me
Increment = Integer + 1.
Run Code Online (Sandbox Code Playgroud)

erlang

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

在列表中摆脱元组,erlang

我想摆脱列表中的所有元组,例如.

我有这样的东西作为输入

test:stack({push, [{{mul,{plus,{num,2},{num,3}},{num,4}},[]}]}, []). 
%% note:  (returns wrong output because of the multiple tuples brackets)
Run Code Online (Sandbox Code Playgroud)

如果我有这样的事情:

proj:stack({push, [mul,plus,{num,2},{num,3},{num,4}]}, []). 
%% this would return: 
%% [{push,{num,4}},{push,{num,3}},{push,{num,2}},
%%  {push,plus},{push,mul}] 
%% This is near to what I need.
Run Code Online (Sandbox Code Playgroud)

我的代码是这样的:

stack({push, []}, StackList) -> StackList;
stack({push,[H|T]}, StackList) ->   
stack({push, T}, [{push,H} | StackList]). 
Run Code Online (Sandbox Code Playgroud)

我希望实现这样的目标:

{push, {num, 4}}, {push, {num, 3}}, 
{push, {num, 2}}, {add}, {mul}, {pop}, {ret}
Run Code Online (Sandbox Code Playgroud)

我想过使用过滤器来实现这个目标,但也许是其他的东西?

erlang filter

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

404使用Go http客户端时

我想以编程方式对Docker中心服务进行身份验证.当我运行我的代码时,我收到404错误.但是当我将相同的URL传递给Curl时,我得到了200.我不知道如何调试问题.

我使用以下代码:

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io/ioutil"
    "log"
    "net/http"
    "strings"
    "time"
)

type Image struct {
    host, name, tag string
}

func authenticate(image Image) (token string) {
    var url = fmt.Sprintf("https://auth.docker.io/token?service=%s&scope=repository:%s:pull", image.host, image.name)
    var req, e1 = http.NewRequest("get", url, nil)
    if e1 != nil {
        log.Fatal(e1)
    }
    fmt.Println(req)
    var client = &http.Client{
        Timeout:       time.Second * 10,
        CheckRedirect: nil,
        Jar:           nil,
    }
    var res, e2 = client.Do(req)
    if e2 != nil {
        log.Fatal(e2)
    }
    var buf, e3 = ioutil.ReadAll(res.Body)
    if …
Run Code Online (Sandbox Code Playgroud)

go

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

我可以自动在所有模块中使用Logger吗?

在我的大多数模块中,我

require Logger
Run Code Online (Sandbox Code Playgroud)

然后做一些日志记录.在我不这样做的模块中,我经常进行更改,包括添加一些日志记录,然后我必须标记我正在使用记录器.

require在每个模块中使用Logger 的成本是多少?有没有一种干净的方法可以随时require使用Logger而不在每个模块中提及它?

elixir

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

如何在perl中使用hash和getopts

我必须GetOptions在哈希数组中使用.

我的要求是编写一个包含多个选项组合的Perl脚本,例如:

test.pl -a mango -s ripe -d <date value>
Run Code Online (Sandbox Code Playgroud)

要么

 test.pl -a apple -s sour 
Run Code Online (Sandbox Code Playgroud)

其中mango,ripe,apple,sour,等是用户输入,其还用于存储在可变绑定SQL在WHERE一个条款SELECT查询来生成报告.

我这个代码

use vars qw ($opt_a $opt_s $opt_d)
Getopts('a:s:d:')
Run Code Online (Sandbox Code Playgroud)

现在我在编写hash方面遇到了一个问题

my %hash = @ARGV 
Run Code Online (Sandbox Code Playgroud)

上面的哈希定义是正确的吗?有没有更好的方法来使用哈希?

perl

0
推荐指数
1
解决办法
260
查看次数