小编ope*_*sas的帖子

scala:将错误添加到错误列表的惯用和功能方法

我有以下验证方法:

def validate(wine: Wine): List[Error] = {

  var errors = List[Error]()

  if (Validate.isEmptyWord(wine.name)) {
    errors ::= ValidationError("name", "Name not specified")
  } else {
    if (isDuplicate(wine, "name")) {
      errors ::= ValidationError("name", "There already exists a wine with the name '%s'".format(wine.name))
    }
  }

  if (Validate.isEmptyWord(wine.grapes)) {
    errors ::= ValidationError("grapes", "Grapes not specified")
  }

  if (Validate.isEmptyWord(wine.country)) {
    errors ::= ValidationError("country", "Country not specified")
  }

  // more stuff like this and finnally
  errors.reverse
}
Run Code Online (Sandbox Code Playgroud)

你明白了

你将如何修改它以避免var List [Error]并使其更具功能性?

functional-programming scala

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

Sql 2008,解析带有波浪号字符的 xml 时无效字符

我正在解析一个 xml 文本,其中包含类似 \'\xc3\xa1 \xc3\xa9 \xc3\xb1\' 的字符。

\n\n

我收到“在文本内容中发现无效字符。”错误,如下所示

\n\n
declare @Xml varchar(100)\n\nset @Xml =\n\'\n<?xml version="1.0" encoding="UTF-8"?>\n<Root>\xc3\xa1</Root>\n\'\n\ndeclare @XmlId integer\n\nexecute dbo.sp_xml_preparedocument @XmlId output, @Xml\n\nselect * from openXml( @XmlId, \'/\', 2) with (\n  Root varchar(10)\n)\nexecute dbo.sp_xml_removedocument @XmlId\n
Run Code Online (Sandbox Code Playgroud)\n\n

我收到以下错误:

\n\n
The XML parse error 0xc00ce508 occurred on line number 3, near the XML text "<Root>".\nMsg 6602, Level 16, State 2, Procedure sp_xml_preparedocument, Line 1\nThe error description is \'An invalid character was found in text content.\'.\nMsg 8179, Level 16, State 5, Line 13\nCould …
Run Code Online (Sandbox Code Playgroud)

xml sql sql-server html-encode sql-server-2008

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

使用.Net Core 2.0 Web应用程序登录到控制台

我正在使用.Net Core迈出第一步

刚刚使用创建了一个Web Hello世界

dotnet new web
Run Code Online (Sandbox Code Playgroud)

我可以看到已启用某种日志记录。我只想将某些内容记录到控制台。

但是我不知道如何从

app.Run(async (context) =>
{
    await context.Response.WriteAsync("Hello World!!!");
});
Run Code Online (Sandbox Code Playgroud)

我尝试了Console.WriteLine,但显然不起作用。

还按照本指南https://github.com/NLog/NLog.Web/wiki/Getting-started-with-ASP.NET-Core-(csproj---vs2017)对NLog进行了尝试,但我不知道如何注入记录器。

我只是出于教育目的而四处寻找,而不是寻找真正的记录器,因此也许有更好/更容易的选择。

asp.net logging dependency-injection asp.net-core-2.0

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

dotnet核心2.1:当从xunit项目引用web项目时"发现不同版本之间的冲突"

当我偶然发现这个奇怪的东西时,我正准备将netcore 2.0应用升级到2.1.

如果我创建一个Web项目,然后是一个引用第一个项目的xunit项目,只要我使用任何Newtonsoft.Json类,我就会收到以下错误:

/media/data/sas/devel/opt/dotnet-sdk-2.1.401/sdk/2.1.401/Microsoft.Common.CurrentVersion.targets(2110,5): 
warning MSB3277: Found conflicts between different versions of "Newtonsoft.Json" that could not be resolved.  
These reference conflicts are listed in the build log when log verbosity is set to detailed. 
[/media/data/sas/devel/apps/tmp/dotnet-error/test/test.csproj]
  test -> /media/data/sas/devel/apps/tmp/dotnet-error/test/bin/Debug/netcoreapp2.1/test.dll
Run Code Online (Sandbox Code Playgroud)

在我尝试升级的项目中,我遇到了很多这样的错误.似乎xunit项目正在使用包的diffente版本并且它们正好相似.

以下是重现错误的步骤:

$ dotnet new web -o project
$ dotnet new xunit -o test
$ cd test
$ dotnet add reference ../project/
$ dotnet clean && dotnet build
Run Code Online (Sandbox Code Playgroud)

一切正常,但如果我将它添加到project/Program.cs

    public static void Main(string[] args)
    {
        CreateWebHostBuilder(args).Build().Run();
        var s = Newtonsoft.Json.JsonConvert.SerializeObject(123);
    }
Run Code Online (Sandbox Code Playgroud)

然后我得到了上述警告. …

.net-core asp.net-core-2.0

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

gitlab api:获取一个组的所有项目(带有子组)

我想使用gitlab api来获取该组的所有项目和子项目,这是我进入该组页面时得到的信息

我注意到 gitlab 的 ui 使用

https://gitlab.com/groups/<group_name>/<subgroup_name>/-/children.json
Run Code Online (Sandbox Code Playgroud)

获取一个组的项目和子组。

我想知道是否有类似的东西,或者我必须使用groups/xxx/subgroupsgrops/xxx/projects端点递归地构建它。

api rest gitlab

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

尝试用自动键模拟shift+end

我正在尝试将 shift+end 键分配给 alt+shift+pageDown。

我有以下脚本:

keyboard.send_key('<shift>+<end>')
Run Code Online (Sandbox Code Playgroud)

我尝试了几种变体,例如:

keyboard.send_key('<shift+end>')
keyboard.send_key('shift+end')
etc...
Run Code Online (Sandbox Code Playgroud)

它们似乎都不起作用。

我查看了这个文档:https://github.com/boppreh/keyboard#api还有这个: https: //pypi.org/project/keyboard/但其中许多方法似乎不起作用(键盘.发送、键盘.按下、键盘.释放等)。看起来我的热键安装使用的是不同版本的键盘库。

还尝试过(来自这个问题):

keyboard.press_key('<shift>')
keyboard.send_key('<end>')
keyboard.release_key('<shift>')
Run Code Online (Sandbox Code Playgroud)

但他们似乎错过了按下的shift键,就像按下了结束键一样。

有什么方法可以找到我正在使用的键盘库,以便我可以找到相应的文档?

在 ubuntu 18.04.2 上使用 autokey-gtk 0.95.1、autokey-common 0.95.1

linux keyboard-shortcuts autokey

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

从表单提交事件访问打字稿中的 event.target.elements 属性

我有以下在 JavaScript 中可以正常工作的 React 代码:

function handleSubmit(event) {
  event.preventDefault()
  console.dir(event.target[0].value)
  console.dir(event.target.usernameInput.value)'EventTarget'.
  console.dir(event.target.elements.usernameInput.value)
}

return (
  <form onSubmit={handleSubmit}>
    <label htmlFor="usernameInput">Username:</label>
    <input id="usernameInput" type="text" onChange={handleChange} />
[...]
Run Code Online (Sandbox Code Playgroud)

我想对 TypeScript 执行相同的操作,但无法访问 event.target[0]、event.target.elements 或 event.target.usernameInput,而是得到““EventTarget 类型上不存在属性‘0’” '”和“类型‘EventTarget’上不存在属性‘usernameInput’”

这是ts代码:

const handleSubmit = (event: FormEvent<HTMLFormElement>) => {
    event.preventDefault()

  console.dir(event.target[0].value) // Property '0' does not exist on type 'EventTarget'.
  console.dir(event.target.usernameInput.value) // Property 'usernameInput' does not exist on type 'EventTarget'.
  console.dir(event.target.elements.usernameInput.value) // Property 'elements' does not exist on type 'EventTarget'.
Run Code Online (Sandbox Code Playgroud)

我如何访问这些属性?

event-handling typescript reactjs

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

高容量扫描和ocr自动解决方案?

我们需要大容量扫描和ocr解决方案

我们正在谈论每天将大约4000个文档数字化,并将它们保存为带有ocr的pdf文件(带有隐藏文本)......

解决方案应该让操作员扫描文档并自动将文件保存到特定的网络资源,由将其上传到数据库的应用程序采取...

我们正在评估来自kofax的企业解决方案http://www.kofax.com/

你还知道其他什么产品?

有类似要求的经验吗?

任何开源(或至少可访问)的解决方案?

com,activex api支持?

ocr document scanning kofax

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

如何使用vbscript读取注册表项的所有值?

我的注册表中有以下值

钥匙:

HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Accepted Documents\

价值观:

* -> application/msword
** -> application/vnd.ms-excel
*** -> application/vnd.ms-powerpoint
Run Code Online (Sandbox Code Playgroud)

等等

我想知道如何阅读所有内容

使用Wscript.ShellRegRead我只能读取一个值,但我事先不知道这些值......

registry vbscript

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

scala coding-style:根据可选值初始化val Seq

我正在开发一个简单的函数,它应该根据可能不存在的可选参数构建一个sql条件.

我正在尝试使用不可变的值来完成它,以及优雅和惯用的方式.

到目前为止,我带来了这样的东西:

val cond: Seq[String] = Nil ++ 
  (if (entity != "*") Seq("entity = {entity}") else Nil) ++
  (if (name != "*") Seq("name = {name}") else Nil) ++

val condition = 
  if (cond.size == 0) "" 
  else " where " + cond.mkString(" and ") + " "
Run Code Online (Sandbox Code Playgroud)

所以,我只是开始使用Seqs,如果价值不存在我将它与Nil合并

使用var我得到类似的东西:

var cond: Seq[String] = Seq();
if (entity != "*") cond = cond :+ "entity = {entity}"
if (name != "*") cond = cond :+ "name = {name}"
Run Code Online (Sandbox Code Playgroud)

我发现它更具可读性(我想知道第二种方法是否因为var而不是线程安全的)

我想知道什么是scala惯用和优雅的方式来解决这样的事情

- …

collections coding-style scala

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