我对Kyle Banker的MongoDB In Action中的引用感到好奇:
考虑所选键名的长度很重要,因为键名存储在文档中.这与RDBMS形成对比,其中列名始终与它们引用的行分开.因此,当使用BSON时,如果您可以使用dob代替date_of_birth作为键名,那么每个文档将节省10个字节.这可能听起来不是很多,但是一旦你有十亿个这样的文件,你只需使用一个较短的密钥名称就可以节省近10 GB的存储空间.这并不意味着你应该采取不合理的长度来确保小关键名称; 要懂事.但是,如果您期望大量数据,节省关键名称将节省空间.
我感兴趣的是在数据库服务器端没有优化它的原因.内存查找表中是否包含集合中的所有键名称是否会导致性能损失太大而不值得节省空间?
我有点困惑groovys方法重载行为:由于阶级和下面的测试中,我与漂亮没关系testAStringNull,并testBStringNull
抛出暧昧的方法调用例外,但为什么就是不适合的情况
testANull和testBNull呢?
而且,更重要的是:为什么testBNull(null)
打电话String foo(A arg)?我猜这个对象不知道它所绑定的变量的类型,但为什么这个调用对于groovy而言并不模糊,而其他的呢?
(我希望我解释得很好,我的脑袋因产生这个极小的例子而受伤.)
class Foo {
static class A {}
static class B {}
String foo(A arg) { return 'a' }
String foo(String s, A a) { return 'a' }
String foo(B arg) { return 'b' }
String foo(String s, B b) { return 'b' }
}
Run Code Online (Sandbox Code Playgroud)
测试:
import org.junit.Test
import Foo.A
import Foo.B
class FooTest {
Foo foo = new Foo()
@Test
void testA() { …Run Code Online (Sandbox Code Playgroud) 我想将一个部分,即现有的私有mercurial存储库的一个子目录移动到bitbucket上的新的公共存储库.是否可以执行此操作,包括更改集,还是必须手动将目录复制到新存储库并将其提交到那里(并在途中丢失版本历史记录)?
我正在尝试让我的远程chrome驱动程序以德语而不是英语请求页面.根据chromedriver文档和chrome首选项列表,我尝试将其设置为:
capabilities.setCapability(ChromeOptions.CAPABILITY, getChromeOptions());
Map<String, String> chromePrefs = new HashMap<String,String>();
chromePrefs.put("settings.language.preferred_languages", "de-DE,de");
capabilities.setCapability("chrome.prefs", chromePrefs);
Run Code Online (Sandbox Code Playgroud)
我可以从日志文件中看到它到达chromedriver:
[0.453][FINE]: Initializing session with capabilities {
"browserName": "chrome",
"chrome.prefs": {
"settings.language.preferred_languages": "de-DE,de"
},
"chromeOptions": {
"args": [ "--ignore-certificate-errors" ],
"extensions": [ ]
},
"platform": "ANY",
"version": null
}
Run Code Online (Sandbox Code Playgroud)
但它仍然要求英文页面,这也可以通过打开首选项中的内容设置来看到.我究竟做错了什么?
以下grails查询将结果数限制为3,然后按id排序:
def results = Domain.findAllByFoo(foo, [sort: 'id', order: 'desc', max: 3])
因此,这将返回ID 1到3,然后反转它们的顺序,这样
results*.id == [3,2,1]
有没有办法先排序,然后限制,以便
results*.id == [99,98,97]
我目前的解决方法是:
if (results.size() > max) results = results[0..<max]
我正在使用一些客户端库,并使用scala.util.control.Exception.ignoring以下代码忽略特定异常:
ignoring(classOf[ReallyNotThatExceptionalException]) {
stuff()
}
Run Code Online (Sandbox Code Playgroud)
现在该库已更改为将所有exceptionn包装在另一个异常类中,这迫使我将代码更改为:
try { stuff() }
catch {
case e:WrapperException if e.getCause != null && e.getCause.isInstanceOf[ReallyNotThatExceptionalException] => { }
}
Run Code Online (Sandbox Code Playgroud)
所以我正在寻找一种更易读的方式来表达"捕获由...引起的异常".
在编写python时,我经常使用日志记录模块.
一些不好的经验,并像阅读文章后这一个,我试图阻止进口时执行的代码尽可能.
但是,为了简单起见,我倾向于将我的日志记录对象放在模块文件的开头:
# -*- coding: utf-8 -*-
import logging
logger = logging.getLogger('product.plugin.foo.bar')
Run Code Online (Sandbox Code Playgroud)
这样,我的记录器可以全局访问,我可以在任何地方写"logger.error()".另一种方法是在类范围内创建它:
class Bar(object):
logger = logging.getLogger('product.plugin.foo.bar')
Run Code Online (Sandbox Code Playgroud)
但是,现在我必须每次都输入类名.为了防止输入类名,我很想使用"self"代替静态方法.
def my_method(self):
Bar.logger.error('foo')
def my_method_2(self):
self.logger.error('foo') # ok...
@staticmethod
def my_method_2():
self.logger.error('foo') # boom!
Run Code Online (Sandbox Code Playgroud)
所以,起初看起来像在模块范围内创建记录器对象似乎是正确的事情 - 仍然感觉就像我这样做时最终会导致与导入相关的麻烦......
我正在使用Hudson为使用Sphinx的Python项目生成文档.这会在项目/ _build/html文件夹中生成HTML文档,我将其设置为用作构建工件.现在,在运行作业之后,我可以通过单击"Artifacts"链接,然后单击文件夹,然后单击index.html文件来导航到文档.这有点麻烦,所以我想自定义项目页面,这样我就可以有一个"查看文档"链接,直接转到index.html文件.哈德森有没有办法做到这一点?
python documentation continuous-integration hudson python-sphinx
我只是使用python从列表中提取了一些数据,但认为它过于复杂和unpythonic,并且可能有更好的方法来做到这一点.我其实很确定我在标准库文档中看到了这个,但我的大脑拒绝告诉我在哪里.
所以这里:
输入:
x = range(8) # any even sequence
Run Code Online (Sandbox Code Playgroud)
输出:
[[0, 1], [2, 3], [4, 5], [6, 7]]
Run Code Online (Sandbox Code Playgroud)
我的看法:
[ [x[i], x[i+1]] for i in range(len(x))[::2] ]
Run Code Online (Sandbox Code Playgroud)