我有这个场景,我需要使用一个迭代器,为每个项调用一个函数f(item)并返回一个Future[Unit]
.
但是,我需要让每个f(item)
调用按顺序执行,它们不能并行运行.
for(item <- it)
f(item)
Run Code Online (Sandbox Code Playgroud)
不会起作用,因为这会并行启动所有调用.
我该怎么做才能按顺序进行?
我们在谷歌云平台上托管git repo.我知道对于github.com,我们可以使用拉取请求进行代码审查,但谷歌云似乎没有提供.
我很奇怪:我如何在谷歌云平台上进行回购代码审查?
git pull-request google-cloud-platform google-cloud-source-repos
TLDR;我在为服务帐号分配 IAM 权限时遇到问题。
我正在构建一个测试,涉及使用 firebase Auth 生成自定义令牌。当我打:
const token = await admin.auth().createCustomToken('test', {
isAdmin: true,
})
Run Code Online (Sandbox Code Playgroud)
抛出以下错误
Permission iam.serviceAccounts.signBlob is required to perform
this operation on service account
projects/-/serviceAccounts/dashboard@appspot.gserviceaccount.com.;
Please refer to
https://firebase.google.com/docs/auth/admin/create-custom-tokens
for more details on how to use and troubleshoot this feature
Run Code Online (Sandbox Code Playgroud)
在引用的文档中,它说将服务帐户令牌创建者角色添加到服务帐户。我已经添加了该角色(以及尝试服务帐户管理员无济于事。
我可以验证我的权限似乎设置正确,当我运行时,
gcloud projects get-iam-policy project
我可以看到我的服务帐户附加到所需的角色
- members:
- serviceAccount:dashboard@appspot.gserviceaccount.com
role: roles/iam.serviceAccountTokenCreator
Run Code Online (Sandbox Code Playgroud)
但是,如果我查看该特定服务帐户,它似乎显示为空,这与我的错误一致:
gcloud iam service-accounts get-iam-policy dashboard@appspot.gserviceaccount.com
etag: ACAB
Run Code Online (Sandbox Code Playgroud)
我认为导致我的服务帐户权限显示为空白的原因是罪魁祸首,但我不确定在哪里进一步调试。在我看来,唯一的区别是一个命令被调用,其中包含一个项目,但我使用项目 ID 初始化了我的 firebase 应用程序,并已对其进行了验证,(firebase-admin).apps[0].options
因此这似乎是一个死胡同。
google-cloud-platform firebase-authentication google-iam google-cloud-iam
我有一个文本语料库,我正在使用正则表达式对其进行解析以查找最常见的单词。目前我正在使用.match(/(?!'.*')\b\[\w'\]+\b/g)
. 我的问题是\w
与非字母数字字符不匹配,我的表情符号永远不会被解析。具体来说,我正在尝试制作一个正则表达式来识别单词(包括收缩)和表情符号,在单词边界上分开。
作为一个例子,我希望能够采取"Hey there! , let's go to the moon "
并得到
Array( "Hey", "there", "", "let's", "go", "to", "the", "moon", "", "")
Run Code Online (Sandbox Code Playgroud) 我正在使用 Google Cloud Functions 构建一个 http 端点。我有一个加密的机密存储为文件,该文件在函数中加载和解密,以防止我的机密存储在代码中。通常我从 Google Cloud Storage 动态加载一些东西,但似乎 KMS 更适合这个目的。
使用 KMS 的代码如下所示:
getCredentials: async function () {
const kms = require('@google-cloud/kms');
const client = new kms.KeyManagementServiceClient();
const fs = require('fs');
let ciphertext = (fs.readFileSync('secret.enc')).toString('base64')
const name = client.cryptoKeyPath(
'[project]',
'global',
'[keyring]',
'[key]'
);
Run Code Online (Sandbox Code Playgroud)
一切都在本地运行良好,但在使用 http 触发器调用时,我似乎无法使该函数正常工作。检查日志我看到了这个:
textPayload: "Error: Permission 'cloudkms.cryptoKeyVersions.useToDecrypt' denied for resource 'projects/[projectname]/locations/global/keyRings/[keyring]/cryptoKeys/[key]'.
at Http2CallStream.call.on (/srv/functions/node_modules/@grpc/grpc-js/build/src/client.js:96:45)
at Http2CallStream.emit (events.js:194:15)
at Http2CallStream.EventEmitter.emit (domain.js:459:23)
at process.nextTick (/srv/functions/node_modules/@grpc/grpc-js/build/src/call-stream.js:71:22)
at process._tickCallback (internal/process/next_tick.js:61:11)"
Run Code Online (Sandbox Code Playgroud)
我已经尝试了各种可用的 IAM 权限(包括所有者),所以似乎我必须有更深层次的误解。
这可能与我无法让 Google Cloud Build …
google-cloud-functions google-cloud-kms google-cloud-iam google-cloud-build
我想测试Point对象列表中是否有正方形.
这是我的Point类:
class Point {
private int x;
private int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public int distanceSquare(Point q) {
return (x - q.getX()) * (x - q.getX()) +
(y - q.getY()) * (y - q.getY());
}
}
Run Code Online (Sandbox Code Playgroud)
我可以测试四个Point是否为Square: …
我有一系列结构; 该数组的大小为N.
我想从数组中删除重复项; 也就是说,进行就地更改,将数组转换为每个结构的单一外观.另外,我想知道新的大小M(简化数组中的最高索引).
结构包括原语,因此比较它们是微不足道的.
如何在C++中有效地完成这项工作?
我已经实现了以下运算符:
bool operator==(const A &rhs1, const A &rhs2)
{
return ( ( rhs1.x== rhs2.x ) &&
( rhs1.y == rhs2.y ) );
}
bool operator<(const A &rhs1, const A &rhs2)
{
if ( rhs1.x == rhs2.x )
return ( rhs1.y < rhs2.y );
return ( rhs1.x < rhs2.x );
}
Run Code Online (Sandbox Code Playgroud)
但是,运行时出错:
std::sort(array, array+ numTotalAvailable);
* array will have all elements here valid.
std::unique_copy(
array,
array+ numTotalAvailable,
back_inserter(uniqueElements));
* uniqueElements will have non-valid elements.
Run Code Online (Sandbox Code Playgroud)
这有什么不对?
我正在尝试编写一个函数sum_of_squares(xs)来计算列表xs中数字的平方和.例如,sum_of_squares([2,3,4])应返回4 + 9 + 16,即29:
这是我试过的:
import random
xs = []
#create three random numbers between 0 and 50
for i in range(3):
xs.append(random.randint(0,50))
def sum_of_squares(xs):
#square the numbers in the list
squared = i ** i
#add together the squared numbers
sum_of_squares = squared + squared + squared
return sum_of_squares
print (sum_of_squares(xs))
Run Code Online (Sandbox Code Playgroud)
现在这总是打印
12
Run Code Online (Sandbox Code Playgroud)
因为它将i视为列表中的整数数,而不是整数的值.我怎么说"将值乘以整数的值",因为列表中有多个整数可以得到平方值?
问这个问题让我尝试这个:
import random
xs = []
#create three random numbers between 0 and 50
for i in range(3):
xs.append(random.randint(0,50))
def sum_of_squares(xs):
#square the numbers …
Run Code Online (Sandbox Code Playgroud) 我遇到一个问题,无法指定使用brew 安装公式的选项。
\n\n具体来说
\n\nbrew install gnuplot --with-qt
结果是 a invalid option: --with-qt
,当我查看时brew info gnuplot
没有可用的选项:
$ brew info gnuplot\ngnuplot: stable 5.2.6 (bottled), HEAD\nCommand-driven, interactive function plotting\nhttp://www.gnuplot.info/\nNot installed\nFrom: https://github.com/Homebrew/homebrew-core/blob/master/Formula/gnuplot.rb\n==> Dependencies\nBuild: pkg-config \xe2\x9c\x94\nRequired: gd \xe2\x9c\x94, libcerf \xe2\x9c\x94, lua \xe2\x9c\x94, pango \xe2\x9c\x94, qt \xe2\x9c\x94, readline \xe2\x9c\x94\n==> Options\n--HEAD\n Install HEAD version\n
Run Code Online (Sandbox Code Playgroud)\n\n然而,我从文档和数千名 Andrew Ng 机器学习课程的学生中得到了所有指示,即我可以指定一些可选标志。我已经尝试了各种更新和升级,但brew doctor
似乎没有什么相关的。我过去用brew安装了很多东西(尽管最终我不太确定内部工作原理)
$ brew --version\nHomebrew 2.0.1\nHomebrew/homebrew-core (git revision 1204; last commit 2019-02-09)\nHomebrew/homebrew-cask (git revision 8d29a; last commit …
Run Code Online (Sandbox Code Playgroud) 我在okhttp3 lib中遇到了一些问题.
我在gradle文件依赖项中添加了以下行:
compile 'com.squareup.okhttp3:okhttp:3.4.1'
Run Code Online (Sandbox Code Playgroud)
之后,我尝试创建webSocket连接,如okhttp websocket示例,但在Android Studio中,我没有看到任何类和接口,如
import okhttp3.WebSocket;
import okhttp3.WebSocketListener;
Run Code Online (Sandbox Code Playgroud)
但我知道这些文件存在于okhttp3中.谁能解释我做错了什么?
如果我们在okhttp javadoc中看到我们找不到这些类.但他们在github.
我想识别数字列表中完美正方形的数字,例如:
a = [3, 4, 8, 16, 21, 58, 144] # return [4, 16, 144]
Run Code Online (Sandbox Code Playgroud) 我写了一个函数,它返回一个数字输入是否为正方形
def is_square(n):
if n<1:
return False
else:
for i in range(int(n/2)+1):
if (i*i)==n:
return True
else:
return False
Run Code Online (Sandbox Code Playgroud)
我相信这段代码有效.但是,当我做测试用例时,例如:test.expect( is_square( 4))
,它表示该值不是预期的值.