问题列表 - 第38260页

查询之间不保留对IEnumerable的更改

IEnumerable是一个懒惰评估的查询.但显然我的理解有点瑕疵.我希望以下工作:

        // e.Result is JSON from a server
        JObject data = JObject.Parse(e.Result);
        JsonSerializer serializer = new JsonSerializer();

        // LINQ query to transform the JSON into Story objects
        var stories = data["nodes"].Select(
                   obj => obj["node"]).Select(
                        storyData => storyOfJson(serializer, storyData));

        // set a value on each story returned by the query
        foreach (Story story in stories)
        {
            story.Vid = vid;
        }

        // run through the query again, making sure the value was actually set
        foreach (Story story in stories)
        {
            // …
Run Code Online (Sandbox Code Playgroud)

.net c# linq ienumerable

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

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

Runnable已成功发布但未运行

在现有的Android项目中,我遇到了以下代码(我插入了调试垃圾)

ImageView img = null;

public void onCreate(...) {

    img = (ImageView)findViewById(R.id.image);

    new Thread() {
        public void run() {
            final Bitmap bmp = BitmapFactory.decodeFile("/sdcard/someImage.jpg");
            System.out.println("bitmap: "+bmp.toString()+" img: "+img.toString());
            if ( !img.post(new Runnable() {
                public void run() {
                    System.out.println("setting bitmap...");
                    img.setImageBitmap(bmp);
                    System.out.println("bitmap set.");
                }
            }) ) System.out.println("Runnable won't run!");
            System.out.println("runnable posted");
        }
    }.start();
Run Code Online (Sandbox Code Playgroud)

Android开发的新手,并且已经开始搜索,我知道这是在不阻塞主(UI)线程的情况下执行操作的方法,同时仍然在解码后在UI线程上设置图像.(至少根据android-developers)(我已通过Thread.currentThread().getName()在各个地方登录验证)

现在有时图像不会出现,stdout只说

I/System.out( 8066): bitmap: android.graphics.Bitmap@432f3ee8 img: android.widget.ImageView@4339d698
I/System.out( 8066): runnable posted
Run Code Online (Sandbox Code Playgroud)

没有来自Runnable的消息的痕迹.所以看起来Runnable没有run(),尽管img.post()返回true.拉入ImageView onCreate()并声明它final …

java multithreading android runnable

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

如何在Tkinter应用程序上运行unittest?

我刚刚开始学习TDD,我正在使用Tkinter GUI开发一个程序.唯一的问题是,一旦.mainloop()调用该方法,测试套件就会挂起,直到窗口关闭.

这是我的代码示例:

# server.py
import Tkinter as tk

class Server(tk.Tk):
    def __init__(self):
        tk.Tk.__init__(self)
        self.mainloop()
Run Code Online (Sandbox Code Playgroud)

# test.py
import unittest
import server

class ServerTestCase(unittest.TestCase):
    def testClassSetup(self):
       server.Server()
       # and of course I can't call any server.whatever functions here

if __name__ == '__main__':
    unittest.main()
Run Code Online (Sandbox Code Playgroud)

测试Tkinter应用程序的适当方法是什么?还是只是'不'?

python tdd unit-testing tkinter

19
推荐指数
2
解决办法
6364
查看次数

JavaScript闭包与全局变量

哪种方法最佳,哪种方式可以获得更好的性能?

更新:jsperf.com报道(a)更快@ http://jsperf.com/closure-vs-global-variable

a)使用封闭物

var obj = {
    init: function() {
        var self = this;
        $('#element').click(function() {
            self.clickEvent();
        });
    },
    clickEvent: function() {
        this.miscMethod();
    },
    miscMethod: function() {}
};
Run Code Online (Sandbox Code Playgroud)

b)使用全局变量

var obj = {
    init: function() {
        // removed self=this closure
        $('#element').click(this.clickEvent); // simple method handler
    },
    clickEvent: function() {
        obj.miscMethod(); // global variable used
    },
    miscMethod: function() {}
};
Run Code Online (Sandbox Code Playgroud)

javascript

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

在Mathematica中阅读此类文件

这是数据文件:

ID  YR  MO  DA  YrM  MoM  DaM  
100  2010  2  20  2010  8  30  
110  2010  4  30  2010  9  12     
112  2010  8  20  2010  10  28  
Run Code Online (Sandbox Code Playgroud)

我应该能够访问此文件中的每个元素,我试图在Mathematica中创建记录时使用此函数但我收到错误

ReadList["testA.txt", Number, RecordLists -> true]

Error: ReadList::opttf: Value of option RecordLists -> true should be True or False.
Run Code Online (Sandbox Code Playgroud)

另外,如何在完成记录后访问每个元素?

Mathematica中还有一种方法可以创建一个列,它可以在两个日期之间产生差异并将其放入新列中.

这个家庭作业允许使用excel来计算,但我必须在Mathematica中这样做.

wolfram-mathematica

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

共线点

如果我有a,b,c点与x,y的矢量形式,我怎么能找到共线点..

fabs((b.x_-a.x _)*(c.y_-a.y _) - (c.x_-a.x _)*(b.y_-a.y_)它的用法就像这样......怎么样这个?

c c++ vector

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

Css div宽度问题

我有宽度为500px的div,其中包含多个锚点...问题锚点没有包装到多行......我尝试使用表格同样的问题....

<div  style="width:500px;">
    <a href="#procrit">procrit</a>&nbsp;
    <a href="#doxil">doxil</a>&nbsp;
    <a href="#prezista">prezista</a>&nbsp;
    <a href="#simponi">simponi</a>&nbsp;
    <a href="#reopro">reopro</a>&nbsp;
    <a href="#topamax">topamax</a>&nbsp;
    <a href="#invega">invega</a>&nbsp;
    <a href="#axert">axert</a>&nbsp;
    <a href="#aciphex">aciphex</a>&nbsp;
    <a href="#concerta">concerta</a>&nbsp;
    <a href="#risperdal">risperdal</a>&nbsp;
    <a href="#remicade">remicade</a>&nbsp;
    <a href="#velcade">velcade</a>&nbsp;
    <a href="#doxil">doxil</a>&nbsp;
    <a href="#regranex">regranex</a>&nbsp;
    <a href="#nucynta">nucynta</a>&nbsp;
    <a href="#duragesic">duragesic</a>&nbsp;
    <a href="#leustatin">leustatin</a>&nbsp;
    <a href="#invega">invega</a>&nbsp;
    <a href="#sustenna">sustenna</a>&nbsp;
    <a href="#reminyl">reminyl</a>&nbsp;
    <a href="#natrecor">natrecor</a>&nbsp;
</div>
Run Code Online (Sandbox Code Playgroud)

css

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

什么是有趣的shell脚本?

我喜欢能够使用shell脚本自动化我的计算机的想法,但我不知道我实际可以做什么.

您是否在服务器,个人计算机,上网本等上使用或者看过以新颖方式使用的shell脚本?

我想到的一些例子:

  • 优化电池寿命:关闭服务,修改亮度,关闭可能保持开放但不必要的程序等
  • 创建工作区配置文件:打开一组应用程序并执行学校,工作等操作.
  • 在其他人的电脑上恶作剧:你觉得有些有趣...... :)

真的很想知道你可能要分享的内容,谢谢!

bash shell powershell

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

Perl编译困境

我正在编译这个方法:

#changes the names of the associations for $agentConf
#where the key value pairs in %associationsToChangeDict are the old and new values respectively
sub UpdateConfObjectAssociations{
    my($agentConf, %associationsToChangeDict) = @_;

    foreach my $association ($agentConf->GetAssociations()) {
        if ( grep {$_ eq $association->Name()} keys %associationsToChangeDict) {
            my $newValue = %associationsToChangeDict{$association->Name()};
            $association->Value($newValue);
        } 
    }   
}
Run Code Online (Sandbox Code Playgroud)

这是错误消息:

syntax error at D:\Install\AutoDeployScripts\scripts\Perl/.\AI\SiteMinderHelper
.pm line 75, near "%associationsToChangeDict{"
syntax error at D:\Install\AutoDeployScripts\scripts\Perl/.\AI\SiteMinderHelper
.pm line 79, near "}"
Run Code Online (Sandbox Code Playgroud)

任何人都可以看到问题出在哪里?

perl sigils perl-context

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