小编kay*_*kay的帖子

不使用sizeof的数据类型的大小

比方说我有一个数据类型,X我想知道它的大小而不声明该类型的变量或指针,当然不使用sizeof运算符.

这可能吗?我想过使用标准头文件,其中包含数据类型的大小和范围,但不适用于用户定义的数据类型.

c sizeof

19
推荐指数
4
解决办法
4万
查看次数

.push()多个对象进入JavaScript数组返回'undefined'

当我向beats数组添加项目然后console.log用户时,我在数组中获得了正确数量的项目.但是当我检查.length时,我总是得到1.尝试调用索引总是会给我'未定义',就像这样: Tom.beats[1] 我想我错过了一些明显的东西,但这是打败了我.我怀疑我滥用这种.push方法,但我不确定.任何帮助是极大的赞赏!(使用Chrome开发工具)

//The USER

function User(name, role){
    this.beats = [ ]; 

    this.name = name;
    this.role = role;

    // add beats to beats array

    this.addBeats = function(beats){ 
        return this.beats.push(beats);
   };

}

// Three New Instances. Three New Users.

var Mal = new User("Mal", "Rapper");
Mal.addBeats(["love", "cash"]);

var Dan = new User("Dan", "Producer");
Dan.addBeats(["cake", "dirt", "sally-mae"]);

var Tom = new User("Tom", "Producer");
Tom.addBeats(["Fun", "Little", "Samsung", "Turtle", "PC"]);

// Check for position in beats array

console.log(Tom.beats); 
console.log(Mal.beats); 
console.log(Dan.beats); 

console.log(Mal.beats[1]);
console.log(Dan.beats[1]); …
Run Code Online (Sandbox Code Playgroud)

javascript arrays

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

Word Awesome未在Windows Phone 8上显示

我有一个测试网站,使用Font Awesome字体显示图标.

我的桌面上的图标在IE和Chrome以及iPhone和Andriod移动设备上显示正常.

但是,诺基亚Lumia 920 Windows Phone 8上未显示字体图标.

我无法弄清楚导致问题的原因.其他具有Font Awesome图标字体的网站在Nokia Lumia 920 Windows Phone上正确显示.因此,必须有一些特定于我创建的设置.

测试网站是:http: //www-peachtreedata.azurewebsites.net/?page_id = 6

任何有关如何使其在Windows Phone平台上运行的建议将不胜感激.

css windows-phone-8

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

在Python中处理未声明的dict键

在我的Ruby应用程序中,我有一个哈希表:

c = {:sample => 1,:another => 2}
Run Code Online (Sandbox Code Playgroud)

我可以像这样处理表格:

[c[:sample].nil? , c[:another].nil? ,c[:not_in_list].nil?]
Run Code Online (Sandbox Code Playgroud)

我正在尝试用Python做同样的事情.我创建了一个新词典:

c = {"sample":1, "another":2}
Run Code Online (Sandbox Code Playgroud)

我无法处理nil值异常:

c["not-in-dictionary"]
Run Code Online (Sandbox Code Playgroud)

我试过这个:

c[:not_in_dictionery] is not None
Run Code Online (Sandbox Code Playgroud)

它返回一个异常,而不是False.我如何处理这个?

python exception-handling exception

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

为什么我们需要使用boost :: asio :: io_service :: work?

有一个使用boost :: asio的例子.

  1. 为什么这个例子使用boost :: asio :: io_service :: work?
  2. 为什么srv.run ();没有调用在线程中执行任务?
int main()
{
    boost::asio::io_service srv;
    boost::asio::io_service::work work(srv);
    boost::thread_group thr_grp;
    thr_grp.create_thread(boost::bind(&boost::asio::io_service::run, &srv));
    thr_grp.create_thread(boost::bind(&boost::asio::io_service::run, &srv));

    srv.post(boost::bind(f1, 123));
    srv.post(boost::bind(f1, 321));
    //sync

    srv.post(boost::bind(f2, 456));
    srv.post(boost::bind(f2, 654));
    //sync

    srv.stop();
    thr_grp.join();
}
Run Code Online (Sandbox Code Playgroud)

更新: 在没有io_service :: work的情况下使用io_service时,poll和run之间有什么区别?

int main()
{
    boost::asio::io_service srv;
    //boost::asio::io_service::work work(srv);
    std::vector<boost::thread> thr_grp;

    srv.post(boost::bind(f1, 123));
    srv.post(boost::bind(f1, 321));
    //sync

    srv.post(boost::bind(f2, 456));
    srv.post(boost::bind(f2, 654));
    //sync

    // What is the difference between the poll and run, when io_service without work?
    thr_grp.emplace_back(boost::bind(&boost::asio::io_service::poll, &srv));// poll …
Run Code Online (Sandbox Code Playgroud)

c++ boost-asio

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

如何在Geany中排序?

我正在寻找一种在Geany中排序的方法.

然后找到下面的解决方案.

geany

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

在Python中进行系统调用

我想syscall在Python中制作并且函数不在libc,有没有办法在Python中做到这一点?

更具体地说,我想打电话getdents,其联机帮助页说

注意:这些系统调用没有glibc包装器;

所有现有的相关解决方案我发现在网络上使用ctypeslibc.so:为例子.

请不要质疑我为什么要getdents直接使用,我有一个非常具体的理由这样做,在这个问题上讨论会分散注意力.谢谢.

python system-calls python-2.7

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

XDomainRequest可以使用SSL吗?

我有在IE8中使用Microsoft的XDomainRequest对象的代码.代码如下所示:

var url = "http://<host>/api/acquire?<query string>";  
var xdr = new XDomainRequest();  
xdr.onload = function(){  
    $.("#identifier").text(xdr.responseText);  
};  
xdr.open("GET", url);  
xdr.send();  
Run Code Online (Sandbox Code Playgroud)

当"url"中的方案是"http://"时,该命令正常工作.但是,当方案是"https://"IE8给我一个"拒绝访问"JavaScript错误.这两种方案在FF 3.6.3中运行良好,我当然使用XmlHttpRequest.对于这两种浏览器,我都遵守W3C访问控制."http://"适用于两种浏览器的交叉原点.所以问题出在IE8,XDomainRequest和SSL上.

SSL证书不是问题.如果我<host在IE8的地址栏中键入https:// > /,其中<host>与上面的"url"相同,页面加载正常.

所以我们有以下内容:
- <host直接从浏览器点击https:// > /可以正常工作;
- 点击https:// <host>/api/acquire?<query string>不允许通过XDomainRequest.

可以吗?我要留下什么了?

ajax ssl internet-explorer-8 internet-explorer-9 xdomainrequest

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

mod_wsgi中的Hello World

在我尝试让我的烧瓶应用程序在Apache上运行后反复失败后,我mod_wsgi决定尝试运行hello world示例.这是我的 -

目录结构(我将apache默认更改/var/www~/public_html)

- public_html    
   - wsgi-scripts
      - test_wsgi.wsgi
   - test_wsgi
      - test_wsgi.wsgi
Run Code Online (Sandbox Code Playgroud)

test_wsgi.wsgi文件

def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]

    start_response(status, response_headers)

    return [output]
Run Code Online (Sandbox Code Playgroud)

VirtualHost配置文件(称为testwsgi) - 驻留在 /etc/apache2/sites-enabled/

<VirtualHost *:80>
    DocumentRoot ~/public_html/test_wsgi

    <Directory ~/public_html/test_wsgi>
        Order allow,deny
        Allow from all
    </Directory>

    WSGIScriptAlias /wsgi ~/public_html/wsgi-scripts/test_wsgi.wsgi

    <Directory ~/public_html/wsgi-scripts>
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

当我尝试localhost/wsgi使用浏览器时,我收到404 Not Found错误.我究竟做错了什么?这是我第一次尝试在生产服务器上部署应用程序.到目前为止,我采用了简单的方法来使用Google App Engine.我无法继续部署我的烧瓶应用程序,直到它启动并运行.非常感谢!

python apache mod-wsgi wsgi

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

如何将IPython历史记录到文本文件?

经过一些搜索和浏览IPython 文档和一些代码后,我似乎无法弄清楚是否可以将命令历史记录(而不是输出日志)存储到文本文件而不是SQLite数据库.ipython --help-all似乎表明此选项不存在.

这对于控制常用命令的版本非常好,例如.bash_history.

编辑:基于@minrk答案的工作解决方案.

python configuration ipython

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