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) 我需要转换字符串:
"There are 6 spaces in this string."
Run Code Online (Sandbox Code Playgroud)
至:
"Thereare6spacesinthisstring."
Run Code Online (Sandbox Code Playgroud) 在现有的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 …
我刚刚开始学习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应用程序的适当方法是什么?还是只是'不'?
哪种方法最佳,哪种方式可以获得更好的性能?
更新: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) 这是数据文件:
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中这样做.
如果我有a,b,c点与x,y的矢量形式,我怎么能找到共线点..
fabs((b.x_-a.x _)*(c.y_-a.y _) - (c.x_-a.x _)*(b.y_-a.y_)它的用法就像这样......怎么样这个?
我有宽度为500px的div,其中包含多个锚点...问题锚点没有包装到多行......我尝试使用表格同样的问题....
<div style="width:500px;">
<a href="#procrit">procrit</a>
<a href="#doxil">doxil</a>
<a href="#prezista">prezista</a>
<a href="#simponi">simponi</a>
<a href="#reopro">reopro</a>
<a href="#topamax">topamax</a>
<a href="#invega">invega</a>
<a href="#axert">axert</a>
<a href="#aciphex">aciphex</a>
<a href="#concerta">concerta</a>
<a href="#risperdal">risperdal</a>
<a href="#remicade">remicade</a>
<a href="#velcade">velcade</a>
<a href="#doxil">doxil</a>
<a href="#regranex">regranex</a>
<a href="#nucynta">nucynta</a>
<a href="#duragesic">duragesic</a>
<a href="#leustatin">leustatin</a>
<a href="#invega">invega</a>
<a href="#sustenna">sustenna</a>
<a href="#reminyl">reminyl</a>
<a href="#natrecor">natrecor</a>
</div>
Run Code Online (Sandbox Code Playgroud) 我喜欢能够使用shell脚本自动化我的计算机的想法,但我不知道我实际可以做什么.
您是否在服务器,个人计算机,上网本等上使用或者看过以新颖方式使用的shell脚本?
我想到的一些例子:
真的很想知道你可能要分享的内容,谢谢!
我正在编译这个方法:
#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)
任何人都可以看到问题出在哪里?
python ×2
.net ×1
android ×1
bash ×1
c ×1
c# ×1
c++ ×1
css ×1
ienumerable ×1
java ×1
javascript ×1
linq ×1
perl ×1
perl-context ×1
powershell ×1
python-3.x ×1
runnable ×1
shell ×1
sigils ×1
string ×1
tdd ×1
tkinter ×1
unit-testing ×1
vector ×1