小编dig*_*ber的帖子

如何查询节点上的cookbook版本?

使用案例: DevOps团队不久前推出了一个节点,我的团队想知道run_list中使用的一个/几个cookbook的版本是什么.我们的DevOps团队正在进行消防,因此我们希望找到一种自给自足的方法.

命令已尝试: knife cookbook show COOKBOOK提供所有可能的版本,但不指定正在使用的版本.

knife node show NODE 显示所有烹饪书,但没有附加版本信息.

问:是否有一个命令(类似的东西来knife search,ohai)查询厨师服务器部署在节点上的版本?

cookbook chef-infra chef-recipe knife

16
推荐指数
3
解决办法
1万
查看次数

C/C++程序打印自己的源代码作为输出

维基百科称它被称为quine,有人给出了以下代码:

char*s="char*s=%c%s%c;main(){printf(s,34,s,34);}";main(){printf(s,34,s,34);}
Run Code Online (Sandbox Code Playgroud)

但是,显然你必须添加

#include <stdio.h> //corrected from #include <stdlib.h>
Run Code Online (Sandbox Code Playgroud)

这样printf()才有用.

从字面上看,由于上面的程序没有打印#include <stdio.h>,所以它不是解决方案(?)

我对"打印自己的源代码"的字面要求以及此类问题的任何目的感到困惑,尤其是在访谈时.

c quine

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

将旧的zookeeper znode/数据复制/迁移到新的zookeeper

我们有一个旧的 Zookeeper 3 集群仲裁,一些永久路由信息存储在 znodes/data 中。现在,我们正在另一个数据中心上设置另一个全新的 3 集群仲裁,我们希望将路由信息迁移到它。执行此操作的最佳可靠方法是什么?

会简单地复制事务日志吗?还是用快照更好?或者是否有一些工具可以从旧 znode 中提取数据并将创建重播到新 znode 上?

发现了类似的问题,但没有回答跨 2 个 Zookeeper 集群复制数据的最佳方法?

python java apache-kafka apache-zookeeper

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

shared_ptr用于原始指针参数

当函数需要char*时,你能传入一个shared_ptr吗?

我正在读取整个文本文件(长度= 100),并希望将char存储到char []数组中.我使用的天真的方式是这样的:

ifstream dictFile(fileName);
size_t fileLength = 100;
char* readInBuffer(new char[fileLength]);
dictFile.read(readInBuffer, fileLength);
//processing readInBuffuer..............
delete[] readInBuffer;
dictFile.close();
Run Code Online (Sandbox Code Playgroud)

如果在delete []语句之前抛出异常,则会发生内存泄漏.我想知道我是否可以使用shared_ptr readInBuffer(new char [fileLength]); 但功能原型

读(char*s,streamsize n)

不会接受智能指针作为输入?任何招数?

编辑:我正在尝试写这样的东西:

shared_ptr<char[]> readInBuffer(new char[fileLength]);
dictFile.read(readInBuffer.get(), fileLength);
Run Code Online (Sandbox Code Playgroud)

但它不会编译.

c++ pointers function smart-pointers

4
推荐指数
2
解决办法
6092
查看次数

使用bash脚本将max comma放在一行上

我有一些\n结束的文字:

她走在美丽的地方,就像
无云的夜晚,满天星斗的天空,
以及所有最好的,黑暗和明亮的
相遇,在她的方面和她的眼睛相遇

我想找到哪一行有最大数量,并打印该行.例如,上面的文本应该是

她像美女一样走在美丽的夜晚

因为它有2个(所有行中最大)逗号.

我试过了:

cat p.txt | grep ','
Run Code Online (Sandbox Code Playgroud)

但不知道现在去哪里.

unix linux bash grep

3
推荐指数
1
解决办法
238
查看次数

shared_ptr初始化

成员定义为

std::shared_ptr<std::array<std::string, 6> > exit_to;
Run Code Online (Sandbox Code Playgroud)

这表示其他人共享的其他数据.当尝试启动指针"exit_to"时.正确的方法是

node_knot.exit_to = std::make_shared<std::array<std::string, 6> >();
Run Code Online (Sandbox Code Playgroud)

但它在另一个文件中,我想保持指针类型一致,如下所示:

node_knot.exit_to = std::make_shared<decltype(*node_knot.exit_to)>();
Run Code Online (Sandbox Code Playgroud)

但是不会编译:

 /usr/include/c++/4.6/bits/shared_ptr_base.h:798:54: error: '__p'
 declared as a pointer to a reference of type
 'std::array<std::basic_string<char>, 6> &'
         __shared_ptr(const __shared_ptr<_Tp1, _Lp>& __r, _Tp* __p)
                                                             ^ /usr/include/c++/4.6/bits/shared_ptr.h:93:31: note: in instantiation
 of template class
 'std::__shared_ptr<std::array<std::basic_string<char>, 6> &, 1>'
 requested here
     class shared_ptr : public __shared_ptr<_Tp>
                               ^ ../node_booker.h:757:20: note: in
 instantiation of template class
 'std::shared_ptr<std::array<std::basic_string<char>, 6> &>' requested
 here
                                                         n.exit_to = std::make_shared<decltype(*n.exit_to)>();
Run Code Online (Sandbox Code Playgroud)

我在Ubuntu 12.10下,clang ++ 3.2,--std = c ++ 11

c++ shared-ptr decltype

3
推荐指数
1
解决办法
1254
查看次数

iphone键盘unicode映射

我正在研究一些iphone应用程序的国际化,我想直接知道iphone内置键盘可能的输入代码点,这应该是整个unicode平面的一个较小的子集.

这些键盘列在设置 - >国际 - >键盘中.大约有70种不同的键盘.Apple有一些官方文件吗?我用Google搜索,但没有找到太多有用的东西.

iphone keyboard unicode ios

3
推荐指数
1
解决办法
778
查看次数

指向函数或函子的指针?函数发生器

我正在尝试构建一个多项式函数生成器,因此它将一个向量(任意大小)作为参数,并生成一个我稍后可以使用的多项式函数.

例如,

poly_gen(vector<int> power_index)
Run Code Online (Sandbox Code Playgroud)

以(我可以用另一个函数调用)的形式返回一个函数(或通过其他方法)

y(k)=a0+ a1*n+ a2*n^2 + a3*n^3 + ... + ak*n^k
Run Code Online (Sandbox Code Playgroud)

其中a0,a1 .... ak存储在vector-power_index中

后来我可以用它来调用它

int calc_poly(int n)
Run Code Online (Sandbox Code Playgroud)

calc_poly可以返回一个数字,通过使用由生成的多项式表达式计算poly_gen()

PS:我不知道如何通过关键词搜索这个问题.功能,构造,发电机,指针,仿函数...没有给我想要的结果.

谢谢你们!

c++ expression class function functor

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

为什么我会看到某些网页的源代码(html)?

大多数网页通常都会被解析,当然我看不到像<html>或的标签<a href=>.

但是,当我打开一些网站时,会弹出源代码.

试试这个

http://mediacomp-jes.googlecode.com/svn-history/r68/jes/JESHelp/auxHelp/mediaToolsOverview.html

所以我保存了这个网页并使用firefox在本地重新打开,一切看起来都很正常了.

任何原因?

html firefox

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

来自perl的奇怪`pwd`输出

我有一个非常简短的perl脚本教程:

#!/usr/bin/perl
print "The date is ",`date`;
print "The date is `date`",".\n";
$directory=`pwd`;
print "\nThe current directory is $directory.";
Run Code Online (Sandbox Code Playgroud)

和输出:

The date is Sat Jul  2 17:04:58 PDT 2011
The date is `date`.

The current directory is total 20
-rwxr-xr-x 1 yan yan 433 2011-07-02 15:58 36
-rwxr-xr-x 1 yan yan 313 2011-07-02 16:29 43
-rwxr-xr-x 1 yan yan 116 2011-07-02 16:51 45
-rwxr-xr-x 1 yan yan 149 2011-07-02 16:53 46
-rwxr-xr-x 1 yan yan 145 2011-07-02 17:02 47
Run Code Online (Sandbox Code Playgroud)

但如果我只是运行pwd我得到: …

unix linux ubuntu perl pwd

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