比方说我有一个数据类型,X我想知道它的大小而不声明该类型的变量或指针,当然不使用sizeof运算符.
这可能吗?我想过使用标准头文件,其中包含数据类型的大小和范围,但不适用于用户定义的数据类型.
当我向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) 我有一个测试网站,使用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平台上运行的建议将不胜感激.
在我的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.我如何处理这个?
有一个使用boost :: asio的例子.
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) 我有在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
在我尝试让我的烧瓶应用程序在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.我无法继续部署我的烧瓶应用程序,直到它启动并运行.非常感谢!
经过一些搜索和浏览IPython 文档和一些代码后,我似乎无法弄清楚是否可以将命令历史记录(而不是输出日志)存储到文本文件而不是SQLite数据库.ipython --help-all似乎表明此选项不存在.
这对于控制常用命令的版本非常好,例如.bash_history.
编辑:基于@minrk答案的工作解决方案.
python ×4
ajax ×1
apache ×1
arrays ×1
boost-asio ×1
c ×1
c++ ×1
css ×1
exception ×1
geany ×1
ipython ×1
javascript ×1
mod-wsgi ×1
python-2.7 ×1
sizeof ×1
ssl ×1
system-calls ×1
wsgi ×1