我正在尝试使用Jsoup解析html文档以获取所有标题标记.另外我需要将标题标签分组为[h1] [h2]等...
hh = doc.select("h[0-6]");
Run Code Online (Sandbox Code Playgroud)
但这给了我一个空阵列.
我正在编写一个应用程序,它从输入文件(任何编解码器,任何容器)解码单个视频流,进行一堆图像处理,并将结果编码为输出文件(单个视频流,Quicktime RLE,MOV).我正在使用ffmpeg的libav 3.1.5(目前是Windows版本,但应用程序将是跨平台的).
输入帧和输出帧之间存在1:1的对应关系,我希望输出中的帧时序与输入相同.我真的很难完成这件事.所以我的一般问题是:我如何可靠地(在所有输入情况下)将输出帧时序设置为与输入相同?
我花了很长时间来讨论API并且达到了我现在的目的.我整理了一个最小的测试程序来处理:
#include <cstdio>
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/avutil.h>
#include <libavutil/imgutils.h>
#include <libswscale/swscale.h>
}
using namespace std;
struct DecoderStuff {
AVFormatContext *formatx;
int nstream;
AVCodec *codec;
AVStream *stream;
AVCodecContext *codecx;
AVFrame *rawframe;
AVFrame *rgbframe;
SwsContext *swsx;
};
struct EncoderStuff {
AVFormatContext *formatx;
AVCodec *codec;
AVStream *stream;
AVCodecContext *codecx;
};
template <typename T>
static void dump_timebase (const char *what, const T *o) {
if (o)
printf("%s timebase: %d/%d\n", what, o->time_base.num, o->time_base.den); …Run Code Online (Sandbox Code Playgroud) 在撰写另一个答案时调查堆栈跟踪差异时,我遇到了一个我不理解的行为.考虑以下测试程序(这是我可以缩小它的范围):
interface TestInterface <U> {
void test (U u);
}
static class Test <T extends Test<T>> implements TestInterface<T> { // line 11
@Override public void test (T t) {
throw new RuntimeException("My exception"); // line 13
}
}
static class TestA extends Test<TestA> { }
static class TestB extends Test<TestB> { }
public static void main (String[] args) throws Exception {
try {
Test a = new TestA();
Test b = new TestB();
a.test(b);
} catch (Exception x) …Run Code Online (Sandbox Code Playgroud) 我在C#,VS2012,WPF 4.5中有以下代码.我的期望是,.ContinueWith将在任务完成后执行(这是一个延续的完整目的,不是吗?).
这应该导致值为2英寸finalResult.
int myTestInt = 0;
Task task = Task.Factory.StartNew(async () =>
{
myTestInt = 1;
await Task.Delay(TimeSpan.FromSeconds(6));
myTestInt = 2;
}).ContinueWith(_ =>
{
int finalResult = myTestInt;
});
Run Code Online (Sandbox Code Playgroud)
实际上,finalResult被赋值为1.所以似乎await已经在声明中开始了延续.
这是预期的行为吗?我在这里错过了什么吗?ContinueWith任务完成后我不能依靠启动吗?
更新:
Justin的回答激发了我检查以下内容:
int myTestInt = 0;
Task task=Task.Factory.StartNew(async () =>
{
myTestInt = 1;
await Task.Delay(TimeSpan.FromSeconds(6));
myTestInt = 2;
});
task.Wait();
int result2 = myTestInt;
Run Code Online (Sandbox Code Playgroud)
finalResult仍设置为1.是否无法可靠地等待包含awaits 的任务完成?
在审查考试时,我注意到我写了一个逻辑错误,我认为这是因为复合赋值+ =因为Increment ++按预期执行,但只有在将foo的值赋给foo +1时才会发生
foo += foo + 1;
Run Code Online (Sandbox Code Playgroud)
这是代码.
//Break Statement
Boolean exit = false;
int foo = 1, bar = 60;
while (!exit) {
foo+=foo+1; //Bad Code
//foo++; //Good Code
//foo=foo+1; // Good Code
//foo+=1; // Good Code
//System.out.println(foo); //Results in -1 (Infinite Loop)
if (foo == bar) {
break;
}
System.out.println("stuff");
}
Run Code Online (Sandbox Code Playgroud)
我的问题是为什么foo + = foo + 1导致-1?
请注意:我是Stackoverflow的新手,无法对你的答案进行投票,所以知道我感谢任何帮助,并提前感谢你!
这是我得到的例外
System.ArgumentException was unhandled
HResult=-2147024809
Message=Parameter is not valid.
Source=System.Drawing
StackTrace:
at System.Drawing.Graphics.CheckErrorStatus(Int32 status)
at System.Drawing.Graphics.FillRectangle(Brush brush, Int32 x, Int32 y, Int32 width, Int32 height)
at System.Drawing.Graphics.FillRectangle(Brush brush, Rectangle rect)
at frmMain.drawCboxItem(Object sender, DrawItemEventArgs e) in frmMain.cs:line 465
at frmMain.cboxSectionCell_DrawItem(Object sender, DrawItemEventArgs e) in frmMain.cs:line 485
at System.Windows.Forms.ComboBox.OnDrawItem(DrawItemEventArgs e)
at System.Windows.Forms.ComboBox.WmReflectDrawItem(Message& m)
at System.Windows.Forms.ComboBox.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at …Run Code Online (Sandbox Code Playgroud) 我正在寻找一个明确的规范描述ioctl 0x1268(BLKSSZGET)的预期参数和行为.
这个数字在许多地方声明(其中没有一个包含确定的参考源),例如linux/fs.h,但我找不到它的规范.
当然,过去某些人确定0x1268会获得设备的物理扇区大小并记录在某处.这些信息来自哪里,我在哪里可以找到它?
编辑:我不是在问BLKSSZGET一般做什么,也不是在问它定义了什么标题.我正在寻找一个明确的,标准化的来源,说明它应该采用什么参数类型以及它应该对任何驱动程序的行为实现它.
具体来说,我问,因为在util-linux 2.23(和2.24)中似乎存在一个错误,blkdiscard其中扇区大小被查询到a uint64_t,但是高32位是未触及的,因为BLKSSZGET 似乎期望一个32位整数,这会导致不正确的扇区大小,不正确的对齐计算以及blkdiscard何时应该成功的失败.所以在我提交补丁之前,我需要绝对确定地确定问题是blkdiscard应该使用32位整数,还是我的内核中的驱动程序实现应该使用64位整数.
编辑2:由于我们是关于这个主题的,所以建议的补丁假定blkdiscard不正确的是:
--- sys-utils/blkdiscard.c-2.23 2013-11-01 18:28:19.270004947 -0400
+++ sys-utils/blkdiscard.c 2013-11-01 18:29:07.334002382 -0400
@@ -71,7 +71,8 @@
{
char *path;
int c, fd, verbose = 0, secure = 0;
- uint64_t end, blksize, secsize, range[2];
+ uint64_t end, blksize, range[2];
+ uint32_t secsize;
struct stat sb;
static const struct option longopts[] = {
@@ -146,8 +147,8 @@ …Run Code Online (Sandbox Code Playgroud) G ++接受此代码,它的行为与我期望的一样:
#include <cassert>
void example (int value, bool condition) {
switch (value) {
case 0:
if (condition) {
case 1:
assert(condition || value == 1);
} else {
assert(!condition && value == 0);
}
assert(value == 0 || value == 1);
}
}
int main () {
example(0, false);
example(1, false);
example(0, true);
example(1, true);
}
Run Code Online (Sandbox Code Playgroud)
也许这是一个愚蠢的基本问题,但代码嗅到一边,将case标签放在一个if...else块中是否是有效的C++ ,并且所有表现良好的编译器是否正确生成将else在输入时跳过块的代码case 1?
为了测试某个功能, cppreference 提到了这些功能测试宏: link。
如果编译器中存在该功能,则定义宏。但我不明白为什么,如果定义了,它们会被定义为类似的东西201606,我相信这是C++ 的版本,而不是编译器的版本。
例如,我正在使用 GCC 的最新版本来实现-std=c++17该功能__cpp_lib_hardware_interference_size。该宏未定义,我认为这意味着 GCC 没有该功能,尽管尝试使用 c++17(和 c++2a)开关 8.2.1。在这种情况下,记录值的意义是什么:
__cpp_lib_hardware_interference_size 201703
(在 cppreference 链接内)?
我正在构建一个站点,一个特定的操作会触发一个长的服务器端进程来运行.此操作不能同时运行两次,因此我需要实现某种保护.它也不能同步,因为服务器在运行时需要继续响应其他请求.
为此,我构建了这个小概念测试,sleep 5用来替代我实际的长期运行过程(需要快速和子进程承诺,在带有sleep命令的系统上运行,但替代Windows的任何内容):
var site = require("express")();
var exec = require("child-process-promise").exec;
var busy = false;
site.get("/test", function (req, res) {
if (busy) {
res.json({status:"busy"});
} else {
busy = true; // <-- set busy before we start
exec("sleep 5").then(function () {
res.json({status:"ok"});
}).catch(function (err) {
res.json({status:err.message});
}).then(function () {
busy = false; // <-- finally: clear busy
});
}
});
site.listen(8082);
Run Code Online (Sandbox Code Playgroud)
这样做的目的是当请求"/ test"时它触发一个长操作,如果在它运行时再次请求"/ test",它会回复"忙"并且什么都不做.
我的问题是,这种实施安全和正确吗?它似乎在我的粗略测试中起作用,但它很可疑.这是基本上实现互斥+ +"try-lock"操作的正确方法,还是有一些更合适的Node.js构造?从习惯于标准多线程实践的语言开始,我对Node的单线程但异步性质不太满意.