小编Man*_*dha的帖子

如果其项目是 Angular 组件,则 CSS-Grid 不起作用

我有一个工作代码(在 HTML/CSS 网格中),它由css-grid3 行 2 列组成。第一行是导航(跨越所有列),中间是内容(没有跨越所有列),最后一行是页脚(跨越所有列)。

.body__div--background {
  background: linear-gradient(45deg,#33b1f8 37%,#6e90f6 100%); /*syntax linear-gradient(direction, color1 limit, color2 limit)*/
  color:#555555;
  font-family: Verdana;
  line-height:1.5;
  font-size: 11px;
  letter-spacing: 0.25px;
}

.css-grid-container{
  height:100vh; /*???*/
  display: grid;
  grid-gap:20px;
  grid-template-columns: 1fr 1fr;  /* 2columns*/
  grid-template-rows: auto 15fr 1fr; /* 3 rows. Auto takes height of navigation, remaining is divided into 2 rows, middle row (content) is 15 times larger than the 3rd row (footer).*/

}
Run Code Online (Sandbox Code Playgroud)

css元素放在网格中的适当位置是

.css-grid-item__nav{
  grid-column: 1 / -1; //nav …
Run Code Online (Sandbox Code Playgroud)

css css-grid angular

4
推荐指数
2
解决办法
3801
查看次数

如何根据字符对字符串进行模式匹配?

在我的代码中,字符串应具有以下结构part1-part2-part3。不同的部分由隔开,-只能有3个部分。

到目前为止,我已经使用过的split方法,String并且可以检查返回的长度Array以验证结构:

val tagDetails: Array[String] = tag.split('-') //syntax of received tag is part1-part2-part3

if (tagDetails.length == 3) {
  val course: String = tagDetails(0)
  val subject: String = tagDetails(1)
  val topic: String = tagDetails(2)
  println("splitted tag " + course + ", " + subject + ", " + topic) 
} else {..}
Run Code Online (Sandbox Code Playgroud)

我该怎么做match呢?

scala

4
推荐指数
2
解决办法
54
查看次数

未捕获的 DOMException:无法在“WorkerGlobalScope”上执行“importScripts”:“http://localhost:9000/worker-html.js”处的脚本无法加载

我在 Angular 应用程序中使用 Ace Editor。它在这里定义 - https://www.npmjs.com/package/ng2-ace-editor

\n\n

用法:

\n\n

.html

\n\n
<ace-editor id="editor" class="form-control" formControlName="answer" [ngClass]="validateField(\'answer\')" [(text)]="text"></ace-editor>\n
Run Code Online (Sandbox Code Playgroud)\n\n

.ts

\n\n
ngAfterViewInit(){\n\n    this.editor = ace.edit(\'editor\');\n         ace.config.set(\'basePath\', \'/assets/ui/\');\n         ace.config.set(\'modePath\', \'/assets/ui/\');\n         ace.config.set(\'themePath\', \'/assets/ui/\');\n        ace.config.setModuleUrl(\'ace/mode/php_worker\',\'/assets/ui/worker-php.js\');\n        ace.config.setModuleUrl(\'ace/mode/coffee_worker\',\'/assets/ui/worker-coffee.js\');\n        ace.config.setModuleUrl(\'ace/mode/css_worker\',\'/assets/ui/worker-css.js\');\n        ace.config.setModuleUrl(\'ace/mode/javascript_worker\',\'/assets/ui/worker-javascript.js\');\n        ace.config\n.setModuleUrl(\'ace/mode/html_worker\',\'/assets/ui/worker-html.js\');\n        ace.config.setModuleUrl(\'ace/mode/json_worker\',\'/assets/ui/worker-json.js\');\n        ace.config.setModuleUrl(\'ace/mode/lua_worker\',\'/assets/ui/worker-lua.js\');\n        ace.config.setModuleUrl(\'ace/mode/xml_worker\',\'/assets/ui/worker-xml.js\');\n        ace.config.setModuleUrl(\'ace/mode/xquery_worker\',\'/assets/ui/worker-xquery.js\');\n        this.editor.setTheme(\'ace/theme/eclipse\');\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

1)我收到以下错误:

\n\n

blob:http://localhos\xe2\x80\xa699f9-cccd48bdb093:1 Uncaught DOMException: Failed to execute \'importScripts\' on \'WorkerGlobalScope\': The script at \'http://localhost:9000/worker-html.js\' failed to load.\n at blob:http://localhost:9000/9446350d-625c-418b-99f9-cccd48bdb093:1:1

\n\n

为什么是这样?

\n\n

2)我找不到这些工作文件的用途,以及它们是从哪里包含的。

\n

ace-editor angular

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

OpenAI Embeddings API:嵌入如何工作?

embeddingsOpenAI有相当多的教程。我无法理解它们是如何工作的。

参考https://platform.openai.com/docs/guides/embeddings/what-are-embeddings, anembedding是 avectorlist。将字符串传递给embedding模型,模型返回一个数字(用最简单的术语来说)。我可以使用这个号码。

如果我使用一个简单的字符串来获取它embeddings,我会得到一个巨大的列表

result = get_embedding("I live in space", engine = "textsearchcuriedoc001mc")
Run Code Online (Sandbox Code Playgroud)

result打印时

[5.4967957112239674e-05,
 -0.01301578339189291,
 -0.002223075833171606,
 0.013594076968729496,
 -0.027540158480405807,
 0.008867159485816956,
 0.009403547272086143,
 -0.010987567715346813,
 0.01919262297451496,
 0.022209804505109787,
 -0.01397960539907217,
 -0.012806257233023643,
 -0.027908924967050552,
 0.013074451126158237,
 0.024942029267549515,
 0.0200139675289392 , ..... -> truncated this much, much, much longer list 
Run Code Online (Sandbox Code Playgroud)

问题 1 - 这个庞大的列表与我的 4 字文本有何关联?

问题2 -

我创建embeddings了要在查询中使用的文本。注意,与原文内容的文字完全一致I live in space

queryembedding = get_embedding(
        'I live in space',
        engine="textsearchcuriequery001mc"
    )
queryembedding …
Run Code Online (Sandbox Code Playgroud)

azure openai-api azure-openai

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

Traversable是特质还是阶级

问题1 -

在Scala文档中,我发现Traversable是一个带有抽象方法的特征foreach:

http://www.scala-lang.org/docu/files/collections-api/collections.html

那么,为什么我可以实例化Traversable类型的对象?

val t = Traversable(1,2,3)

t.foreach(println _) //where is Scala picking foreach a definition from? 
Run Code Online (Sandbox Code Playgroud)

问题2 - Traversable与List或Array等其他类有何不同?它是否属于Seq,Set或Map类别(我认为其他集合继承自Traversable)

问题3 -我能为做完全相同Iterable,即使按文档,可迭代有一个抽象方法,特点iterator:

val v1 = Iterator(1,2,3)

v1.foreach( println _)
Run Code Online (Sandbox Code Playgroud)

我错过了什么?

iterator scala traversable

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

我应该阻止未来 - 斯卡拉

根据Scala文档,不应该对Future进行阻止.

"如前所述,为了表现和防止僵局,强烈建议不要阻止未来.期货的回调和组合是使用其结果的首选方式.但是,在某些情况下可能需要阻止并支持通过Futures and Promises API."

在我的程序退出之前,如何确保我的所有期货已完成(以及他们的回调已完成)?我通常在主函数结束时使用Await.result来确保所有Futures都已完成.

object ConcurrencyExample extends App {
val gpf= Future {some operations}
val ccf = Future{some operations}


val atbf = for {g <- gpf
c <- ccf if c == true}  yield {some operations}

//is it OK to use Await? If not, how do I ensure that all Futures have finished
        ?
Await.result(atbf,1000 millis )
 }
Run Code Online (Sandbox Code Playgroud)

问题

  1. 使用Await错了吗?我的代码不等待期货完成否则
  2. 如果是这样,有什么替代方案?
  3. 在主程序退出之前,如何确保Future及其回调已完成?

scala

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

指令中的选择器

以下指令应该隐藏一个元素。

import {Directive, ElementRef, Input, Renderer2} from '@angular/core';
import {el} from "@angular/platform-browser/testing/src/browser_util";

// Directive decorator
@Directive({ selector: '[hide-me]' })
// Directive class
export class MyHiddenDirective {
//  @Input() hideme:boolean;
  constructor(public el: ElementRef, public  renderer: Renderer2) {
    // Use renderer to render the element with styles
        renderer.setStyle(el.nativeElement, 'display', 'none');

  }
}
Run Code Online (Sandbox Code Playgroud)

我使用它如下:

<div>Name: <input hide-me #myint  type="text" name="name" [(ngModel)]="this.name" />  You entered {{this.name}} {{myint.hasAttribute('required')}}</div>
Run Code Online (Sandbox Code Playgroud)

为什么selector: '[hide-me]'有效但selector: 'hide-me'无效?我在使用指令时不使用方括号,<input hide-me...而不是<input [hide-me].... 在 Components 中,我们通常指定不带方括号的选择器。为什么我需要在指令中指定方括号?

angular2-directives angular

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

为什么我必须以unapply方法返回some

如果我不使用Somein unapply方法,为什么以下代码不起作用?

scala> object T {
     | def unapply(i:Int) = (i+1,i+2) //Some not used, I get error
     | }
defined object T

scala> 1 match {
     | case T(x,y) => println(x,y)
     | }
<console>:14: error: an unapply result must have a member `def isEmpty: Boolean
       case T(x,y) => println(x,y)
            ^

scala> object T {
     | def unapply(i:Int) = Some(i+1,i+2) //Some used. No error
     | }
defined object T

scala> 1 match {
     | case T(x,y) => println(x,y) …
Run Code Online (Sandbox Code Playgroud)

scala

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

如何在 Angular 中安装 Quill.js

抱歉,我对包装工作原理的理解Angular很糟糕!我想WYSIWYG在我的Angular6应用程序中使用编辑器。我已经归零到了quill.jshttps://quilljs.com/docs/quickstart/

但我很困惑如何将它包含在我的项目中。我已将其添加为我的package.json.

  "dependencies": {
...
    "quill": "1.3.6"
  }
Run Code Online (Sandbox Code Playgroud)

然后我尝试用于以下用途textarea

<textarea id="question-description" type="text" class="form-control" formControlName="questionDescription" [ngClass]="validateField('questionDescription')"  rows="4"></textarea>
Run Code Online (Sandbox Code Playgroud)

Quill并像下面一样初始化ngAfterViewInit

var quill = new Quill('#question-description', {
  theme: 'snow'
});
Run Code Online (Sandbox Code Playgroud)

但我收到错误

ReferenceError: Quill is not defined
    at NewPracticeQuestionComponent.push../s
Run Code Online (Sandbox Code Playgroud)

我还在组件文件declare var Quill:any;的顶部添加了.ts

我可以看到node_modules有一个quill文件夹,其中有dist/quill.js我认为Quill必须定义和导出对象的位置(但尚未检查)。

我究竟做错了什么?

quill angular angular6

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

isEmpty 为空集返回 false

在这段代码中

    def findQuestionCreatedCount(transaction:DistributedTransaction,userId:UUID,tagSet:Set[String]):Future[List[(String,Int)]]={
        logger.trace(s"will find questions created portfolio for ${userId} and tagSet ${tagSet}. tagSet empty ${tagSet.isEmpty}")
        if(tagSet.isEmpty == false) { //set has data
      ...
}
Run Code Online (Sandbox Code Playgroud)

我看到印刷品 will find questions created portfolio for 3455c2b9-37f2-4373-9dcd-9e71b43e8c3d and tagSet Set(). tagSet empty false

为什么 tagSet 的值为Set()false?不应该是真的吗?

scala

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