我有一个包含BLOB文件的sqlite表,但需要对blob进行大小/长度检查,我该怎么做?
根据我发现的一些文档,使用length(blob)将不起作用,因为length()仅适用于文本,并将在第一个NULL之后停止计数.我的实证检验证明了这一点.
我正在使用SQLite 3.4.2
更新:
因此,从SQLite 3.7.6开始,似乎length()函数返回正确的blob值 - 我检查了sqlite的各种更改日志,但没有看到更正的版本.
来自Sqlite 3.7.6:
payload_id|length(payload)|length(hex(payload))/2 1807913|194|194 1807914|171|171
该文件被更改,以反映这一点.
length(X) The length(X) function returns the length of X in characters if X is
a string, or in bytes if X is a blob. If X is NULL then length(X) is
NULL. If X is numeric then length(X) returns the length of a string
representation of X.
大多数Unix程序员都习惯于定义的接口syslog.h,并且许多实现(例如glibc)对发送给它的syslog消息的大小没有实际限制,但是应用程序监听通常有限制/dev/log.
我想知道是否有人知道如何找到syslog的最大消息大小?或者一些关于实际(或通常)限制的好文档?
编辑:
到目前为止,我已经在这个主题上找到了这些RFC:
我们在C,C++和Java的代码库上进行了一些代码清理,修复了有符号/无符号比较,运行静态分析等.
我们得到的警告之一是
warning: ISO C does not permit named variadic macros
Run Code Online (Sandbox Code Playgroud)
和它的同伴警告
warning: ISO C99 requires rest arguments to be used
Run Code Online (Sandbox Code Playgroud)
现在,在C代码中我使用C99标准可变参数宏来解决问题,但在C++代码中,正确的答案是什么?使用相同的C99样式会产生不同的警告
warning: anonymous variadic macros were introduced in C99
Run Code Online (Sandbox Code Playgroud)
我没有看到任何答案.
我们在Linux中使用GCC(G ++)4.4.3.
我希望有一些标志或其他方法可以纠正或禁用它的特定代码部分 - 但它用于几乎每个文件中使用的日志...
我有一些数学(在C++中)似乎产生了一些非常小的,接近于零的数字(我怀疑trig函数调用是我真正的问题),但是我想检测这些情况以便我可以在更多详情.
我目前正在尝试以下内容,这是正确的吗?
if ( std::abs(x) < DBL_MIN ) {
log_debug("detected small num, %Le, %Le", x, y);
}
Run Code Online (Sandbox Code Playgroud)
其次,数学的本质是三角函数(也就是使用很多弧度/度数转换和sin/ cos/ tan调用等),我可以做些什么样的转换来避免数学错误?
显然,对于乘法我可以使用对数变换 - 还有什么?
关于Java的WeakReference和Collections的几个问题:
是否有一个库透明地使用WeakReference实现Java的各种数据集接口(例如Collection,List,Set,Queue等)?像WeakHashMap一样用于HashMap接口?
或者是简单地创建普通集合然后使用compareTo或Comparator或某些东西来使搜索集合正常工作的常见解决方案?
我基本上想这样:
public interface WeakCollection<E> extends Collection<E> {}
Run Code Online (Sandbox Code Playgroud)
但是接口的合同是对E的引用存储很弱.显然,get(int index)当该对象已经消失等时返回null 没有问题,但我希望contains(E e)函数和其他类似的项能够正常工作.
我只是想避免"没有发明在这里"的陷阱,并确保如果我自己实现这个最简单的解决方案.
So I'm working off one of the examples for Boost program_options library, and I wanted to try setting a default value for one of the multiple-values/ vector-values, but it doesn't seem to work. As I think is suggested here to work.
What I've modified is on about line 40:
po::options_description config("Configuration");
config.add_options()
("optimization", po::value<int>(&opt)->default_value(10),
"optimization level")
("include-path,I", o::value< vector<string> >()->default_value(vector<string>(),"SOMETHING")->composing(), "include path")
;
Run Code Online (Sandbox Code Playgroud)
When I compile this small change, I expect that when no -I option is passed that …
我和朋友一直在玩pygame,并且遇到了使用pygame 构建游戏的教程.我们真的很喜欢它如何将游戏分解为模型 - 视图 - 控制器系统,其中事件作为中间人,但代码大量使用isinstance事件系统的检查.
例:
class CPUSpinnerController:
...
def Notify(self, event):
if isinstance( event, QuitEvent ):
self.keepGoing = 0
Run Code Online (Sandbox Code Playgroud)
这导致一些非常非常规的代码.有没有人对如何改进这方面有任何建议?或者实施MVC的替代方法?
这是我根据@ Mark-Hildreth答案编写的一些代码(如何链接用户?)其他人有什么好的建议吗?在选择解决方案之前,我将在另一天左右开放.
class EventManager:
def __init__(self):
from weakref import WeakKeyDictionary
self.listeners = WeakKeyDictionary()
def add(self, listener):
self.listeners[ listener ] = 1
def remove(self, listener):
del self.listeners[ listener ]
def post(self, event):
print "post event %s" % event.name
for listener in self.listeners.keys():
listener.notify(event)
class Listener:
def __init__(self, event_mgr=None):
if event_mgr is not None:
event_mgr.add(self) …Run Code Online (Sandbox Code Playgroud) 我正在尝试在命令行,报告样式上为输出格式化一些字符串,并且我正在寻找格式化字符串的最简单方法,以便我可以获得自动段落格式.
在perlform格式化是通过"格式"功能完成的
format Something =
Test: @<<<<<<<< @||||| @>>>>>
$str, $%, '$' . int($num)
.
$str = "widget";
$num = $cost/$quantity;
$~ = 'Something';
write;
Run Code Online (Sandbox Code Playgroud)
perlform的变化允许文本被干净地包裹,对于帮助屏幕,日志报告等是有用的.
是否有python等价物?或者我可以用Python的新字符串格式函数编写一个合理的hack ?
示例输出我想:
Foobar-Title Blob
0123 This is some long text which would wrap
past the 80 column mark and go onto the
next line number of times blah blah blah.
hi there dito
something more text here. more text here. more text
here.
Run Code Online (Sandbox Code Playgroud) 平台:Linux,OSX
编译器:GCC
我有一个简单的程序,目前让我感到困惑 - 我知道我正在搞乱几种不同类型的数组/指针来产生这个问题 - 它是故意的 - 我试图理解它.
列出的代码将按预期编译和运行,但会data4在调用中strsep(&data4, "e");更改data1或data3导致分段错误.我想了解原因.
#include <stdio.h>
#include <string.h>
int main(int c, char** v) {
char* data1 = "hello\0";
char* data2 = strdup(data1);
size_t sz = strlen(data1);
char data3[sz+1];
char* data4;
memset(data3, 0, sz+1);
data4 = strncpy(data3, data1, sz);
data4[sz] = '\0';
char* found = strsep(&data4, "e");
if (found == NULL) {
printf("nothing found\n");
} else {
printf("found e\n");
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)