小编use*_*301的帖子

Scala.React发生了什么?

我读了Odersky撰写的文章"用Scala.React弃用Observer模式"

github看起来被遗弃了:

https://github.com/ingoem/scala-react

此外,最近的Reactive Programming Coursera类使用了JavaRx Observable库(当然还有Scala支持).

这背后有故事吗?我可以假设scala.react只是没有做得很远.基于Observable的JavaRx库是否可取?或者我们可以期待Typesafe中类似或更好的东西吗?

scala reactive-programming observer-pattern

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

python 3 + statsmodels?

如果我这样做,sudo pip3 install statsmodels我会收到错误.我粘贴了下面控制台输出的结尾.我看到一个numpy 1.7警告,但如果我这样做pip3 freeze | grep numpy,我看到我正在使用numpy==1.8.1.

这是输出.有任何想法吗?

/usr/lib/python3/dist-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]

 #warning "Using deprecated NumPy API, disable it by " \

  ^

statsmodels/tsa/kalmanf/kalman_loglike.c: In function ‘__Pyx_TraceSetupAndCall’:

statsmodels/tsa/kalmanf/kalman_loglike.c:7021:17: error: ‘PyFrameObject’ has no member named ‘f_tstate’

         (*frame)->f_tstate = PyThreadState_GET();

                 ^

In file included from /usr/lib/python3/dist-packages/numpy/core/include/numpy/ndarrayobject.h:26:0,

                 from /usr/lib/python3/dist-packages/numpy/core/include/numpy/arrayobject.h:4,

                 from statsmodels/tsa/kalmanf/kalman_loglike.c:257:

statsmodels/tsa/kalmanf/kalman_loglike.c: At top level:

/usr/lib/python3/dist-packages/numpy/core/include/numpy/__multiarray_api.h:1629:1: warning: ‘_import_array’ defined but not used [-Wunused-function]

 _import_array(void) …
Run Code Online (Sandbox Code Playgroud)

python-3.x statsmodels

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

Gradle + Jenkins + Artifactory Maven Repo?

我有一个使用Jenkins构建的Java项目,使用Jenkins CI服务器,我想使用与Maven兼容的工件发布到Artifactory服务器.该项目正在使用Git.如果可能的话,我还想使用Jenkins的发布管理功能.

这非常令人困惑.至少有五个插件,具有很多重叠的冗余功能.一些插件似乎取代了其他插件.有些插件似乎需要其他插件.

仅供参考,五个相关的插件似乎是:

1)Jenkins Artifactory插件 https://wiki.jenkins-ci.org/display/JENKINS/Artifactory+Plugin

2)Gradle"maven"插件 http://www.gradle.org/docs/current/userguide/maven_plugin.html

3)Gradle"maven-publish"插件 http://www.gradle.org/docs/current/userguide/publishing_maven.html

4)Gradle"artifactory"插件 https://www.jfrog.com/confluence/display/RTF/Gradle+Artifactory+Plugin

5)Gradle"artifactory-publish"插件 http://www.jfrog.com/confluence/display/RTF/Gradle+1.6+Publishing+Artifactory+Plugin

设置它的最佳方法是什么?

如果我使用Jenkins Artifactory插件没有提到任何其他插件,我收到一个错误:

No publish configurations specified for project ':' and the default 'archives' configuration does not exist.
Cannot publish pom for project ':my-great-app' since it does not contain the Maven plugin install task and task ':my-great-app:artifactoryPublish' does not specify a custom pom path.
Run Code Online (Sandbox Code Playgroud)

我假设我需要使用mavenmaven-publish在build.gradle中?

maven-publish被标记为maven插件的孵化后继者.它有多好?它有多稳定?

如何使用Gradle Artifactory插件与标准maven发布插件相比使用Jenkins插件?

artifactory gradle jenkins

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

无法设置跟踪信息; 起点'origin/master'不是分支

有人可以解释为什么这不起作用?

?  workspace git:(REL-BRANCH-1.0.1d) ? git branch -a
  REL-BRANCH-1.0.1c
* REL-BRANCH-1.0.1d
  remotes/origin/REL-BRANCH-1.0.1c
  remotes/origin/master
?  workspace git:(REL-BRANCH-1.0.1d) ? git checkout -t origin/master 
fatal: Cannot setup tracking information; starting point 'origin/master' is not a branch.
?  workspace git:(REL-BRANCH-1.0.1d) ? git checkout -t remotes/origin/master
fatal: Cannot setup tracking information; starting point 'remotes/origin/master' is not a branch.
Run Code Online (Sandbox Code Playgroud)

git

12
推荐指数
3
解决办法
6402
查看次数

Scala选项?为什么有些人不继承AnyVal,为什么它不是值类型?

为什么Scala有些不从AnyVal继承,以便它使用值类型功能并节省装箱费用?

就像是:

sealed trait TestOption[+A] extends Any {
  def isEmpty: Boolean
  def get: A
}

final case class TestSome[+A](val x: A) extends AnyVal with TestOption[A] {
  def isEmpty = false
  def get = x
} 

case object TestNone extends TestOption[Nothing] {
  def isEmpty = true
  def get = throw new NoSuchElementException("None.get")
}
Run Code Online (Sandbox Code Playgroud)

scala

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

flatMap或在Python 3中绑定?

Python提供了列表推导,提供了地图/过滤器类型功能.我可以用这个做flatMap aka绑定操作吗?我见过使用itertools或其他附加库的解决方案.我可以用核心Python做到这一点吗?

# this
[[x,10*x] for x in [1,2,3]]
# will result in unflattened [[1, 10], [2, 20], [3, 30]]
Run Code Online (Sandbox Code Playgroud)

python functional-programming

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

xmllint:非root xml元素上的xmlns?

xmllint --xpath "//project" test.xml
Run Code Online (Sandbox Code Playgroud)

失败了

<?xml version="1.0" encoding="UTF-8"?>

<projects>
  <project xmlns="http://maven.apache.org/POM/4.0.0">
    <modelVersion>4.0.0</modelVersion>
  </project>
</projects>
Run Code Online (Sandbox Code Playgroud)

但如果我删除xmlns属性,请成功:

<?xml version="1.0" encoding="UTF-8"?>

<projects>
  <project>
    <modelVersion>4.0.0</modelVersion>
  </project>
</projects>
Run Code Online (Sandbox Code Playgroud)

这有什么问题吗?xmlns在非顶级标签上是否合法?

我正在使用Java Maven:

mvn help:effective-pom
Run Code Online (Sandbox Code Playgroud)

并在非顶部元素上生成带有xmlns的xml,如图所示.

xml xpath maven xmllint

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

为什么Scala for循环比逻辑上相同的循环慢?

我喜欢Scala的强大功能以及它们与任何monadic类型与map和flatMap集成的方式.但是,我还想做一个简单的整数循环而不会有很大的速度惩罚.为什么Scala没有以下两个逻辑上相同的循环以相似的运行时性能运行甚至编译成类似的字节代码?

// This is slow...
for (i <- 0 until n) println(s"for loop with $i")

// This runs much faster. It runs roughly at the same speed as Java code doing an identical while or for loop.
var i = 0;
while (i < n) {
  println(s"while loop with $i")
  i += 1
}
Run Code Online (Sandbox Code Playgroud)

scala

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

Akka Ask 定时重试

这是我编写的一个简单函数,用于通过定时重试执行 Akka“询问”。有一个明显的竞争条件,我不知道如何解决。

def askWithRetry(actor: ActorRef, message: Any, timeout: Timeout): Future[Any] =
  (actor ? message)(timeout) recoverWith { case e: AskTimeoutException =>
      // do a retry. currently there is no retry limit for simplicity.
      askWithRetry(actor, message, timeout)
    }
Run Code Online (Sandbox Code Playgroud)

通常,这是有效的。“询问”或?为每次调用创建一个临时中间参与者。如果目标发送响应消息,临时“询问参与者”将结果放入 Future 作为成功完成。如果目标没有及时响应,future 会以超时异常结束,recoverWith 进程会重试。

但是,存在竞争条件。如果目标将响应消息发送给临时的“询问参与者”,但在响应消息之前处理了超时,则响应消息将丢失。重试过程使用新的临时参与者重新发送新请求。由于响应消息被发送到以前的临时“询问参与者”,现在已经不存在了,它不会被处理并且会丢失。

我怎样才能解决这个问题?

我可以使用内置的重试逻辑编写一个自定义版本的 Ask 模式来修复这个竞争条件……如果有更标准的选项,我讨厌使用不必要的自定义代码。

更新:这是我最终使用的自定义版本:

object AskWithRetry {
  def askWithRetry(context: ActorContext, actor: ActorRef, message: Any, retryInterval: Duration, maxRetries: Option[Int]): Future[Any] = {
    val p = Promise[Any]

    val intermediate = context.actorOf(props(p, actor, message, retryInterval, maxRetries))

    p.future …
Run Code Online (Sandbox Code Playgroud)

scala akka

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

Grizzly Embedded Server + Jersey服务+ Servlet过滤器

以下代码运行我的REST服务,但我的servlet过滤器永远不会被调用.有任何想法吗?

WebappContext webappContext = new WebappContext("grizzly web context", "");

FilterRegistration testFilterReg = webappContext.addFilter("TestFilter", TestFilter.class);
testFilterReg.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), "/*");

ResourceConfig rc = new ResourceConfig().register(MyResource.class);
HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer(URI.create("http://localhost:8080/myapp/"), rc);
webappContext.deploy(httpServer);
Run Code Online (Sandbox Code Playgroud)

java grizzly servlet-filters jersey-2.0

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

关于列表类型的新手Haskell lyah教程

这是着名的Learn You a Haskell一书中的第3章.我的问题和困惑在这段代码中解释:

-- simple lyah tutorial function. by itself this makes sense.
head' :: [a] -> a
head' [] = error "'head' on empty list"
head' (x:_) = x

-- It is my understanding that [3] is the same as 3:[]. Why do they don't work the same?
head' [3]   -- works. returns 3.
head' 3:[] -- doesn't work. I can not understand error.
head' (3:[]) -- works. returns 3.

-- Now in GHCi, I can look at …
Run Code Online (Sandbox Code Playgroud)

haskell

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

C#Max还是默认?

如何在C#中为空集合使用默认值IEnumerable.Max?

这是我想在Java 8中做的事情:

public static void doTest(List<String> l) {
    System.out.println("max string is: " + l.stream().max((a, b) -> a.compareToIgnoreCase(b)).orElse("default"));
    System.out.println("max length is: " + l.stream().mapToInt(s -> s.length()).max().orElse(-1));
}

public static void main(String[] args) throws Exception {
    System.out.println("Test with non-empty list");
    doTest(Arrays.asList("alpha", "beta", "charlie", "gamma"));

    System.out.println("");

    System.out.println("Test with empty list");
    doTest(Arrays.asList());
}
Run Code Online (Sandbox Code Playgroud)

这是我到目前为止在C#中所拥有的:

static void DoTest(List<String> l) {
    Console.WriteLine("max string is: " + l.Max());
    Console.WriteLine("max length is: " + l.Select(s => s.Length).Max());
}

static void Main() {
    Console.WriteLine("Test with non-empty list");
    DoTest(new …
Run Code Online (Sandbox Code Playgroud)

c# collections functional-programming

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