问题列表 - 第40526页

如何将其转换为单线发生器?

我最好的尝试都失败了:

for s in self.services:
  for m in s.messages: yield m
Run Code Online (Sandbox Code Playgroud)

python

0
推荐指数
1
解决办法
136
查看次数

什么是sprintf浮动的正确方法?

我正在尝试使用以下代码printf/sprintf浮点数:

sprintf(buff, "FPS: %d\n%.4f N %.4f E\nAl: %.1fm Rl: %.1f\n", fps, p_viewer.p.lat, p_viewer.p.lon, p_viewer.p.alt, p_viewer.roll);
Run Code Online (Sandbox Code Playgroud)

但是,当我这样做时,我会收到这些警告:

gfx_game_engine.c:300: warning: format '%.4f' expects type 'double', but argument 4 has type 'float'
gfx_game_engine.c:300: warning: format '%.4f' expects type 'double', but argument 5 has type 'float'
gfx_game_engine.c:300: warning: format '%.1f' expects type 'double', but argument 6 has type 'float'
gfx_game_engine.c:300: warning: format '%.1f' expects type 'double', but argument 7 has type 'float'
Run Code Online (Sandbox Code Playgroud)

什么是sprintf浮动的正确方法?是否有特殊的格式字符?我觉得编译器可能会以某种方式转换类型,这可能会导致它减慢速度.

我正在使用dsPIC33FJ128GP802微控制器并使用MPLAB C30进行编译,MPLAB C30是GCC v3.23的变体.

c floating-point printf

0
推荐指数
1
解决办法
4746
查看次数

根据构建配置修改WMAppManifest.xml

我想发布我的应用程序的不同风格,并希望在手机上显示的应用程序名称中指出这一点.据我所知,Silverlight Phone Apps的名称完全取决于WMAppManifest.xml.因此,我想基于我的构建配置在构建时修改应用程序标题.有什么建议?

silverlight visual-studio windows-phone-7

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

.htaccess - 301重定向所有没有扩展名的文件,扩展名为.html

我需要301将请求重定向到没有扩展名的文件,并附加.html扩展名:

http://www.mydomain.com/this
Run Code Online (Sandbox Code Playgroud)

http://www.mydomain.com/this.html
Run Code Online (Sandbox Code Playgroud)

以下内容不会被重定向:

http://www.mydomain.com/that/ (it's a directory)
http://www.mydomain.com/other.php
Run Code Online (Sandbox Code Playgroud)

感谢上述任何帮助.

.htaccess mod-rewrite redirect

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

Is there anyway to automatically make a TextView go to a new line after a certain amount of characters?

I can do this programmatically, but it is really inefficient, and also time consuming if I ever need to do it for multiple TextViews.

I want a TextView to go to a new line after 15 characters, every 15 characters. I tried using android:maxLength="15" but that just stopped the string at 15 characters. No new line or anything.

android newline character maxlength textview

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

When exactly do I use a struct (Dont tell me when I want things to be allocated on a stack)

A lot of times the answer is merely when I want things to be allocated on a stack instead of the heap.. assuming I dont know what the stack and the heap are (and please dont try to explain it here), when exactly should I be using structs instead of classes?

Here is the answer I've been giving out, but please tell me if I'm wrong or falling short of a better answer:

I create structs usually when I have …

c# struct

0
推荐指数
1
解决办法
298
查看次数

DOM节点上的事件处理程序是否会被节点删除?

(注意:我在下面使用jQuery,但问题实际上是一般的Javascript问题.)

假设我有一个div#formsection使用AJAX反复更新其内容的内容,如下所示:

var formSection = $('div#formsection');
var newContents = $.get(/* URL for next section */);
formSection.html(newContents);
Run Code Online (Sandbox Code Playgroud)

每当我更新这个div时,我会触发一个自定义事件,它将事件处理程序绑定到一些新添加的元素,如下所示:

// When the first section of the form is loaded, this runs...
formSection.find('select#phonenumber').change(function(){/* stuff */});

...

// ... when the second section of the form is loaded, this runs...
formSection.find('input#foo').focus(function(){/* stuff */});
Run Code Online (Sandbox Code Playgroud)

所以:我将事件处理程序绑定到某些DOM节点,然后删除这些DOM节点并插入新节点(html()这样做)并将事件处理程序绑定到新的DOM节点.

我的事件处理程序是否与它们绑定的DOM节点一起被删除?换句话说,当我加载新的部分时,很多无用的事件处理程序堆积在浏览器内存中,等待不再存在的DOM节点上的事件,或者当它们的DOM节点被删除时它们被清除了吗?

奖金问题:如何自己测试?

javascript dom javascript-events

32
推荐指数
2
解决办法
9937
查看次数

Jaxb生成的类使用JAXBElement而不是指定的类型

这个问题已被各种各样的问题提出来 - 但我觉得仍然有进一步编目的空间.

我有一个带有两个元素定义的xsd

<xs:complexType name="elementA">
   <xs:sequence>
      <xs:element name="date" type="xs:string" minOccurs="0"/>
      <xs:element name="lastXdigits" type="xs:string" nillable="true" minOccurs="0"/>
   </xs:sequence>
</xs:complexType>
Run Code Online (Sandbox Code Playgroud)

这会产生:

protected String date;
@XmlElementRef(name = "lastXdigits", namespace = "http://xxxxxxx", type = JAXBElement.class)
protected JAXBElement<String> lastXDigits;
Run Code Online (Sandbox Code Playgroud)

将xsd更改为:

<xs:element name="lastXdigits" type="xs:string" nillable="true" minOccurs="1"/>
Run Code Online (Sandbox Code Playgroud)

结果是:

protected String date;
@XmlElement(name = "lastXdigits", required = true, nillable = true)
protected String lastXDigits;
Run Code Online (Sandbox Code Playgroud)

和使用:

<xs:element name="lastXdigits" type="xs:string" minOccurs="0"/>
Run Code Online (Sandbox Code Playgroud)

结果是:

protected String date;
@XmlElement(name = "lastXdigits")
protected String lastXDigits;
Run Code Online (Sandbox Code Playgroud)

这对我来说似乎很奇怪.为什么在第一种情况下将lastXDigits生成为JAXBElement类型,为什么String类型在所有情况下都不够用?另外,当jaxb除了名称之外的定义相同时,为什么jaxb应该区别对待这两个元素呢?

我正在使用jaxb 2.0.5中的jaxb-xjc ant任务.

这看起来是否可疑或是否有充分的理由来解决这些差异?

java code-generation jaxb

9
推荐指数
1
解决办法
6046
查看次数

如何在Scala中"覆盖"内部类?

在Enumeration#Val类的Scaladoc中,我可以读到:"实现Value类型的类.可以重写此类以更改枚举的命名和整数标识行为." 我很困惑:如何覆盖一个类?override class Val extends super.Val不允许这样的事情.

enums overriding scala nested-class

9
推荐指数
1
解决办法
1131
查看次数

为什么主线程在继续之前等待另一个线程完成?

我在一个复杂的Java应用程序中遇到的问题归结为以下几点:主线程在子线程未完成之前不会继续,尽管我认为应该这样做.示例问题的代码如下所示:

public class ThreadTest {

        static class MyThread extends Thread{
            public void run(){
                for(double i = 0; i<1; i+=0.01){
                    System.out.println(Math.pow(Math.PI,Math.E)*100.0*i-234.0);
                }
            }
        }

        public static void main(String[] args){
            (new MyThread()).run();
            System.out.println("main thread");
        }
    }
Run Code Online (Sandbox Code Playgroud)

当我运行这个程序时,我总是首先从MyThread获取输出(独立于循环中有多少步骤),然后我从主线程获取消息.创建线程的想法是异步执行代码,但在这里我观察到一个明显同步的行为.我错过了什么?

提前致谢!

java multithreading

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