小编Jan*_*Jan的帖子

获取类的函数(方法)

我必须动态获取ES6类的属性和功能.这甚至可能吗?

使用for ... in循环,我只能循环遍历类实例的属性:

class Foo {
  constructor() {
    this.bar = "hi";
  }
  someFunc() {
    console.log(this.bar);
  }
}
var foo = new Foo();
for (var idx in foo) {
  console.log(idx);
}
Run Code Online (Sandbox Code Playgroud)

输出:

bar
Run Code Online (Sandbox Code Playgroud)

javascript oop ecmascript-6

61
推荐指数
4
解决办法
4万
查看次数

GCP部署管理器:403没有storage.buckets.get访问权限

我正在尝试使用Deployment Manager创建一个存储桶但是当我想创建部署时,我收到以下错误:

ERROR: (gcloud.deployment-manager.deployments.create) Error in Operation [operation-1525606425901-56b87ed1537c9-70ca4aca-72406eee]: errors:
- code: RESOURCE_ERROR
  location: /deployments/posts/resources/posts
  message: '{"ResourceType":"storage.v1.bucket","ResourceErrorCode":"403","ResourceErrorMessage":{"code":403,"errors":[{"domain":"global","message":"myprojectid@cloudservices.gserviceaccount.com
    does not have storage.buckets.get access to posts.","reason":"forbidden"}],"message":"myprojectid@cloudservices.gserviceaccount.com
    does not have storage.buckets.get access to posts.","statusMessage":"Forbidden","requestPath":"https://www.googleapis.com/storage/v1/b/posts","httpMethod":"GET","suggestion":"Consider
    granting permissions to myprojectid@cloudservices.gserviceaccount.com"}}'
Run Code Online (Sandbox Code Playgroud)

如果我理解正确,部署管理器使用服务帐户(如消息中所述)来实际创建我的所有资源.我已经检查了IAM并确保服务角色(myprojectid@cloudservices.gserviceaccount.com)确实具有"编辑器"的访问权限,甚至添加了"存储管理"(包括storage.buckets.get)以确保更加可靠.但是,我仍然得到相同的错误消息.

我是否将权限分配给错误的IAM用户/我做错了什么?


使用的命令:

gcloud deployment-manager deployments create posts --config posts.yml
Run Code Online (Sandbox Code Playgroud)

我的部署模板:

bucket.jinja

resources:
- name: {{ properties['name'] }}
  type: storage.v1.bucket
  properties:
    name: {{ properties['name'] }}
    location: europe-west1
    lifecycle:
      rule:
      - action:
          type: Delete
        condition:
          age: 30
          isLive: true
    labels:
      datatype: {{ properties['datatype'] …
Run Code Online (Sandbox Code Playgroud)

google-cloud-storage google-cloud-platform google-iam google-deployment-manager

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

无法使用Cocoa(IOKit)将数据发送到我的Arduino Uno

我目前正在尝试通过Mac应用程序将数据发送到我的Arduino.我的Arduino Uno中的代码如下所示:

void setup()
{
    pinMode (2, OUTPUT);
    pinMode (3, OUTPUT);
    pinMode (4, OUTPUT);

    Serial.begin (9600);
}

void loop ()
{
    digitalWrite (2, HIGH);

    if (Serial.available () > 0)
    {
        int c = Serial.read();

        if (c == 255)
        {
            digitalWrite (3, HIGH);
        }
        else
            digitalWrite (4, HIGH);
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我在XCode项目中的代码:

// Open the serial like POSIX C
serialFileDescriptor = open(
                            "/dev/tty.usbmodemfa131",
                            O_RDWR |
                            O_NOCTTY |
                            O_NONBLOCK );

struct termios options;

// Block non-root users from using this port …
Run Code Online (Sandbox Code Playgroud)

cocoa serial-port arduino objective-c iokit

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

golang:将hex转换为float

我必须转换hex,表示为strings(例如"0xC40C5253")浮点值(IEEE-754转换).我没有设法使用strconv.ParseFloat函数.还有什么我必须使用的吗?到目前为止我找不到它.我也尝试先将它转换为整数然后转换为浮点数,但结果是错误的.

我上次尝试的代码:

package main

import (
  "fmt"
  "strconv"
)

func main () {
  x, err := strconv.ParseInt("C40C5253", 16, 64) 
  f, err := strconv.ParseFloat(fmt.Sprintf("%d", x), 64) 

  if err != nil {
    fmt.Printf("Error in conversion: %s\n", err)
  } else {
    fmt.Println(f)
  }
}
Run Code Online (Sandbox Code Playgroud)

floating-point hex type-conversion go

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