小编use*_*250的帖子

在github/gitlab wiki中嵌入PDF

我正在使用gitlab来管理我的存储库,到目前为止这个存储库非常令人满意.然而,维基可以使用相当数量的改进IMO.

当您已经拥有只想添加到Wiki的文档时,这真的很烦人.将表格或pdf翻译成gitlab风格的降价可能是耗时且非平凡的.

我的问题是双重的.

  1. 有没有人幸运地将文件(特别是pdf)嵌入到他们的github/gitlab wiki中?这绝对可以在gitlab上实现,但这是一个简单的方法吗?我有一个文档仓库设置,嵌入从文档仓库链接的文件将是非常棒的.

  2. 如果没有将文件嵌入页面中.你如何有效地将文档翻译成gitlab风格的降价?

pdf github pdf-viewer gitlab

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

如何使Python3成为Geany中的默认Python

我一直在尝试修改Geany中的默认Python编译器/运行命令.

有些搜索表明我需要修改`/usr/share/geany/filetypes.python的最后两行如下

#compiler=python -m py_compile "%f"
#run_cmd=python "%f"
compiler=python3 -c "import py_compile; py_compile.compile('%f')"
run_cmd=python3 "%f"
Run Code Online (Sandbox Code Playgroud)

然而,在重新启动Geany之后,Build -> Set Build Commands仍然会显示旧命令并尝试运行py3脚本会导致错误.

python geany python-3.x

14
推荐指数
2
解决办法
2万
查看次数

使用8位无符号整数变量作为计数器循环超过256个值

所以我只是想用连续数字0-255来填充缓冲区.我对此并没有多想,最终陷入无限循环.

uint8_t i;
uint8_t txbuf[256];

for (i=0; i<256; i++) {
    txbuf[i] = i;
}
Run Code Online (Sandbox Code Playgroud)

问题是i永远不会是256,因为它在255之后翻了个零.

我的问题是,有没有办法在没有碰到i16位值的情况下执行此循环?

注意:我知道我可以将循环更改i<255为最后一个位置添加另一行,但我试图找出一个更好看的方式.

c loops

5
推荐指数
2
解决办法
3932
查看次数

c警告:在常量表达式中使用const变量在C中是非标准的

尝试将数组初始化为常量时,我​​收到此警告.

#2170-D在常量表达式中使用const变量在C中是非标准的

#file.h
typedef struct {
    // LED Blink Pattern
    .....
} LEDSeq

void addError(LEDSeq);
void runLEDErrors();
....

#file.c
const uint8_t MAXERRORS = 4;
LEDSeq errors[MAXERRORS];
uint8_t errorsLength = 0;
....
Run Code Online (Sandbox Code Playgroud)

本质上,它是一些代码,它将循环遍历在运行时添加的LED错误序列.我必须使用固定大小的数组,因为realloc在我的环境中不可用.代码都有效.我只是想知道为什么我会收到这个错误.

c warnings

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

c预编译器对定义为(void)0的宏做了什么

我有一些基于编译器标志定义的宏.我正在尝试决定是否要将宏定义为(void)0或将其定义为未定义并导致编译时错误.

#ifdef DEBUG
  #define PRINTF(...) printf(__VA_ARGS__)
#else
  #define PRINTF(...) (void)0
#endif

int main(void) {
  ...
  PRINTF("something");
  ...
}
Run Code Online (Sandbox Code Playgroud)

#ifdef DEBUG
  #define PRINTF(...) printf(__VA_ARGS__)
#endif

int main(void) {
  ...
  #ifdef DEBUG
    PRINTF("something");
  #endif
  ...
}
Run Code Online (Sandbox Code Playgroud)

我不确定我喜欢哪种技术.一方面用#ifdef包装每个PRINTF语句都很难看.另一方面,如果我已经调用了一个在上下文中不起作用的函数,那么在编译时就知道了.

我认为决定因素是(void)0宏是否会影响可执行文件的大小.

编译代码时,(void)0会发生什么?如果PRINTF定义为(void)0,那是否意味着可执行文件将包含某种(void)0指令或是否会被完全忽略?

c compiler-construction macros

3
推荐指数
2
解决办法
1166
查看次数

Python串口侦听器

我已经开始使用PySerial编写一些代码来向串行设备发送和接收数据.

到目前为止,我一直致力于从终端启动事务并从串行设备接收响应.

伪:

main:
    loop:
        message = get_message()
        send_to_serial(message)
        time_delay(1 second)
        read_response()
Run Code Online (Sandbox Code Playgroud)

现在我想在串口设备启动通信的情况下在该端口上实现一个监听器.另外要移除time_delay哪个可能会结束太长时间,或者不足以让串行设备响应.

state = idle
register_interrupt(serial_device, read_response())

main:
    loop:
        message = get_message()
        state = sending
        send_to_serial(message)
Run Code Online (Sandbox Code Playgroud)

到目前为止,我还没有找到任何使用中断进行通信的PySerial代码.

我只是不知道如何在python中设置任何类型的中断,怎么会

python serial-port interrupt pyserial

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

Python - 如果定义则传递参数,否则使用默认值

我正在尝试使用字典的值进行函数调用。

该函数采用许多参数,大多数具有默认值。

def foo(name, a=None, b='', c=12):
    print(name,a,b,12)
Run Code Online (Sandbox Code Playgroud)

如果字典已完全填充,函数调用将如下所示。

def call_foo(arg_dict):
    foo(name=arg_dict['name'], a=arg_dict['a'], b=arg_dict['b'], c=arg_dict['c'])
Run Code Online (Sandbox Code Playgroud)

不过,我需要根据这些键是否实际存在于字典中来进行函数调用。因此,如果只有一部分参数存在,我只会传递这些参数。

def call_foo(arg_dict):
    if 'a' in arg_dict and 'b' in arg_dict and 'c' in arg_dict:
        foo(name=arg_dict['name'], a=arg_dict['a'], b=arg_dict['b'], c=arg_dict['c'])
    elif 'a' in arg_dict and 'c' in arg_dict: 
        foo(name=arg_dict['name'], a=arg_dict['a'], c=arg_dict['c'])
Run Code Online (Sandbox Code Playgroud)

这种类型的表达式将很快变得难以管理,因为有大量可选参数。

如何定义要传递给 foo 的命名参数列表?类似于以下内容。

def call_foo(arg_dict):
    arg_list = []
    arg_list.append(name=arg_dict['name'])
    if 'a' in arg_dict:
        arg_list.append(a=arg_dict['a'])
    if 'b' in arg_dict:
        arg_list.append(b=arg_dict['b'])
    if 'c' in arg_dict:
        arg_list.append(c=arg_dict['c'])
    foo(arg_list)
Run Code Online (Sandbox Code Playgroud)

python arguments

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

c函数返回sprintf字符串

只是尝试创建一个简单的toString函数,但我很难弄清楚如何创建一个sprintf样式字符串而无需创建临时变量.

即如果以下工作将会很棒

#myfile.c
bool status;
int state;
...
const char* myfileToString(void) {
    return sprintf("myfile::status=%s;state=%d;", \
                   status ? "true" : "false", \
                   state);
}
Run Code Online (Sandbox Code Playgroud)

这将无法工作,因为sprintf需要您首先创建字符串然后将其传递给函数.

即我相信以下工作

#myfile.c
bool status;
int state;
...
const char* myfileToString(void) {
    char ret[40];
    sprintf(ret, \
            "myfile::status=%s;state=%d;", \
            status ? "true" : "false", \
            state);
    return ret;
}
Run Code Online (Sandbox Code Playgroud)

是否有另一个函数,我可以使用而不是sprintf或者我可以用sprintf做一些奇怪的事情,就像传递一些指针直接返回 sprintf(*return, "...", ...);

c string

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