小编Ber*_*tel的帖子

从作为一个文档一部分的对象数组中获取一个元素(mongoose)

我有一个包含的架构Friends.Friends是一个数组,其中每个元素都是一个包含id,gender和emoji的对象.

var userSchema = new Schema({
    id: {
        type: String,
        unique: true,
        required: true
    },
    gender: String,

    Friends: [{
        id: String
        gender: String
        emoji: String

    }]

});
Run Code Online (Sandbox Code Playgroud)

在下面的代码中,我正在访问一个包含Friends数组的文档,并指定使用它的搜索distinct只显示文档的Friends数组.我只需要访问包含指定id的那个数组的一个元素.不像在代码中完成的那样在查询之后过滤那个数组,有没有办法只从查询中获取元素?换句话说,是否有一个额外的功能来区分或某种类型的猫鼬运算符,允许这样做?

User.findOne().distinct('Friends', { id: req.body.myId }).then(function(myDoc) {

    var friendAtt = myDoc.filter(function(obj) {
        return obj.id == req.body.id
    })[0]

})
Run Code Online (Sandbox Code Playgroud)

mongoose mongodb node.js mongodb-query

6
推荐指数
2
解决办法
8332
查看次数

SonarQube不评论GitHub拉取请求

SonarQube在Travis成功构建之后,我正试图对我的GitHub拉取请求进行评论.

我已经进行了正常的分析工作.对于拉取请求分析,我还有所有令牌,安装了插件等.成功识别了拉取请求中的问题:调试日志显示成功的HTTP请求,其中服务器响应相关问题.日志的一些行:

15:06:10.194 INFO: ANALYSIS SUCCESSFUL
15:06:10.197 DEBUG: Post-jobs : GitHub Pull Request Issue Publisher (wrapped)
15:06:10.197 INFO: Executing post-job GitHub Pull Request Issue Publisher (wrapped)
Run Code Online (Sandbox Code Playgroud)

在GitHub上,我可以看到声纳使用的oauth令牌实际上正在被使用.

在向pull请求添加提交时,甚至还有sonarqube的状态:当添加新提交时,等待响应的时间很短,然后更改为"SonarQube reported no issues".请注意,此状态出现在声纳扫描仪在Travis上运行之前.

有谁知道可能是什么问题或我可以做什么来进一步调试这个?提前致谢!

github pull-request travis-ci sonarqube

6
推荐指数
1
解决办法
2192
查看次数

找不到方法apt()

我正在尝试使用Dagger2,我正在使用Android studio 2.2.2但是我有一个gradle错误:

Error:(34, 0) Could not find method apt() for arguments
[com.google.dagger:dagger-compiler:2.6] on object of type
 org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
<a href="openFile:C:\Users\edi.bershatsky\Google
Drive\Android\eWave\MyCode\MyDagger2\app\build.gradle">Open File</a>
Run Code Online (Sandbox Code Playgroud)

请帮我理解我的gradle有什么问题

这是我的项目gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.2'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenCentral()
        maven{
            url 'https://oss.sonatype.org/content/repositories/snapshots/'
        }
    } …
Run Code Online (Sandbox Code Playgroud)

android apt dagger-2

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

Keras:如何从张量中找到与numpy.where()类似的特定值的索引

我正在寻找类似于python "numpy.where()"命令的Keras 命令.基本上,我的想法是从张量中提取指数.在python我可以做的只是f_j=(np.where(X==j))让我具体indices(f_j)的价值j.

例如:

X= [0 1 1 0 0 2 3 ]

f_j=(np.where(X==1))

f_j= [1 2]
Run Code Online (Sandbox Code Playgroud)

是否有任何类似的功能可用于此目的?

我试着在张量内编写数组搜索.但是,当调用"if K.equal():"line as 时,我最终会出错

TypeError:不允许使用tf.Tensor作为Python bool.如果t不是None,则使用:而不是if t:来测试是否定义了张量,并使用TensorFlow操作(如tf.cond)来执行以张量值为条件的子图.

def loss(y_true, y_pred:

b=K.equal(y_true,0)

b=K.cast(b,dtype='float32')

for i in range(0,5):

if K.equal(b[i],1):

........

y_true = [0 1 1 0 0 2 3 ]
Run Code Online (Sandbox Code Playgroud)

keras

6
推荐指数
1
解决办法
3863
查看次数

curl:发送带有嵌入式图像和附件的html电子邮件

我的目标是使用curl带有嵌入图像的html正文发送电子邮件,例如:

电子邮件模板图片

我正在这样发送电子邮件:

curl "smtp://smtp.gmail.com:587" -v \
     --mail-from "sender@gmail.com" \
     --mail-rcpt "receiver@gmail.com" \
     --ssl -u sender@gmail.com:secretpassword \
     -T "message.txt" -k --anyauth
Run Code Online (Sandbox Code Playgroud)

我的message.txt样子:

From: Some Name <sender@gmail.com>
To: Some Name <receiver@gmail.com>
Subject: example of mail
Reply-To: Some Name <sender@gmail.com>
Cc: 
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="MULTIPART-MIXED-BOUNDARY"

--MULTIPART-MIXED-BOUNDARY
Content-Type: multipart/alternative; boundary="MULTIPART-ALTERNATIVE-BOUNDARY"

--MULTIPART-ALTERNATIVE-BOUNDARY
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: base64
Content-Disposition: inline

PGh0bWw+Cjxib2R5PgogICAgPGRpdj4KICAgICAgICA8cD5IZWxsbywgPC9wPgogICAgICAgIDxw
PlBsZWFzZSBzZWUgdGhlIGxvZyBmaWxlIGF0dGFjaGVkPC9wPgogICAgICAgIDxwPkFkbWluIFRl
YW08L3A+CiAgICAgICAgPGltZyBzcmM9ImFkbWluLnBuZyIgd2lkdGg9IjE1MCIgaGVpZ2h0PSI1
MCI+CiAgICA8L2Rpdj4KPC9ib2R5Pgo8L2h0bWw+Cg==
--MULTIPART-ALTERNATIVE-BOUNDARY--
--MULTIPART-MIXED-BOUNDARY
Run Code Online (Sandbox Code Playgroud)

解码的html是:

<html>
<body>
    <div>
        <p>Hello, </p>
        <p>Please see the log file attached</p>
        <p>Admin Team</p>
        <img …
Run Code Online (Sandbox Code Playgroud)

email bash curl smtp

6
推荐指数
1
解决办法
6127
查看次数

有效的 GitHub api v4 查询不断返回错误“解析 JSON 的问题”

以下是对 GitHub api v4 的 cURL 查询示例,该查询不断返回错误:

curl -H "Authorization: bearer token" -X POST -d " \
 { \
   \"query\": \"query { repositoryOwner(login: \"brianzelip\") { id } }\" \
 } \
" https:\/\/api.github.com\/graphql
Run Code Online (Sandbox Code Playgroud)

返回的错误:

{
  "message": "Problems parsing JSON",
  "documentation_url": "https://developer.github.com/v3"
}
Run Code Online (Sandbox Code Playgroud)

为什么我一直收到这个错误?


根据关于形成查询调用GH api v4 文档,上述 cURL 命令是有效的。以下是文档所说的支持我关于上述 cURL 命令有效的说法:

{
  "message": "Problems parsing JSON",
  "documentation_url": "https://developer.github.com/v3"
}
Run Code Online (Sandbox Code Playgroud)

注意:“query”的字符串值必须转义换行符,否则架构将无法正确解析它。对于 POST 正文,使用外部双引号和转义的内部双引号。

当我在GitHub GraphQL API Explorer 中输入上述查询时,我得到了预期的结果。对于 GH GraphQL Explorer,上述 cURL 命令的格式如下所示:

{
  repositoryOwner(login: …
Run Code Online (Sandbox Code Playgroud)

curl github-api graphql github-graphql

6
推荐指数
1
解决办法
3754
查看次数

Google Translate API 身份验证密钥和用法

https://cloud.google.com/translate/docs/basic/setup-basic,需要设置环境变量:

export GOOGLE_APPLICATION_CREDENTIALS='/path/to/credential.json'
Run Code Online (Sandbox Code Playgroud)

然后可以发出 curl 请求:

curl -s -X POST -H "Content-Type: application/json" \
    -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
    --data "{
  'q': 'The Great Pyramid of Giza (also known as the Pyramid of Khufu or the
        Pyramid of Cheops) is the oldest and largest of the three pyramids in
        the Giza pyramid complex.',
  'source': 'en',
  'target': 'es',
  'format': 'text'
}" "https://translation.googleapis.com/language/translate/v2"
  
Run Code Online (Sandbox Code Playgroud)

Bearer来自gcloud auth application-default print-access-token命令值的请求标头中有一个身份验证密钥。

在尝试多次调用 之后gcloud auth application-default print-access-token …

oauth google-api google-translate google-cloud-platform

6
推荐指数
1
解决办法
1460
查看次数

Nivo ResponsiveBar 中未显示数据的颜色

我的 React 应用程序中有一个ResponsiveBar组件,但颜色未按预期显示。我已遵循官方文档中的指南。数据如下所示:

{
  "data": [
    {
      "bucket": "Prospects Imported",
      "Oliver Queen": 10,
      "Oliver QueenColor": "hsl(177.06123087721252,18.89068530574307%,16.53273587631816%)",
      "Ray Palmer": 10,
      "Ray PalmerColor": "hsl(287.8197874078934,62.18829850513416%,13.604789291455033%)"
    },
    {
      "bucket": "Assigned",
      "Oliver Queen": 158,
      "Oliver QueenColor": "hsl(130.29946551632844,21.88588940442986%,85.78716216902176%)",
      "Ray Palmer": 2,
      "Ray PalmerColor": "hsl(192.1716868789712,1.8797192964029374%,7.158239130186517%)"
    },
    {
      "bucket": "Calls Made",
      "Oliver Queen": 24,
      "Oliver QueenColor": "hsl(164.04170858156496,47.95430493222506%,79.37512126292603%)",
      "Ray Palmer": 0,
      "Ray PalmerColor": "hsl(38.148811405937096,23.83917214972724%,37.366418973565544%)"
    },
    {
      "bucket": "Emails Sent",
      "Oliver Queen": 120,
      "Oliver QueenColor": "hsl(316.96830604521773,3.6081626612787465%,54.49458825991964%)",
      "Ray Palmer": 0,
      "Ray PalmerColor": "hsl(223.97078722168806,98.41710495281106%,47.3590863956761%)"
    },
    {
      "bucket": "Texts …
Run Code Online (Sandbox Code Playgroud)

bar-chart reactjs nivo-react

6
推荐指数
1
解决办法
3551
查看次数

如何在 gitlab api 问题查询中使用“not”条件

我正在尝试阅读未解决的问题标题列表。为此,我参考了 API 文档(https://docs.gitlab.com/ee/api/issues.html),其中提到了 NOT,但我无法让 NOT 工作。

到目前为止,我已尝试使用以下 python 脚本来阅读问题列表,但现在我无法找到如何使用 NOT 来过滤未解决标签的问题。

import gitlab

# private token or personal token authentication
gl = gitlab.Gitlab('https://example.com', private_token='XXXYYYZZZ')

# make an API request to create the gl.user object. This is mandatory if you
# use the username/password authentication.
gl.auth()

# list all the issues
issues = gl.issues.list(all=True,scope='all',state='opened',assignee_username='username')
for issue in issues:
    print(issue.title)
Run Code Online (Sandbox Code Playgroud)

python gitlab-api

6
推荐指数
1
解决办法
1280
查看次数

当没有进行SSL连接尝试时,MongoDB抱怨SSL握手

我尝试使用官方mongo Docker镜像以及khezen/mongo,当我尝试建立未加密的HTTP连接时,我收到相同的错误消息:

AssertionException handling request, closing client connection: 17133 SSL handshake requested, SSL feature not available in this build
Run Code Online (Sandbox Code Playgroud)

这是来自khezen/mongo的消息.官方mongo图像给出了稍微不同的错误:

AssertionException handling request, closing client connection: 17132 SSL handshake received but server is started without SSL support
Run Code Online (Sandbox Code Playgroud)

当使用自定义命令(mongod --sslMode allowSSL --sslPEMKeyFile /data/db/mongodb.pem)从docker-compose.yml启动官方mongo映像时:

SSL: error:1407609C:SSL routines:SSL23_GET_CLIENT_HELLO:http request
Run Code Online (Sandbox Code Playgroud)

现在,这是在尝试从邮递员提出以下请求时:

模式:POST

URL:http:// localhost:27017/lasdf?client = asdf

数据负载:

{
    "gargen": "flagren",
    "jiminy": {
        "crickets": 1,
        "isChirping": false
    },
    "blargen": "fargle",
    "_id": "a96c2a4ec6fb4a8dbe2305687eb0e50b"
}
Run Code Online (Sandbox Code Playgroud)

有趣的是,当我将' http' 更改为' '时,https我没有收到任何错误消息,但也没有响应,当然数据库也没有更改.

更奇怪的是,我是 …

ssl json http mongodb node.js

5
推荐指数
1
解决办法
2564
查看次数