小编Col*_*Two的帖子

什么是无效[]?

我已经void[]在D文档和函数签名中看到过几个地方使用的类型.这是什么意思?

我已经搜索了文档中的数组部分以及Google,但没有找到任何结论.我发现所有数组都可以隐式转换为该void[]类型.它只是一个无类型数组吗?

d

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

如何从排名较高的特征绑定特征返回关联类型?

我有一个特征,它具有反序列化关联类型的功能。然而,关联类型需要有调用者决定的生命周期,所以我有一个单独的特征,我使用更高等级的特征绑定,以便它可以在任何生命周期反序列化。

我需要使用一个返回此关联类型的闭包。

我有以下代码来做到这一点:

#![allow(unreachable_code)]

use std::marker::PhantomData;

trait Endpoint: for<'a> EndpointBody<'a> {}
trait EndpointBody<'a> {
    type Out: 'a;
    fn serialize(body: &Self::Out) -> Vec<u8>;
    fn deserialize(raw_body: &'a [u8]) -> Self::Out;
}

// /////////////////////////////////////////////////////////

/// Trait object compatible handler
trait Handler {
    fn execute(&self, raw_body: &[u8]) -> Vec<u8>;
}

/// Wraps a function for an endpoint, convertint it to a Handler
struct FnHandler<EP, F>
where
    EP: Endpoint,
    F: 'static + for<'a> Fn(&'a [u8]) -> <EP as EndpointBody<'a>>::Out,
{
    func: F,
    _ph: PhantomData<EP>,
} …
Run Code Online (Sandbox Code Playgroud)

traits rust higher-rank-types

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

错误"没有这样的文件加载" - sqlite3/sqlite3_native(LoadError)

我的操作系统是Windows 7.

我的问题是,当我尝试运行时rails server,会发生错误.我已经安装了sqlite3宝石,甚至sqlite-ruby宝石,但仍然没有.

我已经不知道该怎么做了.

如果有人需要任何其他信息,请求它,我会把它提出来.

完整的错误是:

C:/Ruby192/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.3-x86-mingw32/lib/sqlite3.rb:6:in `require': no such file to load -- sqlite3/sqlite3_native (LoadError)
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.3-x86-mingw32/lib/sqlite3.rb:6:in `rescue in <top (required)>'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sqlite3-1.3.3-x86-mingw32/lib/sqlite3.rb:2:in `<top (required)>'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.12/lib/bundler/runtime.rb:68:in `require'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.12/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.12/lib/bundler/runtime.rb:66:in `each'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.12/lib/bundler/runtime.rb:66:in `block in require'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.12/lib/bundler/runtime.rb:55:in `each'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.12/lib/bundler/runtime.rb:55:in `require'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.12/lib/bundler.rb:120:in `require'
    from C:/Users/JorWan/Desktop/JorWan/ASCENDSTUDIO/RoR/intento2/config/application.rb:7:in `<top (required)>'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/commands.rb:28:in `require'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/commands.rb:28:in `block in <top (required)>'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/commands.rb:27:in `tap'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/commands.rb:27:in `<top (required)>' …
Run Code Online (Sandbox Code Playgroud)

windows sqlite ruby-on-rails file-not-found

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

如何暂时禁用d3.js中的缩放

我正在寻找暂时禁用d3库提供的缩放功能的可能性.我尝试在停用缩放时保存洞穴当前缩放/平移值,并在再次激活缩放时设置缩放/平移值.不幸的是,这不起作用.

这是我创建的代码示例:

var savedTranslation = null;
var savedScale = null;

var body = d3.select("body");

var svg = body.append("svg");

var svgContainer = svg.append("svg:g");

var circle = svgContainer.append("svg:circle")
    .attr('cx', 100)
    .attr('cy', 100)
    .attr('r',30)
    .attr('fill', 'red');

circle.on('click', clickFn);

function clickFn(){
    if (circle.attr('fill') === 'red'){
        circle.attr('fill','blue')
    }
    else if (circle.attr('fill') === 'blue'){
        circle.attr('fill','red')
    }
}; 

svg.call(zoom = d3.behavior.zoom().on('zoom', redrawOnZoom)).on('dblclick.zoom', null);


 function redrawOnZoom(){
     if (circle.attr('fill') === 'red'){
         if (savedScale !== null){
             zoom.scale(savedScale)
             savedScale = null
         }
         if (savedTranslation !== null){
             zoom.translate(savedTranslation)
             savedTranslation = null
         } …
Run Code Online (Sandbox Code Playgroud)

javascript svg behavior zoom d3.js

9
推荐指数
2
解决办法
9563
查看次数

Python ValueError:无法解码JSON对象

我正在尝试读取json并获取其值.我有一个包含JSON档案的文件夹,我需要打开所有档案并从中获取值.

这是代码:

# -*- encoding: utf-8 -*-
from pprint import pprint
import json
import os 
def start():
    for dirname, dirnames, filenames in os.walk('test'):
        for filename in filenames:
            json_file = open(os.path.join(dirname, filename)).read()
            # json_file = unicode(json_file, 'utf-8')
            json_data = json.loads(json_file)
           pprint(json_data)
            for key, value in json_data.items():
                print "KEY : ", key
                print "VALUE: ", value
                start()
Run Code Online (Sandbox Code Playgroud)

这是JSON之一

{ "test" : "Search User 1",
   "url"  : "http://127.0.0.1:8000/api/v1/user/1/?format=json",
   "status_code" : 200,
   "method" : "get"
}
Run Code Online (Sandbox Code Playgroud)

但是当我运行它时,我得到了这个:

ValueError: No JSON object could be decoded …
Run Code Online (Sandbox Code Playgroud)

python json

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

Lua弱参考

我知道Lua中的弱表功能,但我希望对单个变量有一个弱引用.

我已经看到这个提议建议API如下:

-- creation
ref = weakref(obj)
-- dereference
obj = ref()
Run Code Online (Sandbox Code Playgroud)

这看起来很理想.然而,这似乎并未出现在其他地方的文件中; 只有弱表.

是否有类似于Python 对对象功能的弱引用

lua lua-table

9
推荐指数
2
解决办法
939
查看次数

比较两个浮点数在Python中是否相等

当比较两个是否在Python中浮动时,我看到代码总是这样比较一个小值epsilon,想知道选择正确的epsilon值的最佳实践是什么?它背后的场景是什么?谢谢.

epsilon = 0.000001
abs(a - b)<epsilon
Run Code Online (Sandbox Code Playgroud)

python floating-point

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

使用sqlite3编译Python 3.4

我编译了SQLite3 3.8.6并将其安装到$ {HOME}/opt:

LDFLAGS="-L${HOME}/opt/lib" CFLAGS="-L${HOME}/opt/include" ./configure --prefix=$HOME/opt
make && make install
Run Code Online (Sandbox Code Playgroud)

我现在正在尝试编译Python 3.4.2以使用此版本而不是为整个系统安装的版本.我在这个系统上没有root访问权限.要编译Python,我正在使用:

LDFLAGS="-L${HOME}/opt/lib" CFLAGS="-L${HOME}/opt/include" ./configure --prefix=$HOME/opt
make && make install
Run Code Online (Sandbox Code Playgroud)

如果是SQLite3,我能用我的新版本编译Python 3.3.5,但这些相同的步骤似乎对我来说不适用于3.4.2.

如何编译Python 3.4.2以包含我的版本的SQLite 3.8.6,它位于$ {HOME}/opt?

谢谢.

编辑:它编译和安装好,除了使用较旧的系统版本的sqlite3而不是我自己编译和安装的版本的事实.

python sqlite

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

C程序的内存分析

需要对我的C应用程序进行内存分析..

它应该包括占用空间大小和RAM大小......

例如,如果我的应用程序如下所示..

#include <stdio.h>

int global = 10; /* initialized global variable */

int test_code(void)
{
    static int i = 100; /* Initialized static variable*/
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出:

[putta@linux]$ gcc memory-layout.c -c memory-layout 

[putta@linux]$ ls -ltrh  memory-layout.o
760 Nov  9 18:26 memory-layout

[putta@linux]$ size memory-layout.o
   text    data     bss     dec     hex filename
     67       8       0      75      4b memory-layout.o
Run Code Online (Sandbox Code Playgroud)

那么现在我应该考虑哪些内存用于分析足迹,以及加载程序时的RAM.

以下分析是正确的吗?占用内存= 760(即闪存或硬盘)RAM = 67 + 8 + 0 = 75字节

需要专家建议

c memory memory-layout

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

纹波仿真器 - node.js

我无法启动波纹模拟.这是错误:

ripple emulate could not find cordova as a local module. expecting to find it installed globally
Run Code Online (Sandbox Code Playgroud)

使用以下命令安装Cordova: npm install cordova

我正在使用Windows 8.1 64位

ripple cordova

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