我有这个小功能:
// Adds to menu
public void addMenuToList(int menuVal, string menuTxt, int depth, bool hasChildren)
{
for (int i = 0; i < depth; i++)
{
menuTxt = " " + menuTxt;
}
if (hasChildren) { menuTxt = " + " + menuTxt; }
ListItem newItem = new ListItem();
newItem.Text = menuTxt;
newItem.Value = menuVal.ToString();
parent.Items.Add(newItem);
}
Run Code Online (Sandbox Code Playgroud)
然后继续创建以下HTML:
<select size="4" name="ctl00$mainContent$parent" id="ctl00_mainContent_parent" class="tbox widebox">
<option selected="selected" value="0">Top Level</option>
<option value="1"> + Boxes</option>
<option value="2">&nbsp;&nbsp;Wrapping</option>
<option value="8"> + &nbsp;&nbsp;&nbsp;&nbsp;All Products</option>
</select>
Run Code Online (Sandbox Code Playgroud)
这是编码的URL …
我正在开发一个Android应用程序,您应该可以浏览餐馆.
我从服务中检索关于餐馆的信息,它们不是本地存储在设备上的.但我希望允许用户将餐馆添加到他/她的收藏夹中.
在设备上存储此类信息的"最佳"方式是什么?我应该使用共享首选项还是Sqlite数据库?还是其他任何建议?
我正在使用Ryan Bate的CanCan gem来定义能力,而一些基本功能正在失败.我有一个产品型号和产品控制器,我的索引操作如下所示:
def index
@req_host_w_port = request.host_with_port
@products = Product.accessible_by(current_ability, :index)
end
Run Code Online (Sandbox Code Playgroud)
当我尝试使用该accessible_by方法检索产品时出现错误,我收到此错误:
Cannot determine SQL conditions or joins from block for :index Product(id: integer, secret: string, context_date: datetime, expiration_date: datetime, blurb: text, created_at: datetime, updated_at: datetime, owner_id: integer, product_type_id: integer, approved_at: datetime)
Run Code Online (Sandbox Code Playgroud)
我的能力课看起来像这样:
can :index, Product do |product|
product && !!product.approved_at
end
Run Code Online (Sandbox Code Playgroud)
这看起来像一个非常简单的例子,所以我很惊讶它失败了,想知道我是否忽略了一些简单的事情(即我盯着我的代码太长时间).
我做了更多的探测并进行了一个简单的测试.如果你看下面的代码,一个例子工作正常,一个失败,他们应该实际做同样的事情.
# This works
can :index, Product, :approved_at => nil
# This fails
can :index, Product do |product|
product && product.approved_at.nil?
end
Run Code Online (Sandbox Code Playgroud)
所以问题似乎在于CanCan正在处理这些块的方式.我更深入地进入库并找到错误的位置 …
我正在努力进行打印和unicode转换.这是在2.5 windows解释器中执行的一些代码.
>>> import sys
>>> print sys.stdout.encoding
cp850
>>> print u"é"
é
>>> print u"é".encode("cp850")
é
>>> print u"é".encode("utf8")
?®
>>> print u"é".__repr__()
u'\xe9'
>>> class A():
... def __unicode__(self):
... return u"é"
...
>>> print A()
<__main__.A instance at 0x0000000002AEEA88>
>>> class B():
... def __repr__(self):
... return u"é".encode("cp850")
...
>>> print B()
é
>>> class C():
... def __repr__(self):
... return u"é".encode("utf8")
...
>>> print C()
?®
>>> class D():
... def __str__(self):
... return u"é"
... …Run Code Online (Sandbox Code Playgroud) 我的程序中有一个主线程和一个单独的线程.如果单独的线程在主线程之前完成,它应该自动释放.如果主线程首先完成,它应该释放单独的线程.
我知道FreeOnTerminate,我读过你必须小心使用它.
我的问题是,以下代码是否正确?
procedure TMyThread.Execute;
begin
... Do some processing
Synchronize(ThreadFinished);
if Terminated then exit;
FreeOnTerminate := true;
end;
procedure TMyThread.ThreadFinished;
begin
MainForm.MyThreadReady := true;
end;
procedure TMainForm.Create;
begin
MyThreadReady := false;
MyThread := TMyThread.Create(false);
end;
procedure TMainForm.Close;
begin
if not MyThreadReady then
begin
MyThread.Terminate;
MyThread.WaitFor;
MyThread.Free;
end;
end;
Run Code Online (Sandbox Code Playgroud) 我需要创建一个Robotium应用程序,它将使用"设置"应用程序从菜单设置 - >无线和网络 - > Wi-Fi打开/关闭WIFi.我设法在这里找到一些示例代码,演示如何通过仅使用apk文件启动应用程序.问题是我的Robotium应用程序应该与(系统)设置应用程序具有相同的签名.在尝试运行应用程序时,我收到错误消息:
测试运行失败:权限拒绝:从pid = 354开始检测ComponentInfo {com.jayway.test/android.test.InstrumentationTestRunner},因为包com.jayway.test没有与目标com匹配的签名,所以不允许使用uid = 354. android.settings
代码在许多地方说"无效的间接".请帮忙.
int main()
{
char *s1,*s2,*position;
printf("Enter string:\n");
gets(s1);
printf("Enter word to find:\n");
gets(s2);
*position=ststr(*s1,*s1);
if(*position)
printf("word is found at %c loc\n",*position);
else
printf("word not found");
getch();
return 0;
}
char *strstr(char *s1,char *s2)
{
int flag=1;
char i,j;
for(i=0; ;i++)
{
if(*s1[i]==*s2[0])
for(j=i;*s2;j++)
{
if(*s1[j]!=*s2[j])
flag=0;
}
}
if(flag)
return i;
else
return 0;
}
Run Code Online (Sandbox Code Playgroud) 在我的CSS文件中,我使用这个:
html,body{height:100%;padding:0;margin:0;border:0;}
Run Code Online (Sandbox Code Playgroud)
这导致垂直滚动条出现在IE8,Chrome 5和Mozilla 3.6上,所有最新版本.
此外,该文档是空的,它只有html,head和body标签,所以没有任何东西离开屏幕导致.
设置溢出:隐藏; 在html元素上将完全停止在页面上滚动.
如何让它消失,但是当内容高于显示高度时还要滚动?
谢谢.
我想知道一些代码块执行了多长时间.像这样的东西:
startStopwatch();
// do some calculations
stopStopwatch();
printf("%lf", timeMesuredInSeconds);
Run Code Online (Sandbox Code Playgroud)
怎么样?