我很想尝试f#3.0,但我只有visual studio 2010专业版.我知道F#3.0安装了开箱即用的visual studio 2012,但我还没有能够升级到vs2012的位置.
最近由Don Syme发布的msdn文章暗示它可以与visual studio 2010一起使用,但似乎没有任何资源或解释如何实现.
引用文章:
...要在Visual Studio 2008或Visual Studio 2010中使用F#3.0,包括使用免费工具,请访问fsharp.net
但当然fsharp.net只是进入推动visual studio 2012 的msdn页面.
如果你看看帖子中的评论,我显然也不是唯一一个一直在问这个问题的人.
有没有人对此有任何好运或者我是否需要使用visual studio 2012来使用f#3.0?
我遇到了一个管道脚本的奇怪问题.我有一个多行sh blob喜欢
sh """
git tag -fa \\"${version}\\" -m \\"Release of ${version}\\"
"""
Run Code Online (Sandbox Code Playgroud)
而这在某种程度上运行:
+ git tag -fa '"1.0-16-959069f'
error: Terminal is dumb, but EDITOR unset
Please supply the message using either -m or -F option.
Run Code Online (Sandbox Code Playgroud)
所以它放弃了-m和消息.我试过单逃,双逃,似乎没什么用.
我正在阅读Machine Learning In Action并正在阅读决策树章节.我知道决策树的构建使得分割数据集为您提供了构建分支和叶子的方法.这为您提供了更多可能在树顶部的信息,并限制了您需要经历的决策数量.
该书显示了确定数据集的shanon熵的函数:
def calcShannonEnt(dataSet):
numEntries = len(dataSet)
labelCounts = {}
for featVec in dataSet: #the the number of unique elements and their occurance
currentLabel = featVec[-1]
if currentLabel not in labelCounts.keys(): labelCounts[currentLabel] = 0
labelCounts[currentLabel] += 1
shannonEnt = 0.0
for key in labelCounts:
prob = float(labelCounts[key])/numEntries
shannonEnt -= prob * log(prob,2) #log base 2
return shannonEnt
Run Code Online (Sandbox Code Playgroud)
输入数据集是一个数组数组,其中每个数组代表一个潜在的可分类特征:
dataSet = [[1, 1, 'yes'],
[1, 1, 'yes'],
[1, 0, 'no'],
[0, 1, 'no'],
[0, 1, 'no']] …Run Code Online (Sandbox Code Playgroud) 我正在使用 java 8 的可完成的 future,我希望能够接受 future 抛出的异常并将其转换为不同的异常。
一旦发生异常,我尝试过的所有复合材料似乎都会短路。
例如,使用 scala future,我可以做这样的事情:
scala.concurrent.Future<Object> translatedException = ask.recover(new Recover<Object>() {
@Override public Object recover(final Throwable failure) throws Throwable {
if (failure instanceof AskTimeoutException) {
throw new ApiException(failure);
}
throw failure;
}
}, actorSystem.dispatcher());
Run Code Online (Sandbox Code Playgroud)
我希望能够在未来的 java 复合块中模仿这一点。这可能吗?
我是scala mongo驱动程序的新手,正在尝试了解如何从Document映射类?该文档似乎都没有显示如何完成此操作。在.net驱动程序中,它就像传递通用类并自动映射字段一样容易。Scala中没有类似的东西吗?
我正在尝试使用无形来创建一个可以带有副产品的poly2函数:
case class IndexedItem(
item1: Item1,
item2: Item2,
item3: Item3
)
case class Item1(name: Int)
case class Item2()
case class Item3()
object IndexUpdater {
type Indexable = Item1 :+: Item2 :+: Item3 :+: CNil
object updateCopy extends Poly2 {
implicit def caseItem1 = at[IndexedItem, Item1] { (a, b) => a.copy(item1 = b) }
implicit def caseItem2 = at[IndexedItem, Item2] { (a, b) => a.copy(item2 = b) }
implicit def caseItem3 = at[IndexedItem, Item3] { (a, b) => a.copy(item3 = b) …Run Code Online (Sandbox Code Playgroud) 是否已经有办法做一些像a chooseTill或a 这样的事情foldTill,直到收到None选项才会处理?实际上,任何具有"until"选项的高阶函数.当然,对于像地图这样的东西没有任何意义,但我发现我经常需要这种东西而且我想确保我没有重新发明轮子.
一般来说,写这样的东西很容易,但我很好奇是否已经有办法做到这一点,或者是否存在于某个已知的库中?
let chooseTill predicate (sequence:seq<'a>) =
seq {
let finished = ref false
for elem in sequence do
if not !finished then
match predicate elem with
| Some(x) -> yield x
| None -> finished := true
}
let foldTill predicate seed list =
let rec foldTill' acc = function
| [] -> acc
| (h::t) -> match predicate acc h with
| Some(x) -> foldTill' x t
| None -> acc
foldTill' seed …Run Code Online (Sandbox Code Playgroud) 我是python的新手,并且好奇如果python有类似的东西npm install会pip安装我所拥有的脚本所需的包.我已经查看了setup.py自述文件,看起来它主要是为了创建一个tarball发送到pip,这不是我想要的.
我希望能够查看源代码,然后运行它.当我要求我的同事使用脚本时,他们会遇到导入失败,并且必须手动pip安装那些经验不佳的东西.
我的setup.py文件是
#!/usr/bin/env python
from distutils.core import setup
setup(name='Add-Webhook',
version='1.0',
description='Adds webhooks to git repos',
author='devshorts',
packages=['requests'],
)
Run Code Online (Sandbox Code Playgroud)
当我跑它时
$ python setup.py install
running install
running build
running build_py
error: package directory 'requests' does not exist
Run Code Online (Sandbox Code Playgroud)
我有一个小脚本,位于使用该requests软件包的setup.py旁边,我希望它安装在'install'上
$ ls
total 40
-rw-r--r-- 1 akropp JOMAX\Domain Users 1039 Feb 24 09:51 README.md
-rwxr-xr-x 1 akropp JOMAX\Domain Users 4489 Feb 27 17:01 add-webhook.py
-rw-r--r-- 1 akropp JOMAX\Domain Users 391 Feb 23 14:24 github.iml
-rw-r--r-- …Run Code Online (Sandbox Code Playgroud) 我一直在尝试让 json 流在 jersey 2 中工作。在我的一生中,在流完成之前没有任何流。
我尝试过这个示例,试图模拟缓慢的数据生成器。
@Path("/foo")
@GET
public void getAsyncStream(@Suspended AsyncResponse response) {
StreamingOutput streamingOutput = output -> {
JsonGenerator jg = new ObjectMapper().getFactory().createGenerator(output, JsonEncoding.UTF8);
jg.writeStartArray();
for (int i = 0; i < 100; i++) {
jg.writeObject(i);
try {
Thread.sleep(100);
}
catch (InterruptedException e) {
logger.error(e, "Error");
}
}
jg.writeEndArray();
jg.flush();
jg.close();
};
response.resume(Response.ok(streamingOutput).build());
}
Run Code Online (Sandbox Code Playgroud)
然而 jersey 只是坐在那里,直到 json 生成器完成返回结果为止。我正在观察查尔斯代理中的结果。
我需要启用某些功能吗?不知道为什么这不会流出
编辑:
这实际上可能有效,只是不是我预期的那样。我不认为流正在实时写入内容,这正是我想要的,它更多的是不必缓冲响应并立即将它们写出给客户端。如果我运行一百万个循环并且没有线程睡眠,那么数据确实会以块的形式写出,而无需将其缓冲在内存中。
我似乎无法弄清楚为什么以下代码死锁:
"Locks around blocking futures" should "be re-entrant" in {
val lock = new Object()
def processInFuture = {
lock.synchronized {
// simulate async call made blocking
Await.result(Future {
blocking {
logger.info("Sleeping")
Thread.sleep(100)
logger.info("Waking")
}
}, Duration.Inf)
}
}
// fire off 10 async events and wait on each one
(0 until 10).
map(_ => Future { processInFuture }).
foreach(future => Await.result(future, Duration.Inf))
}
Run Code Online (Sandbox Code Playgroud)
我不明白为什么在关键部分中使异步同步会导致整个fork-join池出现问题.
如果我使未来在fork连接池的单独池上执行,那么它可以工作.我不明白为什么fork join pool线程不阻塞其他线程然后先完成?是因为游泳池被某种方式阻挡了吗?
我意识到如果它的异步,它总是最好使所有异步,但有些情况不允许(例如带有番石榴缓存的缓存)
- 编辑
为了说明@Dima的答案,这是有效的
"Locks around blocking futures" should "be re-entrant" in …Run Code Online (Sandbox Code Playgroud)