我想将F#用于我之前使用批处理文件的一些非常基本的任务.我可以将fsx文件与fsi.exe关联起来并通过双击它来运行它.到目前为止,这很棒.
但是,有时我可能想深入研究代码并进行调试.当我在Visual Studio中打开fsx文件时,我无法运行它,但我也无法选择行并使用"发送到交互式".
在我看来,如果你设置一个完整的F#项目,这些命令才有效.这似乎很麻烦(作为批处理文件替换).我想知道哪种方法正确?我想吃蛋糕然后吃!我想要一个简单的文件,我可以快速更改,但我也希望能够根据需要使用Visual Studio进行分析.
更新 我刚刚发现您可以在"View\Other Windows\F#Interactive"中打开交互式控制台,然后您可以使用"发送到交互式"命令.
我仍然缺乏运行代码和设置断点的能力,但..
我想知道在.NET框架(或其他地方)中是否有任何帮助类将字符转换为ConsoleKey枚举.
e.g 'A' should become ConsoleKey.A
Run Code Online (Sandbox Code Playgroud)
在有人问我为什么要这样做之前.我想写一个带有字符串的帮助器(例如'Hello World')并将其转换为一系列ConsoleKeyInfo对象.我需要这个用于一些疯狂的单元测试,我在模拟用户输入.
我只是有点厌倦了自己创建胶水代码所以我想,也许已经有办法将char转换为ConsoleKey枚举?
为了完整起见,到目前为止似乎工作得很好
public static IEnumerable<ConsoleKeyInfo> ToInputSequence(this string text)
{
return text.Select(c =>
{
ConsoleKey consoleKey;
if (Enum.TryParse(c.ToString(CultureInfo.InvariantCulture), true, out consoleKey))
{
return new ConsoleKeyInfo(c, consoleKey, false, false, false);
}
else if (c == ' ')
return new ConsoleKeyInfo(' ', ConsoleKey.Spacebar, false, false, false);
return (ConsoleKeyInfo?) null;
})
.Where(info => info.HasValue)
.Select(info => info.GetValueOrDefault());
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试将我们在代码库中使用的模式提取为更通用的可重用构造.但是,我似乎无法使用通用类型注释来使用mypy.
这是我得到的:
from abc import (
ABC,
abstractmethod
)
import asyncio
import contextlib
from typing import (
Any,
Iterator,
Generic,
TypeVar
)
_TMsg = TypeVar('_TMsg')
class MsgQueueExposer(ABC, Generic[_TMsg]):
@abstractmethod
def subscribe(self, subscriber: 'MsgQueueSubscriber[_TMsg]') -> None:
raise NotImplementedError("Must be implemented by subclasses")
@abstractmethod
def unsubscribe(self, subscriber: 'MsgQueueSubscriber[_TMsg]') -> None:
raise NotImplementedError("Must be implemented by subclasses")
class MsgQueueSubscriber(Generic[_TMsg]):
@contextlib.contextmanager
def subscribe(
self,
msg_queue_exposer: MsgQueueExposer[_TMsg]) -> Iterator[None]:
msg_queue_exposer.subscribe(self)
try:
yield
finally:
msg_queue_exposer.unsubscribe(self)
class DemoMsgQueSubscriber(MsgQueueSubscriber[int]):
pass
class DemoMsgQueueExposer(MsgQueueExposer[int]):
# The following works for mypy: …Run Code Online (Sandbox Code Playgroud) 我知道在StackOverflow上调试Rust问题,我之前也使用了gdb.但是,我遇到了一个问题,似乎gdb无法找到调试符号.
考虑一下这个复杂的程序main.rs?
pub fn main () {
println!("run");
}
Run Code Online (Sandbox Code Playgroud)
我用调试符号编译它
rustc -g main.rs
Run Code Online (Sandbox Code Playgroud)
然后我运行gdb
gdb main
Run Code Online (Sandbox Code Playgroud)
这给出了第一个线索,即加载调试符号的东西不太正确.

现在,当我在gdb和键入
list
Run Code Online (Sandbox Code Playgroud)
它留给我一些C代码,这不是我所期望的.

我究竟做错了什么?我的gdb版本是7.7,我在OS X 10.9.2(13C64).我的rustc版本是rustc 0.11.0-pre(3035d8dfb13077e195eb056568183911c90c1b4b 2014-07-02 21:26:40 +0000)
查看`gdb --configuration``的输出可能也会有所帮助
$ gdb --configuration
This GDB was configured as follows:
configure --host=x86_64-apple-darwin13.1.0 --target=x86_64-apple-darwin13.1.0
--with-auto-load-dir=:${prefix}/share/auto-load
--with-auto-load-safe-path=:${prefix}/share/auto-load
--with-expat
--with-gdb-datadir=/usr/local/share/gdb (relocatable)
--with-jit-reader-dir=/usr/local/lib/gdb (relocatable)
--without-libunwind-ia64
--without-lzma
--with-python=/System/Library/Frameworks/Python.framework/Versions/2.7
--with-separate-debug-dir=/usr/local/lib/debug (relocatable)
--with-zlib
--without-babeltrace
Run Code Online (Sandbox Code Playgroud) 使用Resharper 6可以编写qunit测试并使用集成的resharper测试运行器运行它们,这是一件好事.但是,我想知道是否可以在测试和被测代码中设置断点.问题是,每次打开浏览器时,它都使用不同的随机端口号,这意味着您不能只在浏览器中设置断点并通过点击F5重新运行测试.所以我想知道,甚至可能以某种方式?
我正Streams从远程服务返回(.NET Remoting).但Streams也是一次性用品,我们都知道这些是待处理的.
我Dispose完成消费之后,我可以在客户端打电话.但是,当我Stream从远程对象返回时,我想知道封面下究竟发生了什么.
特别:
byte[]并返回而不是一个Stream?Stream与返回不同的是byte[]什么?最后,还是.NET Remoting必须以某种方式序列化数据?Dispose客户端甚至是否有任何影响?客户端对象和服务器端对象之间是否存在神奇的连接?我认为一旦它在封面后反序列化,在呼叫Dispose()客户端或在那里是没有意义的?我在这里回答Mike Bild,因为我也希望稍微改进一下这个问题
好的,所以回流到服务器的流是(对我来说至少)意想不到的.
为了获取远程对象,必须执行以下操作:
public static class ServiceFactory <T>
{
public static T CreateProxy()
{
Type interfaceType = typeof(T);
string uri = ApplicationServer.ServerURL + interfaceType.FullName;
return (T)Activator.GetObject(interfaceType, uri);
}
}
Run Code Online (Sandbox Code Playgroud)
因此,您明确要在某个URI上使用特定的远程对象.当该远程对象上的方法返回一个继承自MarshallByRefObject的对象时,这意味着它自动与远程端的对象相关联?好吧,使用我自己构建的测试对象,这应该很容易重现.所以这也意味着我应该在客户端调用Dispose并将其代理回服务器端的对象?
考虑这个应该返回给定文件扩展名的函数Path.
pub fn get_extension<'a>(path: &'a Path) -> Option<&'a str> {
let path_str = path.as_str().unwrap();
let ext_pos = regex!(".[a-z0-9]+$").find(path_str);
match ext_pos {
Some((start, _)) => {
return Some(path_str.as_slice().slice_from(start))
},
None => return None
}
}
Run Code Online (Sandbox Code Playgroud)
错误消息如下:
`path_str` does not live long enough
Run Code Online (Sandbox Code Playgroud)

错误信息很清楚,很遗憾我无法自己解决这个问题.我在理论上理解它,但对我来说还有一些模糊的东西.
据我所知,编译器想告诉我,path_str活动时间不够长,因为返回值标记为生命周期'a.
但这就是它停止的地方:
据我所知,对path(输入参数)的引用应该与str对Option(包含在输出参数中)的引用完全一样长
因为我们回来了,Some(path_str.as_slice().slice_from(start))我认为在实践中,这意味着只path_str需要生活path.
我不明白的是到底为什么不path_str不活足够长的时间,我怎么能解决这个问题?是什么让它很快死去?
UPDATE
正如在评论中指出的那样以及IRC中删除superflous as_slice()使代码编译.有谁知道那是为什么?还有人指出存在一种直接获得扩展的方法.但是,我实际上更感兴趣的是学习问题背后的故事.
如果我创建一个文件foo,touch foo然后运行shasum foo它将打印出来
da39a3ee5e6b4b0d3255bfef95601890afd80709.
无论我多久运行一次,shasum foo或者如果我在另一台计算机上运行它,它总是打印,da39a3ee5e6b4b0d3255bfef95601890afd80709因为,是的,它是完全相同内容的SHA1表示.在这种情况下空内容:)
但是,如果我执行以下步骤:
cd /some/where
mkdir demo
git init
touch foo
git add -A
git commit -m "adding foo"
Run Code Online (Sandbox Code Playgroud)
..并记住提交的SHA键(例如959c363ed4cf147725360532454bc258c964c744).
现在,当我删除demo并重复完全相同的步骤时,提交 SHA键仍然不同.这很好,确保身份很重要.
我想知道的是,git确实做了什么确保提交哈希总是唯一的,即使它们使用完全相同的内容完成相同的操作.git只是使用类似的东西uuidgen来为提交对象生成一个唯一的id,或者根据时间戳,你的mac地址,你的wifi信号等组合做一些不同的事情.
我只是注意到一些令人惊讶的事情。考虑以下示例:
import asyncio
async def wait_n(n):
asyncio.sleep(n)
async def main(fn):
print("meh")
await fn(1)
print("foo")
loop = asyncio.get_event_loop()
loop.run_until_complete(main(wait_n))
Run Code Online (Sandbox Code Playgroud)
运行此命令时,我们正确地收到以下警告:
awaitable_lambda.py:5: RuntimeWarning: coroutine 'sleep' was never awaited
Run Code Online (Sandbox Code Playgroud)
asyncio.sleep(n)
这是因为在wait_n我们中,我们asyncio.sleep(n)没有调用await。
但现在考虑第二个示例:
import asyncio
async def main(fn):
print("meh")
await fn(1)
print("foo")
loop = asyncio.get_event_loop()
loop.run_until_complete(main(lambda n: asyncio.sleep(n)))
Run Code Online (Sandbox Code Playgroud)
这次我们使用的是lambda,即使没有,代码也可以正常工作await。
我明白,我们不能用await一个Python里面lambda表情让这似乎是一个功能,可以提高工效,但它导致了我一些问题:
await在任何协程功能之前?这是我想要解决的问题.我有谷歌Chrome的崩溃转储.
我打开windbg说文件 - >符号文件路径:"SRV*c:\ code\symbols*http://msdl.microsoft.com/download/symbols; SRV*c:\ code\symbols*https:// chromium -browser-symsrv.commondatastorage.googleapis.com"我想从头到右寻找调试符号,最后应该从google中获取它们.我从http://www.chromium.org/developers/how-tos/debugging复制了它.
我将崩溃转储拖放到windbg中
然后...
Microsoft (R) Windows Debugger Version 6.2.8400.0 AMD64
Copyright (c) Microsoft Corporation. All rights reserved.
Loading Dump File [C:\Users\cburgdorf\Desktop\Chrome-last.dmp]
User Mini Dump File: Only registers, stack and portions of memory are available
Symbol search path is: SRV*c:\code\symbols*http://msdl.microsoft.com/download/symbols;SRV*c:\code\symbols*https://chromium-browser-symsrv.commondatastorage.googleapis.com
Executable search path is:
Windows 7 Version 7601 (Service Pack 1) MP (8 procs) Free x86 compatible
Product: WinNt, suite: SingleUserTS
Machine Name:
Debug session time: Wed May 16 16:25:24.000 2012 …Run Code Online (Sandbox Code Playgroud)