我正在寻找一种方法来获取成员变量的偏移量,以静态地将此偏移量传递给成员变量.基本上我想实现这个:
template <std::intptr_t OFFSET>
struct A
{
std::intptr_t self()
{
return reinterpret_cast<std::intptr_t>(this) - OFFSET;
}
};
struct B
{
int some_variables[256];
A<???> a;
};
int main()
{
B b;
assert(reinterpret_cast<std::intptr_t>(&b) == b.a.self()); // shall pass
return 0;
}
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点?
我有一个函数,将不同长度的元组作为参数:
from typing import Tuple
def process_tuple(t: Tuple[str]):
# Do nasty tuple stuff
process_tuple(("a",))
process_tuple(("a", "b"))
process_tuple(("a", "b", "c"))
Run Code Online (Sandbox Code Playgroud)
当我注释上述函数时,出现这些错误消息
fool.py:9: error: Argument 1 to "process_tuple" has incompatible type "Tuple[str, str]"; expected "Tuple[str]"
fool.py:10: error: Argument 1 to "process_tuple" has incompatible type "Tuple[str, str, str]"; expected "Tuple[str]"
Run Code Online (Sandbox Code Playgroud)
process_tuple真正适用于元组,我将它们用作可变长度的不可变列表。我尚未在互联网上找到关于此主题的任何共识,因此我想知道该如何注释这种输入。
我正在尝试Blazor在由js. Js使用互操作在事件上调用 C# 代码,我需要以某种方式调用this.StateHasChangedc# 回调:
JS
window.methods = {
timeout: null,
setTimeout: function () {
timeout = window.setInterval(async function () {
console.log("From js timeout occured ,sending to .net");
await DotNet.invokeMethodAsync('[assembly name]', "TimeoutCallback", Date.now().toString());
}, 2000);
},
clearTimeout: function () {
if (this.timeout == null || this.timeout == undefined) {
return;
}
console.log("Clearing timeout");
window.clearTimeout(timeout);
}
}
Run Code Online (Sandbox Code Playgroud)
C#
@inherits StuffBase
@page "/test"
Current value: @val
<button onclick="@(async()=>await StartTimeout())">Start timeout </button>
<button onclick="@(async()=>await ClearTimeout())">Clear timeout</button> …Run Code Online (Sandbox Code Playgroud) 当我使用 BEM 时,我对简单的场景感到困惑。示例中有一个基本按钮:
.button {
// styles for button
}
Run Code Online (Sandbox Code Playgroud)
及其具有更具体样式的修饰符:
.button.button_run {
// additional styles for this type of button
// i.e. custom width and height
}
Run Code Online (Sandbox Code Playgroud)
有一刻我意识到我需要 的修饰符button_run,让我们将其命名为button_run_pressed:
.button_run_pressed {
// more styles, i.e. darker background color
}
Run Code Online (Sandbox Code Playgroud)
button_run_pressed问题是,按照 BEM 约定来命名最后一个元素是不正确的。但我需要仅向“运行”按钮添加“按下”样式,而不是通过编写类button_pressed和混合修饰符来为所有按钮添加“按下”样式button button_run button_pressed。
我应该如何重构我的代码以匹配 BEM 约定?
我freeMemory在https://playground.arduino.cc/Code/AvailableMemory看到了这个函数,它似乎使用了一个叫做__brkval. 但是,我根本找不到这个宏或变量的定义位置:
$ grep -ri brkval /c/arduino-1.8.8/ --include='*.c' --include='*.h'
/c/arduino-1.8.8/libraries/Robot_Control/src/Fat16util.h: extern int* __brkval;
/c/arduino-1.8.8/libraries/Robot_Control/src/Fat16util.h: if (reinterpret_cast<int>(__brkval) == 0) {
/c/arduino-1.8.8/libraries/Robot_Control/src/Fat16util.h: - reinterpret_cast<int>(__brkval);
/c/arduino-1.8.8/libraries/SD/src/utility/SdFatUtil.h: extern int* __brkval;
/c/arduino-1.8.8/libraries/SD/src/utility/SdFatUtil.h: if (reinterpret_cast<int>(__brkval) == 0) {
/c/arduino-1.8.8/libraries/SD/src/utility/SdFatUtil.h: - reinterpret_cast<int>(__brkval);
$ grep -ri brkval /c/avr-gcc-8.2.0-x64-mingw/ --include='*.c' --include='*.h'
# nothing
$ grep -ri brkval /c/Program\ Files\ \(x86\)/Atmel/Studio/ --include='*.c' --include='*.h'
# nothing
$ grep -ri brkval /c/cvavr/ --include='*.c'
# nothing
Run Code Online (Sandbox Code Playgroud)
也就是说,只有 Arduino IDE 对它有一些引用,但仅作为extern int*参考,它没有定义。
我最接近某种详细解释的是https://github.com/greiman/SdFat/blob/master/src/FreeStack.h:
/** …Run Code Online (Sandbox Code Playgroud) 我有一个 base64 编码的 zip 文件。我能够转换该 zip 文件,然后使用 Windows 命令行提取其内容。我一直在尝试用 Python 做同样的事情,但没有成功。请你帮助我好吗?当我运行以下代码时:
import base64
import codecs
import zlib
import io, zipfile, json, pprint
d = open("data.txt", "rb").read()
#dd = base64.decodestring(d)
#print(dd)
z = zipfile.ZipFile(io.BytesIO(d))
unpack = zlib.decompress(d)
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
raise BadZipFile("文件不是 zip 文件") zipfile.BadZipFile:文件不是 zip 文件
data.txt 文件包含 base64 字符串:

我有 python 3.4。
我发送了一个 2MHz(例如)频率并随着时间的推移接收到空化(直到我停止测量)。我想得到一个频谱图(空化与频率),更有趣的是在次谐波 (1MHz) 频率时间内的空化频谱图。
数据保存在sdataA(=空化)和t(=测量时间)
我试图在 FFTA 中保存 fft
FFTA = np.array([])
FFTA = np.fft.fft(dataA)
FFTA = np.append(FFTA, dataA)
Run Code Online (Sandbox Code Playgroud)
我得到了实数和复数然后我只取了一半(从 0 到 1MHz)并保存了实数和复数数据。
nA = int(len(FFTA)/2)
yAre = FFTA[range(nA)].real
yAim = FFTA[range(nA)].imag
Run Code Online (Sandbox Code Playgroud)
我试图通过以下方式获取频率:
FFTAfreqs = np.fft.fftfreq(len(yAre))
Run Code Online (Sandbox Code Playgroud)
但这是完全错误的(我打印了数据print (FFTAfreqs))
我还绘制了数据,但它又是错误的:
plt.plot(t, FFTA[range(n)].real, 'b-', t, FFTA[range(n)].imag, 'r--')
plt.legend(('real', 'imaginary'))
plt.show()
Run Code Online (Sandbox Code Playgroud)
如何在次谐波 (1MHz) 频率范围内输出空化频谱图?
编辑:
数据示例:
查看“dataA”和“time”的示例:
dataA = [6.08E-04,2.78E-04,3.64E-04,3.64E-04,4.37E-04,4.09E-04,4.49E-04,4.09E-04,3.52E-04,3.24E-04,3.92E-04,3.24E-04,2.67E-04,3.24E-04,2.95E-04,2.95E-04,4.94E-04,4.09E-04,3.64E-04,3.07E-04]
time = [0.00E+00,4.96E-07,9.92E-07,1.49E-06,1.98E-06,2.48E-06,2.98E-06,3.47E-06,3.97E-06,4.46E-06,4.96E-06,5.46E-06,5.95E-06,6.45E-06,6.94E-06,7.44E-06,7.94E-06,8.43E-06,8.93E-06,9.42E-06]
Run Code Online (Sandbox Code Playgroud)
编辑二: 从@Martin 示例中,我尝试了以下代码,如果我做得对,请告诉我。
如果 dataA 和 Time 保存为 h5 文件(或我已经发布的数据)
import numpy as np
import …Run Code Online (Sandbox Code Playgroud) 是否有一种优雅的方式将其转换Map<P, Optional<Q>>为稀疏Map<P, Q>?
这应该工作,但它有点meh:
Map<P,Optional<Q>> map = ...;
Map<P,Q> map2 = map.entrySet()
.stream().filter(e -> e.getValue().isPresent())
.collect(Collectors.toMap(e -> e.getKey(), e->e.getValue().get()));
Run Code Online (Sandbox Code Playgroud) 我试图glReadPixels通过以下代码提取图像数据:
std::array<unsigned char, 3 * height * width> data;
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, data.data());
Run Code Online (Sandbox Code Playgroud)
当宽度是4的倍数(高度似乎是任意的)时,图像是完美的.但是,当它不是时,我得到运行时错误:
*** stack smashing detected ***: <unknown> terminated
Run Code Online (Sandbox Code Playgroud)
因此,例如,以下(宽度,高度)对可以正常工作:
(20,20),(20,21),(20,22),(20,23),(20,24)
(24,20),(24,21),(24,22),(24,23),(24,24)
Run Code Online (Sandbox Code Playgroud)
以下产生"堆栈粉碎"错误:
(21,20),(22,20),(23,20)
Run Code Online (Sandbox Code Playgroud)
我猜想有一些填充,但我在OpenGL网站上没有看到任何提及:
https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glReadPixels.xml
有人可以请一些文件说明我应该分配多少空间,以及填充是什么样的?
我们可以使用动态属性将包含 JaaS 配置路径的 java.security.auth.login.config 传递给 ConsumerKafka 处理器,而不在 bootstrap.conf 中进行设置吗?
是否可以?
c++ ×2
python ×2
apache-nifi ×1
avr ×1
base64 ×1
bem ×1
blazor ×1
c ×1
css ×1
fft ×1
interop ×1
java ×1
java-8 ×1
java-stream ×1
javascript ×1
less ×1
mypy ×1
opengl ×1
pkzip ×1
python-3.x ×1
templates ×1
type-hinting ×1
zip ×1