我正在尝试将这个简单的程序上传到我的 Arduino,以获取时钟时间:
#include <Time.h>
time_t nowTime;
void setup() {
nowTime = now();
}
Run Code Online (Sandbox Code Playgroud)
但是,它无法编译:
exit status 1
'now' was not declared in this scope
Run Code Online (Sandbox Code Playgroud)
为什么now()不在这个范围内声明呢?Time.h 文件已包含在内。那么为什么不now()公开呢?我该如何解决这个问题?
这是我的 docker-compose yaml 文件。
version: '2.1'
services:
myservice:
environment:
- MYENVVAR={"1": "Hello"}
Run Code Online (Sandbox Code Playgroud)
当我运行时,这给了我以下解析错误 docker-compose
ERROR: yaml.parser.ParserError: while parsing a block mapping
in "./my_docker_compose_.yml", line 6, column 9
expected <block end>, but found '}'
in "./my_docker_compose_.yml", line 6, column 111
Run Code Online (Sandbox Code Playgroud)
如何正确转义我的 JSON 对象,以便将其作为环境变量的值发送到容器中MYENVVAR?
我正在使用 GRPC/proto-buffers 在 GoLang 中编写我的第一个 API 端点。我对 GoLang 比较陌生。下面是我为我的测试用例编写的文件
package my_package
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/types/known/structpb"
"github.com/MyTeam/myproject/cmd/eventstream/setup"
v1handler "github.com/MyTeam/myproject/internal/handlers/myproject/v1"
v1interface "github.com/MyTeam/myproject/proto/.gen/go/myteam/myproject/v1"
)
func TestEndpoint(t *testing.T) {
conf := &setup.Config{}
// Initialize our API handlers
myhandler := v1handler.New(&v1handler.Config{})
t.Run("Success", func(t *testing.T) {
res, err := myhandler.Endpoint(context.Background(), &v1interface.EndpointRequest{
Data: &structpb.Struct{},
})
require.Nil(t, err)
// Assert we got what we want.
require.Equal(t, "Ok", res.Text)
})
}
Run Code Online (Sandbox Code Playgroud)
这是EndpointRequest在v1.go上面包含的文件中定义对象的方式:
// An v1 interface Endpoint Request object.
message EndpointRequest {
// …Run Code Online (Sandbox Code Playgroud) 我使用golangci-lint工具使用以下命令对我的 Go 项目进行 linting,如下所示:
> golangci-lint run
Run Code Online (Sandbox Code Playgroud)
该项目中有许多文件。所以有几十个(也许超过 100 个?)linter 错误。但令人烦恼的事情不断发生。它向我显示了大约十几个 linter 错误,然后我去修复它们,然后它向我显示了另外十几个错误,然后我去修复它们,等等,等等,等等。这个循环重复了很多次。
但当我经历这个循环时,我不知道剩余的 linter 错误总数,所以我无法弄清楚我距离完成还有多远。我觉得自己像西西弗斯!
如何让 golangci-lint 列出所有 linter 错误及其总数?
其他语言的编译器和 linter 总是这样做。这太初级了。我不敢相信他们做出了这个糟糕的设计决定。
我有一个表格:
class myForm(forms.Form):
myBoolField = forms.BooleanField(
label='myLabel',
required=True,
)
Run Code Online (Sandbox Code Playgroud)
这是相应的模板:
<form action="." method="post" enctype="application/x-www-form-urlencoded">
{% csrf_token %}
{{ form.as_p }}
<div class="form-actions">
<button type="submit" class="btn btn-primary">Submit</button>
<a class="btn" href="{{ secondary_action_url }}">{{ secondary_action_text }}</a>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
当Django呈现此模板时,myField显示为空复选框.如果我选中该框,则按下提交按钮会为清除的myField值生成"True".但是,如果我将框保持为空并点击提交按钮,而不是获得"假",我将获得无.那根本不是我想要的.我希望此复选框返回True或False.
我该怎么做才能使它像我想要的那样工作(并期待)?我期望必需的布尔字段返回True或False放错位置吗?
我正在使用Django-Registration包让用户创建帐户,验证他们并登录我的webapp.
但是,帐户创建的表单/视图不会要求用户输入名字/姓氏(这些字段是模型BTW的一部分).它只询问他们的电子邮件地址,登录ID和密码(两次).我想要询问用户的名字/姓氏(这些字段可以是可选的......但它仍应该询问).我找不到要修改的表单和视图文件,以便它要求提供此信息.我修改了模板文件.但没有形式和视图修改是没用的.这是怎么做到的?
我创建一个MySQL用户如下:
mysql> grant all privileges on *.* to mysql@'%' IDENTIFIED by 'myPassword' with grant option;
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.02 sec)
mysql> exit;
Bye
Run Code Online (Sandbox Code Playgroud)
然后我尝试使用新创建的用户登录但它不起作用.
% mysql -u mysql -pmyPassword
ERROR 1045 (28000): Access denied for user 'mysql'@'localhost' (using password: YES)
%
Run Code Online (Sandbox Code Playgroud)
为什么?
我有以下代码使用d3.js成功地将我的文本绘制到SVG上:
var myRect = svgContainer.append("text")
.attr("x", 10)
.attr("y", 20)
.text("Lorem Ipsum")
.attr("font-weight", "bold")
.attr("fill", "white");
Run Code Online (Sandbox Code Playgroud)
现在我想获得该文本的边界框.我该怎么做??我尝试了以下方法:
console.log("getBBox = ", myRect.getBBox());
Run Code Online (Sandbox Code Playgroud)
但它给了我这个错误:
Uncaught TypeError: myRect.getBBox is not a function
Run Code Online (Sandbox Code Playgroud) 我有以下 Javascript 字符串代表协调世界时 (UTC) 中的某个时刻:
myUTCString = "2014-11-06 00:00:00";
Run Code Online (Sandbox Code Playgroud)
我想使用 moment.js 将此字符串转换为本地化为访问者浏览器时区的时刻。我该怎么做?
我试过这个:
moment(moment.utc("2014-11-06 00:00:00")).local()
Run Code Online (Sandbox Code Playgroud)
但它给了我这个:
如您所见,该对象不包含_d显示本地化时间字符串值的属性。但这不是我需要的。我需要一个本地时间的实际时刻对象,以便稍后在我的代码中进一步操作/使用它。怎么做到呢?这似乎是非常普遍需要的东西。