小编Jul*_*ano的帖子

为什么随机在Ruby中这样工作?

我试图巧妙地确定性地选择随机的东西,并发现:

irb(main):011:0> Random.new(Random.new(1).rand + 1).rand == Random.new(1).rand
=> true
irb(main):012:0> Random.new(Random.new(5).rand + 1).rand == Random.new(5).rand
=> false
irb(main):013:0> Random.new(Random.new(5).rand + 5).rand == Random.new(5).rand
=> true
Run Code Online (Sandbox Code Playgroud)

有一秒钟,我想"哇,也许这是随机数生成器的属性",但Python和C#无法重现这一点.

ruby random

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

带有动态参数的ChannelFactory错误

此问题与动态语言运行时中的Bug以及IIS 7.5相关

ChannelFactory 如果我提供正确类型的动态对象,则挂起.

dynamic src = "MSFT";

var binding = new BasicHttpBinding();
var endpoint = new EndpointAddress("http://www.restfulwebservices.net/wcf/StockQuoteService.svc");
var channel = new ChannelFactory<IStockQuoteService>(binding, endpoint).CreateChannel();

// this will print just fine
Console.WriteLine(channel.GetStockQuote(src as string));

// this will print just fine
Console.WriteLine(new StockQuoteServiceClient().GetStockQuote(src));

// this will never print and the application will hang with no exceptions
Console.WriteLine(channel.GetStockQuote(src));
Run Code Online (Sandbox Code Playgroud)
  • 上面的服务是公共的,不是我的,如果您只是将服务引用添加到代码中提供的端点,您可以自己测试此代码;
  • StockQuoteServiceClient 是由Add Service Reference菜单项创建的,并且使动态对象很好;
  • 当我在Debug上使用F5启动应用程序时,这种神奇不会发生,所有行打印并且程序正确退出;
  • 如果我运行它然后在执行期间附加调试器,我可以看到它挂在调用上channel.GetStockQuote(src);
  • 如果我离开它,程序会占用我所有的记忆;
  • 它只会在我使用自己ChannelFactory的动态对象时挂起,如注释中所述.

ChannelFactory当添加服务引用创建的那个运行得很好时,为什么我将动态对象作为参数挂起?

.net wcf wcf-client channelfactory c#-4.0

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

svcutil/sc不生成Task异步方法

当我svcutil没有参数运行时,我默认获得两个方法,一个同步和一个任务异步,如下所示:

[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IConsultaDisponibilidade/RetornaDados", ReplyAction="http://tempuri.org/IConsultaDisponibilidade/RetornaDadosResponse")]
string RetornaDados(FastServices.WsConsultaDisponibilidade.Componentes.PedidoEntity dadosPedido);

[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IConsultaDisponibilidade/RetornaDados", ReplyAction="http://tempuri.org/IConsultaDisponibilidade/RetornaDadosResponse")]
System.Threading.Tasks.Task<string> RetornaDadosAsync(FastServices.WsConsultaDisponibilidade.Componentes.PedidoEntity dadosPedido);
Run Code Online (Sandbox Code Playgroud)

我正在用客户端和渠道做自己的事情,而且我不想svcutil生成额外的代码,所以我运行它svcutil /sc ....

问题是,当我打开它时,我只创建了同步方法.

[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IConsultaDisponibilidade/RetornaDados", ReplyAction="http://tempuri.org/IConsultaDisponibilidade/RetornaDadosResponse")]
string RetornaDados(FastServices.WsConsultaDisponibilidade.Componentes.PedidoEntity dadosPedido);
Run Code Online (Sandbox Code Playgroud)

我还没有找到一种方法来绕过这个选项.

还有一个吗?

/a,但会产生开始/结束异步方法是这样的:

[System.ServiceModel.OperationContractAttribute(AsyncPattern=true, Action="http://tempuri.org/IConsultaDisponibilidade/RetornaDados", ReplyAction="http://tempuri.org/IConsultaDisponibilidade/RetornaDadosResponse")]
System.IAsyncResult BeginRetornaDados(FastServices.WsConsultaDisponibilidade.Componentes.PedidoEntity dadosPedido, System.AsyncCallback callback, object asyncState);

string EndRetornaDados(System.IAsyncResult result);
Run Code Online (Sandbox Code Playgroud)

我想要使​​用Task async方法.

有关如何保持合同生成但自动丢弃客户端和渠道样板的任何建议?

c# wcf svcutil.exe

7
推荐指数
0
解决办法
428
查看次数

Erlang Hot Code加载不广泛使用?

我刚刚在LinuxConf.au上看到了关于Erlang的2012年视频.

视频中有一部分是伯纳德说除了爱立信之外没有大的Erlang项目使用热码加载,因为很难保证事情能够奏效.大概是29分钟.

这仍然是真的吗?是否有工具可以帮助测试热代码加载或者让它变得更容易?

erlang

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

/ 3之间可以不递归吗?

我看过Prolog Prologue的定义between/3:

between(Lower, Upper, Lower) :-
   Lower =< Upper.
between(Lower1, Upper, X) :-
   Lower1 < Upper,
   Lower2 is Lower1 + 1,
   between(Lower2, Upper, X).
Run Code Online (Sandbox Code Playgroud)

我不明白为什么它需要递归.逻辑定义between可以是:

between(Lower, Upper, Something):-
   Lower =< Upper,
   Lower =< Something,
   Something =< Upper.
Run Code Online (Sandbox Code Playgroud)

我试过它gprolog并且它可以工作,但仅用于简单的查询:

| ?- between(0,5,1).

yes
Run Code Online (Sandbox Code Playgroud)

对于带变量的查询,我得到:

| ?- between(0,5,X).
uncaught exception: error(instantiation_error, (=<)/2)
Run Code Online (Sandbox Code Playgroud)

我真的不明白为什么.

我有点像Prolog需要某种参考数字来统一变量,但为什么会出现神秘错误(=<)/2

prolog instantiation-error

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

git 快进合并是否会更改合并提交的 SHA?

换句话说,快进合并是否保证产生与要合并的源分支的 HEAD 相同的 GIT SHA?

我在终端中测试了此行为,它适用于我的测试场景:

$ git rev-parse some-branch
0fc9fba2fb1c8a13556da4a333351bc12909c497

$ git merge some-branch --ff-only
Updating 90c6244..0fc9fba
Fast-forward
 b | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 b

$ git rev-parse HEAD  
0fc9fba2fb1c8a13556da4a333351bc12909c497
Run Code Online (Sandbox Code Playgroud)

我可以在我的工具中利用这个条件,例如,我使用源 GIT SHA 标记构建工件。如果快进保证 SHA 不会发生变化,我就不必进行一些可能成本高昂的重建检查。问题是我必须确定这是真的。

git github git-merge gitlab

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