我正在尝试安装pg-native
包:
sudo npm install pg-native
Run Code Online (Sandbox Code Playgroud)
但会生成以下错误:
> libpq@1.7.0 install /Workspace/auth/node_modules/libpq
> node-gyp rebuild
/bin/sh: pg_config: command not found
gyp: Call to 'pg_config --libdir' returned exit status 127. while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:355:16)
gyp ERR! stack at emitTwo (events.js:87:13)
gyp ERR! stack at ChildProcess.emit (events.js:172:7)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
gyp ERR! System Darwin 15.0.0
gyp ERR! command …
Run Code Online (Sandbox Code Playgroud) 我希望能够在Ruby中流式传输子进程的输出
例如
p `ping google.com`
Run Code Online (Sandbox Code Playgroud)
我想立即看到ping响应; 我不想等待这个过程完成.
我仍在努力学习 Golang 的基础知识。
考虑以下示例代码:
func OpenOutputFile(name string) (fp *os.File) {
fp, err := os.Create(name)
if err != nil {
panic(err)
}
defer func() {
if err := fp.Close(); err != nil {
panic(err)
}
}()
return fp
}
Run Code Online (Sandbox Code Playgroud)
我会假设调用:
fp := OpenOutputFile("output.txt")
Run Code Online (Sandbox Code Playgroud)
现在将创建fp
一个文件指针 ( *os.File
),以便我可以调用如下语句:
io.WriteString(fp, "Hello World")
Run Code Online (Sandbox Code Playgroud)
在另一个函数中。但是调用这个方法的时候,报错:
0 write output.txt: bad file descriptor
Run Code Online (Sandbox Code Playgroud)
所以看起来返回的指针无效。我怎样才能返回一个正确形成的指针来使用io.WriteString
?
我感谢您的帮助!
注意:当文件指针的创建和文件指针的写入存在于同一方法中时,一切都会按预期执行。将逻辑分解为函数会导致其行为不符合预期。
我一直非常密切地关注这篇关于 D3 线转换的帖子,实现了与此类似的东西,除了按时间进行轴转换。
最终目标是显示实时数据点。
我已经定义了轴,如下所示:
var x = d3.time.scale()
.domain([now - (n - 2) * duration, now - duration])
.range([0, width]);
var y = d3.scale.linear()
.range([height, 0])
.domain([0, 100])
var axisx = svg.append('g')
.attr('class', 'x axis')
.attr('transform', `translate(0, ${height})`)
.call(x.axis = d3.svg.axis().scale(x).orient('bottom').tickPadding(10));
var axisy = svg.append('g')
.attr('class', 'y axis')
.attr('transform', `translate(${width}, 0)`)
.call(y.axis = d3.svg.axis().scale(y).orient('right').tickPadding(10));
Run Code Online (Sandbox Code Playgroud)
和这样的行:
var line = d3.svg.line()
.interpolate('basis')
.x(function(d, i) { return x(now - (n - 1 - i) * duration); …
Run Code Online (Sandbox Code Playgroud) 我正在尝试为可能的数据库类型编写一个自定义封送拆收器nil
。它的结构与类型完全相同sql.NullFloat64
:
type NullFloat64 sql.NullFloat64
func (ni *NullFloat64) MarshalJSON() ([]byte, error) {
if !ni.Valid {
return []byte("null"), nil
}
return json.Marshal(ni.Float64)
}
Run Code Online (Sandbox Code Playgroud)
struct
这是需要整理的较大部分的一部分:
type Data struct {
X time.Time `json:"x"`
Y float32 `json:"y"`
Stderr NullFloat64 `json:"stderr"`
}
Run Code Online (Sandbox Code Playgroud)
如果我尝试json.Marshal()
这样做struct
,它会正常工作,创建:
{"x":"2017-01-12T23:36:12-05:00","y":4,"stderr":null}
Run Code Online (Sandbox Code Playgroud)
如果值为 ,我想完全省略 JSON 键null
。我添加json:"stderr,omitempty"
到Data
.
根据此处的建议,我尝试仅返回一个nil
值MarshalJSON
,但得到:
json: error calling MarshalJSON for type common.NullFloat64: unexpected end of JSON input
Run Code Online (Sandbox Code Playgroud)
我也尝试更新Data
为:
type Data …
Run Code Online (Sandbox Code Playgroud) 我有以下内容struct
:
type Relation struct {
Metric *Metric `gorm:"foreignkey:MetricID"`
MetricID uint
...
}
Run Code Online (Sandbox Code Playgroud)
Metric
定义为:
type DatabaseMeta struct {
Id uint `json:"-" gorm:"primary_key"`
}
type Metric struct {
DatabaseMeta
Name string `json:"name"`
Medium string `json:"medium"`
}
Run Code Online (Sandbox Code Playgroud)
我想Relation
从使用 GORM 中设置的值中找到 a Metric
,它具有 FK 关联。
我试过:
var relation common.Relation
database.Preload("Relation.Metric").Where(&Relation{
Metric: &Metric{
Name: "temperature",
Medium: "water",
},
}).First(&relation)
Run Code Online (Sandbox Code Playgroud)
尽管尝试了和参数Preload
的组合,以下 SQL 实际上是由 GORM 生成的:Association
Preload
[2018-05-06 18:47:37] sql: converting argument $1 type: unsupported type common.Metric, a …
Run Code Online (Sandbox Code Playgroud) 我有两个属性,其中包含列表.每当此列表中的任何项目发生更改时,我希望其他列表自行更新.这包括声明obj.myProp[3]=5
.现在,这个语句调用getter函数获取整个列表,从列表中获取第三个项目,并将其设置为5. myProp
列表已更改,但第二个列表永远不会更新.
class Grid(object):
def __init__(self,width=0,height=0):
# Make self._rows a multi dimensional array
# with it's size width * height
self._rows=[[None] * height for i in xrange(width)]
# Make `self._columns` a multi dimensional array
# with it's size height * width
self._columns=[[None] * width for i in xrange(height)]
@property
def rows(self):
# Getting the rows of the array
return self._rows
@rows.setter
def rows(self, value):
# When the rows are changed, the columns are updated
self._rows=value
self._columns=self._flip(value)
@property …
Run Code Online (Sandbox Code Playgroud) 我有一个变量,我希望在Chef ERB模板中输出时跨越两行.
所以,如果node['apples']
等于"Cortland, \nRed Delicious, \nGolden Delicious, \nEmpire, \nFuji, \nGala"
我希望它显示为:
Cortland,
Red Delicious,
Golden Delicious,
Empire,
Fuji,
Gala
Run Code Online (Sandbox Code Playgroud)
我打电话的时候:
<%= node['apples'] %>
Run Code Online (Sandbox Code Playgroud)
在我的模板中.换行符\n
似乎不起作用.这种行为是如何实现的?
谢谢!
我有cloud-init.log
日志发送到 CloudWatch,我想创建一个指标过滤器来提取 Cloud Init 运行所需的报告时间。
示例日志条目如下所示:
Jun 24 12:06:51 ip-x-x-x-x [CLOUDINIT] util.py[DEBUG]: cloud-init mode 'modules' took 295.097 seconds (294.83)
Run Code Online (Sandbox Code Playgroud)
我想提取的价值是: 295.097
这看起来很简单,因为它took [number] seconds
是这条线独有的。本指标过滤器语法指南似乎只显示了从 JSON 日志中提取值的示例,而此官方示例列表并未涵盖它。
根据文档,我想出了类似的东西:
[..., "took", seconds]
Run Code Online (Sandbox Code Playgroud)
会工作,但我没有太多运气。
任何帮助将非常感激!
我有以下 Python 脚本example.py
:
import redis
r = redis.Redis()
r.set('a','b')
Run Code Online (Sandbox Code Playgroud)
以及以下内容Dockerfile
:
FROM ubuntu:18.04
# Install system-wide dependencies
RUN apt-get -yqq update
RUN apt-get -yqq install python3-dev python3-pip
RUN apt-get -yqq install redis-tools redis-server
RUN pip3 install redis
# Copy application code
ADD . /usr/local/example
WORKDIR /usr/local/example
# Start application
CMD /etc/init.d/redis-server restart \
&& python3 example.py
Run Code Online (Sandbox Code Playgroud)
在我构建容器 ( docker build -t redis-example .
) 并运行它 ( docker run -P -it -d redis-example
) 后,将打印以下堆栈跟踪:
Stopping redis-server: redis-server. …
Run Code Online (Sandbox Code Playgroud)