小编Dav*_*ver的帖子

我怎么能用git"diff -c"?

在$ VCS中,我大量使用$VCS diff -c $N只查看修订版中引入的更改$N(即diff -r $N..$N+1).

我怎么能用git做同样的事情?

git

4
推荐指数
2
解决办法
199
查看次数

Firefox:凭据的跨域请求返回空

Firefox 发送带有凭据的跨域帖子,我可以(使用Charles - HTTP调试的代理)看到服务器正在发回响应......但Firefox并没有"让我看到它"(因为缺乏更好的描述) ).

例如,使用记录的示例:

>>> var invocation = new XMLHttpRequest();
>>> invocation.open('GET', 'http://localhost/~wolever/cookie.php', true);
>>> invocation.withCredentials=true;
>>> invocation.onreadystatechange = console.log;
>>> invocation.send()
http://img.skitch.com/20100113-bq3a4qb1ufn52331x18ce3c7xu.png
>>> invocation.responseText
""
>>> invocation.responseXML
null

但是,Charles告诉我,这个请求实际上已经返回了预期的响应:

http://img.skitch.com/20100113-njakyu4xequ5e3cyfhfnyeatq5.png

什么可能出错?

而且,这有助于:没有凭据的相同请求会返回应有的数据.

firefox xmlhttprequest cross-domain

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

Eclipse:在Open Resource(和其他对话框)之后重新聚焦主编辑器窗口

当我使用Eclipse时,我用编辑器填充主监视器,并将所有面板(导航器,控制台,问题等)分解到我的辅助监视器上.

我注意到,虽然当我打开一个对话框(例如,Open Resource)然后取消它(例如,通过点击转义)时,焦点从主编辑器窗口转移到其中一个分解面板.

有什么方法可以防止这种情况吗?或者,如果失败了,是否有一些"重新聚焦主编辑器"的捷径?

eclipse

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

Python:当删除项目时,set类是否会"泄漏",就像dict一样?

我知道Python dict会在删除项目时"泄漏"(因为项目的插槽将被魔法"删除"值覆盖)......但是这个set类的行为方式是否相同?set随着时间的推移,保持周围,​​添加和删除东西是否安全?

编辑:好的,我已经尝试过了,这就是我发现的:

>>> import gc
>>> gc.collect()
0
>>> nums = range(1000000)
>>> gc.collect()
0
### rsize: 20 megs
### A baseline measurement
>>> s = set(nums)
>>> gc.collect()
0
### rsize: 36 megs
>>> for n in nums: s.remove(n)
>>> gc.collect()
0
### rsize: 36 megs
### Memory usage doesn't drop after removing every item from the set…
>>> s = None
>>> gc.collect()
0
### rsize: 20 megs
### … but nulling the reference to the set *does* free the memory. …

python dictionary set

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

为什么 Django 在使用外键时添加约束而不是在 Create 语句中定义它?

我正在阅读 Django 教程并定义投票和选择模型。当我运行manage.py sql polls查看 sql 语句时,我得到:

CREATE TABLE `polls_poll` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `question` varchar(200) NOT NULL,
    `pub_date` datetime NOT NULL
);

CREATE TABLE `polls_choice` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `poll_id` integer NOT NULL,
    `choice_text` varchar(200) NOT NULL,
    `votes` integer NOT NULL
);

ALTER TABLE `polls_choice` ADD CONSTRAINT `poll_id_refs_id_3aa09835`
    FOREIGN KEY (`poll_id`) REFERENCES `polls_poll` (`id`);
Run Code Online (Sandbox Code Playgroud)

为什么DjangoALTER在应用外键时使用语句而不是在Create table语句中执行?类似以下的内容似乎更简洁:

`poll_id integer NOT NULL REFERENCES polls_choice(id)`
Run Code Online (Sandbox Code Playgroud)

mysql sql django

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

使用Django进行多个并发数据库事务?

是否可以在一个Django进程中使用多个并发事务?

具体来说,我有两个函数应同时执行(相互之间产生),但每个函数应在各自的事务中执行。例如:

def process_things(callback, things):
    with start_transaction():
        for thing in things:
            obj = Thing.objects.create(…)
            callback(obj)

def callback(obj):
    with start_separate_transaction():
        …
        ThingProcessingLog.objects.create(…)
Run Code Online (Sandbox Code Playgroud)

我希望每个函数都可以在独立的数据库事务中运行,因此在此示例中,ThingProcessingLog记录将被创建并立即可见,但是在Thing对象全部处理完之后这些对象才可见。

我该如何使用Django的ORM?

python django django-orm

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

在非主键关系上加入和查询Django模型?

我有两个通过非主键字段在逻辑上相关的模型。是否可以在select_related(…)不引入ForeignKey列的情况下查询它们(例如,)?

例如,考虑人为模型:

class LogEntry(Model):
    source_name = CharField(…)
    log_message = CharField(…)

class LogSource(Model):
    name = CharField(…)
    domain = CharField(…)
Run Code Online (Sandbox Code Playgroud)

我希望能够查询LogEntry,加入和过滤相关内容LogSource(例如,因此我可以访问log_entry.source而无需其他查询):

LogEntry.objects
    .select_related(
        source=Join(LogSource, on="logsource.name = logentry.source_name")),
    )
    .filter(source__domain="example.com")
Run Code Online (Sandbox Code Playgroud)

不引入ForeignKey可以做到吗?

django django-models

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

PyPI错误"上传失败(400):摘要:不允许多行"是什么意思?

我只是尝试将一个新版本的软件包上传到PyPI,但是出现了这个错误:

$ python setup.py sdist bdist_wheel upload
…
Writing pip2pi-0.7.0/setup.cfg
Creating tar archive
removing 'pip2pi-0.7.0' (and everything under it)
running upload
Submitting /Users/wolever/code/pip2pi/dist/pip2pi-0.7.0-py2.py3-none-any.whl to https://upload.pypi.org/legacy/
Upload failed (400): summary: Multiple lines are not allowed.
error: Upload failed (400): summary: Multiple lines are not allowed.

这是什么意思?我该如何解决?

上传此软件包的早期版本没有问题.

我试图上传的代码:https://github.com/wolever/pip2pi/tree/a026f05a265a6f8c7fb7a5c4cf6484b9ede77761

python pypi

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

bignumber.js 中的`c`、`e` 和`s` 是什么意思?

什么是的含义ce以及s在所产生的对象字段bignumber.js

例如:

> new BigNumber('1234')
{ c: [1234], e: 3, s: 1 }
> new BigNumber('12345678901234567890')
{ c: [123456, 78901234567890], e: 19, s: 1 }
Run Code Online (Sandbox Code Playgroud)

javascript bignum

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

pymongo:findandmodify - 返回"no such command"

我相信pymongo(或者至少是文档)中存在一个错误,它使得无法运行findandupdate查询.

这是发生了什么.当我跑:

    result = db.command({
        'findandmodify': 'my_collection',
        'query': {'foo': 'bar'},
        'update': {'$set': {'status': 'queued'}},
    })
Run Code Online (Sandbox Code Playgroud)

实际发送到服务器的查询是:

{ 'query': {'foo': 'bar'}, 'findandmodify': 'my_collection', … }
Run Code Online (Sandbox Code Playgroud)

请注意,query参数是第一个,findandmodify第二个.

但这导致服务器抛出:

OperationFailure: command { 'query': {'foo': 'bar'}, 'findandmodify': 'my_collection', … } failed: no such cmd

因为服务器期望findandmodify是第一个(BSON dicts显然是有序的).

这有什么工作吗?

python mongodb pymongo

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