首先是一些代码:
import java.util.*;
//...
class TicTacToe
{
//...
public static void main (String[]arg)
{
Random Random = new Random() ;
toerunner () ; // this leads to a path of
// methods that eventualy gets us to the rest of the code
}
//...
public void CompTurn (int type, boolean debug)
{
//...
boolean done = true ;
int a = 0 ;
while (!done)
{
a = Random.nextInt(10) ;
if (debug) { int i = 0 ; while (i<20) …Run Code Online (Sandbox Code Playgroud) 我想创建一个bash脚本,它将启动两个进程并在第一个进程完成时终止第二个进程.这是一个例子:
#fork first process producer& #fork second process consumer& #wait for producer to finish ... #kill the consumer ...
我有一种感觉,这可能会变得丑陋,但有一个非常简单的解决方案.请帮我填空.
我在C#(.NET 2.0)中有一个大项目,它包含由SubSonic生成的非常大的代码块.像这样的尝试捕获导致可怕的性能打击?
for (int x = 0; x < identifiers.Count; x++)
{decimal target = 0;
try
{
target = Convert.ToDecimal(assets[x + identifiers.Count * 2]); // target %
}
catch { targetEmpty = true; }}
Run Code Online (Sandbox Code Playgroud)
发生的事情是,如果传入的给定字段不是可以转换为十进制的字段,则会设置一个标志,然后在记录中进一步使用该标志以确定其他内容.
问题是,当我通过30k记录进行解析时,应用程序实际上会抛出数以万计的异常.整个过程花了将近10分钟的时间来完成所有事情,我的总体任务是将时间改进一些,如果这是一个糟糕的设计理念,这似乎很容易挂起.
任何想法都会有所帮助(善良,这是一个悲惨的一天)
谢谢,克里斯
我有一个iPhone应用程序,我目前正在转换为通用二进制文件,以便与iPad配合使用.我已经成功实现了我在布局方面所需的一切,以便我的应用程序现在支持完整的横向功能(之前我主要使用纵向模式来显示内容).
但是,我有一个奇怪的问题,它只出现在横向模式下:当我将视图控制器推到堆栈上时,在后退按钮上需要两次点击才能返回到前一个视图控制器!第一次点击显示空白视图,但在左侧后退导航按钮上使用相同的名称,第二次点击将控制器恢复到之前的视图.
我没有iPad测试,所以我依靠模拟器.问题不会显示在iPhone上,如果您旋转回纵向模式则不会显示.
我的应用程序包含一个tabbarcontroller,其导航控制器为其vc加载:
//application delegate
- (void)applicationDidFinishLaunching:(UIApplication *)application
//....
WebHelpViewController *vc8 = [[WebHelpViewController alloc] init];
UINavigationController *nv8 = [[UINavigationController alloc] initWithRootViewController:vc8];
[self.tabBarController setViewControllers:[NSArray arrayWithObjects:nv1,nv2,nv3,nv4,nv5,nv6,nv7,nv8,nil]];
Run Code Online (Sandbox Code Playgroud)
要实现格局功能,将覆盖UITabBarController以在需要时自动旋转:
//CustomTabBarController.m
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return [[(UINavigationController *)self.selectedViewController topViewController] shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
Run Code Online (Sandbox Code Playgroud)
... 工作良好.我使用此方法导航到新视图
SomeViewController *vc = [[SomeViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
[vc release];
Run Code Online (Sandbox Code Playgroud)
这只是模拟错误吗?我该如何解决这个问题?
iphone uitabbarcontroller uinavigationcontroller popviewcontroller ipad
遇到AR 2.3.5的问题,例如:
users = User.all( :select => "u.id, c.user_id", :from => "users u, connections c",
:conditions => ... )
Run Code Online (Sandbox Code Playgroud)
返回,例如:
=> [#<User id: 1000>]
>> users.first.attributes
=> {"id"=>1000, "user_id"=>"1000"}
Run Code Online (Sandbox Code Playgroud)
请注意,AR返回id作为数字搜索的模型,但选择user_id的连接模型为a String,尽管两者都int(11)在数据库模式中.
我怎样才能更好地形成这种类型的查询来选择支持多个模型的表列并检索它们的自然类型而不是String?似乎AR正在这个地方撑船.如何在AR加载时强制返回类型,而不必.to_i在每个post-hoc访问上添加(等)?
我遇到的问题我很确定很简单.我一直在使用Asp.Net MVC,我决定开始使用Asp.Net MVC 2.有些事情发生了变化,现在我需要一些帮助.强类型助手现在写成这样 -
<%= Html.TextBoxFor(model => model.State) %>
Run Code Online (Sandbox Code Playgroud)
我需要在文本框中添加默认值.在Asp.Net MVC的早期版本中,很容易分配默认值.我认为以下操作可以在MVC 2-中工作
<%= Html.TextBoxFor(model => model.CountyId, new{ value = 840 })%>
Run Code Online (Sandbox Code Playgroud)
但是,这在Asp.Net MVC 2中对我不起作用.文本框的值仍为空白.我想确保这不是我遇到的一些随机错误.还有其他人遇到过同样的问题吗?我搜索并搜索了有关MVC 2中html助手的默认属性的更多信息,但我找不到任何东西.有没有人知道如何正确地将默认值分配给Asp.Net MVC 2中的文本框?
如果有任何DOM API搜索具有给定属性名称和属性值的元素,请告诉我:
就像是:
doc.findElementByAttribute("myAttribute", "aValue");
Run Code Online (Sandbox Code Playgroud) 有没有人知道那里的图书馆(最好是在C#中)会接受课程并生成适合亚马逊商城网络服务提要的XML或平面文件?
换句话说,我想做这样的事情:
var feed = new AmazonProductFeed();
var list = new AmazonProductList();
var product1 = new AmazonProduct();
product1.Name = "Product 1";
list.Add(product1);
var product2 = new AmazonProduct();
product2.Name = "Product 2";
list.Add(product2);
feed.Products = list;
// spits out XML compliant with Amazon's schema
Console.Write(feed.ToXml());
Run Code Online (Sandbox Code Playgroud)
看起来亚马逊提供的唯一代码是Web服务本身和基于目录的传输实用程序(AMTU)的包装器.
在我的应用程序中,我在表中创建动态行,就像在本教程中一样:http: //en.androidwiki.com/wiki/Dynamically_adding_rows_to_TableLayout
for(int i = startDay; i < startDay + 7; i++){
/* Create a TextView to be the row-content. */
TextView day = new TextView(this);
day.setText(Integer.toString(i));
day.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
day.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.i("Listener: ", "Click");
}
Run Code Online (Sandbox Code Playgroud)
所以现在当我单击TextView时我可以注册click事件,但是如何确定单击了哪个TextView?
不仅仅是我在事件中获得的对象,而是点击了哪一天的数据?
理想情况下,我希望将数据附加到我动态创建的每个视图.像Javascript jQuery中的data()方法.
现在我只能看到解决这个问题的一种方法 - 创建TextView时添加带数据的id,点击时 - 获取id并解析它以获取我的数据.但它让我感到丑陋.
有没有办法将任意数据附加到android视图?