我想增加Jenkins的可用堆空间.但由于它作为服务安装,我不知道该怎么做.
我们目前正在使用DoxyGen来记录用C/C++,PHP和Java编写的代码.要拥有一致的环境,最好将它用于C#文档.
但是我们想知道:
我想将一个String写入一个Stream(本例中是一个MemoryStream)并逐个读取这些字节.
stringAsStream = new MemoryStream();
UnicodeEncoding uniEncoding = new UnicodeEncoding();
String message = "Message";
stringAsStream.Write(uniEncoding.GetBytes(message), 0, message.Length);
Console.WriteLine("This:\t\t" + (char)uniEncoding.GetBytes(message)[0]);
Console.WriteLine("Differs from:\t" + (char)stringAsStream.ReadByte());
Run Code Online (Sandbox Code Playgroud)
我得到的(不受欢迎的)结果是:
This: M
Differs from: ?
Run Code Online (Sandbox Code Playgroud)
它看起来像它没有被正确读取,为"信息"的第一个字符是"M",从UnicodeEncoding实例获取字节时,但不读他们从流回来时,其工作原理.
我究竟做错了什么?
更大的图片:我有一个算法可以处理Stream的字节,我希望尽可能通用并使用任何Stream.我想将ASCII-String转换为MemoryStream,或者使用另一种方法将String作为Stream处理.有问题的算法将处理Stream的字节.
如何读取用户特定的环境变量?我知道如何获得系统范围的,比如
Environment.GetEnvironmentVariable("SOMETHING");
Run Code Online (Sandbox Code Playgroud)
提前致谢!
我有一个使用XML命名空间的文档,我希望将其增加/group/house/dogs一个:(调用该文件houses.xml)
<?xml version="1.0"?>
<group xmlns="http://dogs.house.local">
<house>
<id>2821</id>
<dogs>2</dogs>
</house>
</group>
Run Code Online (Sandbox Code Playgroud)
我使用下面代码的当前结果是:(调用创建的文件houses2.xml)
<ns0:group xmlns:ns0="http://dogs.house.local">
<ns0:house>
<ns0:id>2821</ns0:id>
<ns0:dogs>3</ns0:dogs>
</ns0:house>
</ns0:group>
Run Code Online (Sandbox Code Playgroud)
我想修复两件事(如果有可能使用ElementTree.如果不是,我会很高兴建议我应该使用什么):
<?xml version="1.0"?>条线.总而言之,我不想把文件弄得比我绝对要多.
产生上述结果的我当前的代码(除了上面提到的缺陷之外起作用)如下.
我创建了一个实用程序函数,它使用ElementTree加载XML文件并返回elementTree和命名空间(因为我不想对命名空间进行硬编码,并且我愿意承担它所暗示的风险):
def elementTreeRootAndNamespace(xml_file):
from xml.etree import ElementTree
import re
element_tree = ElementTree.parse(xml_file)
# Search for a namespace on the root tag
namespace_search = re.search('^({\S+})', element_tree.getroot().tag)
# Keep the namespace empty if none exists, if a namespace exists set
# namespace to {namespacename}
namespace = ''
if namespace_search: …Run Code Online (Sandbox Code Playgroud) 我在使用Bash时遇到这种行为(在Cygwin下):
$ printf '\u00d5'
\u00d5
$ env printf '\u00d5' # This results in the behavior I want
Õ
Run Code Online (Sandbox Code Playgroud)
如果我在终端中使用UTF-8或ISO-8859-1编码并不重要.
我的问题是:env究竟做了什么?为什么在这种特定情况下我需要它?
我收到一个Stream,需要将IEnumerable传递给另一个方法.
public static void streamPairSwitchCipher(Stream someStream)
{
...
someStreamAsIEnumerable = ...
IEnumerable returned = anotherMethodWhichWantsAnIEnumerable(someStreamAsIEnumerable);
...
}
Run Code Online (Sandbox Code Playgroud)
一种方法是读取整个Stream,将其转换为字节数组并将其传入,因为Array实现了IEnumerable.但是,如果我能以这样的方式传入它,以至于在传入之前我不必读取整个Stream,那就更好了.
public static IEnumerable<T> anotherMethodWhichWantsAnIEnumerable<T>(IEnumerable<T> p) {
... // Something uninteresting
}
Run Code Online (Sandbox Code Playgroud) 如果我有一个在多个参数之间共享的有效选项字符串列表,则该列表将写入帮助字符串中的多个位置.让它更难阅读:
def main():
elements = ['a', 'b', 'c', 'd', 'e', 'f']
parser = argparse.ArgumentParser()
parser.add_argument(
'-i',
nargs='*',
choices=elements,
default=elements,
help='Space separated list of case sensitive element names.')
parser.add_argument(
'-e',
nargs='*',
choices=elements,
default=[],
help='Space separated list of case sensitive element names to '
'exclude from processing')
parser.parse_args()
Run Code Online (Sandbox Code Playgroud)
使用命令行参数运行上述函数时,--help它显示:
usage: arguments.py [-h] [-i [{a,b,c,d,e,f} [{a,b,c,d,e,f} ...]]]
[-e [{a,b,c,d,e,f} [{a,b,c,d,e,f} ...]]]
optional arguments:
-h, --help show this help message and exit
-i [{a,b,c,d,e,f} [{a,b,c,d,e,f} ...]]
Space separated list of case …Run Code Online (Sandbox Code Playgroud) 我们使用.NET 2.0框架和C#3.0(我认为它是C#的最后一个版本,它可以在2.0版本的框架上运行,如果我错了,请纠正我).
是否有内置于C#中的内容可以使这种类型的参数验证更方便?
public ConnectionSettings(string url, string username, string password,
bool checkPermissions)
{
if (username == null) {
throw new ArgumentNullException("username");
}
if (password == null) {
throw new ArgumentNullException("password");
}
if (String.IsNullOrEmpty(url)) {
throw new ArgumentException("Must not be null or empty, it was " +
(url == null ? url : "empty"), "url");
}
this.url = url;
this.username = username;
this.password = password;
this.checkPermissions = checkPermissions;
}
Run Code Online (Sandbox Code Playgroud)
这种参数验证成为一种常见的模式,并导致许多"近似样板"代码在我们的公共方法中跋涉.
如果没有内置的东西.我们可以使用哪些优秀的免费图书馆?
我有一个像这个例子中的字典列表:
listofdict = [{'name': 'Foo', 'two': 'Baz', 'one': 'Bar'}, {'name': 'FooFoo', 'two': 'BazBaz', 'one': 'BarBar'}]
Run Code Online (Sandbox Code Playgroud)
我知道每个字典(以及其他键)中都存在'name',并且它是唯一的,并且不会出现在列表中的任何其他字典中.
我想通过使用键'name'来访问'two'和'one'的值.我想字典词典会最方便吗?喜欢:
{'Foo': {'two': 'Baz', 'one': 'Bar'}, 'FooFoo': {'two': 'BazBaz', 'one': 'BarBar'}}
Run Code Online (Sandbox Code Playgroud)
有了这个结构,我可以轻松地遍历名称,并通过使用名称作为键来获取其他数据.您对数据结构有任何其他建议吗?
我的主要问题是:进行这种转变的最好和最恐怖的方法是什么?
c# ×5
python ×3
argparse ×1
bash ×1
dictionary ×1
heap ×1
jenkins ×1
parameters ×1
stream ×1
xml ×1