我搜索了stackoverflow的答案,但我无法得到相关的东西.
我正在尝试通过指定其标记来初始化具有初始值的静态结构实例,但是在编译时遇到错误:
src/version.cpp:10: error: expected primary-expression before ‘.’ token
这是代码:
// h
typedef struct
{
int lots_of_ints;
/* ... lots of other members */
const char *build_date;
const char *build_version;
} infos;
Run Code Online (Sandbox Code Playgroud)
而错误的代码:
// C
static const char *version_date = VERSION_DATE;
static const char *version_rev = VERSION_REVISION;
static const infos s_infos =
{
.build_date = version_date, // why is this wrong? it works in C!
.build_version = version_rev
};
const infos *get_info()
{
return &s_infos;
}
Run Code Online (Sandbox Code Playgroud)
所以基本的想法是绕过"其他成员"的初始化,只设置相关build_date和build_version …
函数dirname()和basename()将以null结尾的路径名字符串分解为目录和文件名组件.在通常情况下,dirname()返回字符串,但不包括最后的'/',basename()返回最后的'/'后面的组件.尾随'/'字符不计入路径名的一部分.
后来,你有这个小桌子:
path dirname basename
"/usr/lib" "/usr" "lib"
"/usr/" "/" "usr" // wat?
"usr" "." "usr"
"/" "/" "/"
"." "." "."
".." "." ".."
Run Code Online (Sandbox Code Playgroud)
为什么要dirname( "/usr/")回来"/"而不是"/usr"?
手册中的句子告诉我,我应该得到/usr结果.
我在虚拟程序中测试了实际结果,它的行为就像手册所说的那样.
#include <libgen.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char const *argv[])
{
const char *mydir="/usr/";
char *dummy = strdup( mydir );
char *dummy2 = strdup( mydir );
char *dname = dirname( dummy );
char …Run Code Online (Sandbox Code Playgroud) 假设我希望我的星期在星期二开始,那天应该从早上5:30开始.
这意味着,像这样的代码应该工作:
// LocalDateTimes created with the "standard" ISO time
LocalDateTime tuesday_4_30 = LocalDateTime.now()
.with(TemporalAdjusters.next(DayOfWeek.TUESDAY))
.withHour(4).withMinute(30);
LocalDateTime tuesday_6_30 = tuesday_4_30.withHour(6).withMinute(30);
LocalDateTime previous_monday = tuesday_4_30.minusDays(1);
// eventual adjustment using TemporalAdjusters here? like this?
// tuesday_4_30 = tuesday_4_30.with(new MyTemporalAdjuster(DayOfWeek.TUESDAY, 5, 30));
// <do the same for 6_30 and previous monday>
// or possibly change some global parameter like Chronology, Locale, or such..
Assert.assertEquals(tuesday_4_30.getDayOfWeek(), DayOfWeek.MONDAY);
Assert.assertEquals(tuesday_6_30.getDayOfWeek(), DayOfWeek.TUESDAY);
// there is 1 week between the previous monday and the next tuesday 6:30
Assert.assertEquals( ChronoUnit.WEEKS.between(previous_monday,tuesday_6_30), …Run Code Online (Sandbox Code Playgroud) 我想显示我的代码中所有 TODO 的列表,但使用历史记录 (Git) 排序并首先显示最近的。
有点像这里显示的结果: git – order commits 按日期引入“TODO”
但是显示的是 TODO 的行,而不是散列。
应该是这样的:
Fri May 22 11:22:27 2015 +0200 - // TODO: Refactor this code
Fri Apr 25 17:32:13 2014 +0200 - // TODO: We should remove this when tests pass
Sat Mar 29 23:11:39 2014 +0100 - // TODO: Rename to FooBar
Run Code Online (Sandbox Code Playgroud)
我认为git log不能证明这一点,但我不确定,而且我没有 Git CLI mojo 来自己解决这个问题。任何的想法?
每当有更新时,即每个月左右,VsCode都会唠叨我.
安装更新有点复杂(去网站,下载Deb,打开终端,sudo dpkg等)所以我希望VsCode不要打扰我这个更新栏.
可能吗?
我找不到允许隐藏此栏的设置..
我正在使用 python 的 picamera 模块捕获游戏中时光倒流:
from picamera import PiCamera, Color
class EggAlertCam:
def __init__(self):
self.camera = PiCamera()
self.camera.start_preview()
def capture_thread_task(self):
filename = os.path.join(self.SAVEPATH, self.safe_camname + '_{timestamp:%Y%m%d-%H%M%S}-{counter:03d}' + '.jpg' )
starttime = dt.datetime.now()
current_time = dt.datetime.now()
for filename in self.camera.capture_continuous(filename):
print('Captured {}'.format(filename))
self.wait(current_time)
current_time = dt.datetime.now()
def get_frame(self, size=None):
if size is None:
size = (640,480)
output = io.BytesIO()
self.camera.capture(output, format='jpeg', resize=size, use_video_port=True)
output.seek(0)
return output
Run Code Online (Sandbox Code Playgroud)
它capture_thread_task在线程中运行,我有一个 Flask 应用程序,允许通过调用get_frame.
我希望video_port=True即使在捕捉延时拍摄时也能获取(更高的噪音,但我不在乎)图像,但我得到了一个例外:
from picamera import PiCamera, Color …Run Code Online (Sandbox Code Playgroud) 我们正在使用旧版本的 Payara,并使用 Prometheus JVM GC 导出器和内存导出器导出 JVM 指标。
在这些导出器中,我们无法访问 Java HeapSpace 异常的数量,这是 XMX 值不足的指标。
我有一个仪表板,可以在其中调查 Java 应用程序的内存状态,下面是“内存匮乏”应用程序的典型示例:

我可以使用 GC 平均持续时间,但我宁愿有一个 Java 堆空间异常数量的“硬事实”计数器,这是内存不足的真正指标。由于我们在 Java 应用程序服务器中运行,因此我们没有 main() 来拦截所有 Java HeapSpace 异常(并且我们无法确定它没有在下面被拦截,因此计数器可能有问题) )。
你们是否也遇到过同样的问题,并找到了衡量这个问题的方法?我探索了 JMX 树,但没有找到决定性的指标。
我想在我的应用程序上公开REST API,使用Mongoose Web服务器并为不同的查询提供处理程序.
查询的一个例子就是这样(我现在只使用GET,其余的HTTP动词将在以后出现):
GET /items -> returns a list of all items in JSON
GET /item/by/handle/123456789 -> returns item that has handle 123456789
GET /item/by/name/My%20Item -> returns item(s) that have the name "My Item"
Run Code Online (Sandbox Code Playgroud)
我很好奇的是我应该如何实现这些查询的解析.我可以很容易地解析第一个,因为它只是一个问题if( query.getURI() == "/items") return ....
但是对于接下来的两个查询,我必须以std::完全不同的方式操纵字符串,使用一些std::string::find()魔法和偏移来获得参数.
作为示例,这是我对第二个查询的实现:
size_t position = std::string::npos;
std::string path = "/item/by/handle/";
if( (position = query.getURI().find(path) ) != std::string::npos )
{
std::string argument = query.getURI().substr( position + path.size() );
// now parse the argument …Run Code Online (Sandbox Code Playgroud) 我对我的 Ansible 库存有这样的想法:我只想拥有一个存储值,即一颗种子,它可以生成我的库存中所需的所有密码。
像这样的东西:
---
# I only have this to generate randomly, and vault
inventory_seed: "a strong random string"
# Then all my other password are derived from this seed.
# I feed the salted seed to a filter that creates a password directly sourced from the string I give him.
# will output, say, `wgSqz$@+SU^nw2;I` everytime I invoke ansible for the same inventory_hostname
machine_root_password: "{{ inventory_hostname + inventory_seed + 'root password' | to_strong_password }}"
# same: …Run Code Online (Sandbox Code Playgroud) 我有这个Makefile,它有一个名为"MODULES"的变量,它列出了我在构建中激活的所有模块.
这个列表用空格分隔,所以当我这样做时它看起来像这样echo $(MODULES):
module1 module2 module3 module4 mod5 mod6 mod7 module8 module9
Run Code Online (Sandbox Code Playgroud)
我想要做的是在编译时显示的某些列中显示此列表.
像这样:
Modules activated:
module1 module2 module3
module4 mod5 mod6
mod7 module8 module9
Run Code Online (Sandbox Code Playgroud)
理想情况下,列withs将调整为列中最大模块的宽度(请参阅参考资料mod7); 并且将根据当前终端的宽度调整列数.
现在,我发现了一些似乎这样做的unix实用程序,比如列,但我不能使它与我的set一起工作.
你有一些技巧可以让我这样做吗?
编辑:
在下面选择的答案中,我终于在我的Makefile中破解了这个命令:
@printf '%s\n' $(MODULES) | sort | column
Run Code Online (Sandbox Code Playgroud)