我写了一个小片段来计算给定节点的路径长度(例如它到根节点的距离):
def node_depth(node, depth=0, colored_nodes=set()):
"""
Return the length of the path in the parse tree from C{node}'s position
up to the root node. Effectively tests if C{node} is inside a circle
and, if so, returns -1.
"""
if node.mother is None:
return depth
mother = node.mother
if mother.id in colored_nodes:
return -1
colored_nodes.add(node.id)
return node_depth(mother, depth + 1, colored_nodes)
Run Code Online (Sandbox Code Playgroud)
现在这个函数发生了一件奇怪的事情(至少对我来说很奇怪):第一次调用node_depth会返回正确的值.但是,使用相同节点第二次调用它会返回-1.coloured_nodes集在第一次调用中为空,但包含第二次调用中已在第一次调用期间添加的所有节点ID:
print node_depth(node) # --> 9
# initially colored nodes --> set([])
print node_depth(node) # --> -1
# initially colored …Run Code Online (Sandbox Code Playgroud) 我正在使用CGRect来显示图像.我希望CGRect在没有指定的情况下使用图像的宽度和高度.
这可以:
CGRectMake(0.0f, 40.0f, 480.0f, 280.0f);
Run Code Online (Sandbox Code Playgroud)
变成这样:
CGRectMake(0.0f, 40.0f, myImage.width, myImage.height);
Run Code Online (Sandbox Code Playgroud)
指定参数时,某些图像会失真.
这是代码:
CGRect myImageRect = CGRectMake(0.0f, 40.0f, 480.0f, 280.0f);
UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect];
[myImage setImage:[UIImage imageNamed:recipe.img]];
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.
我为我们的站点编写了一个HttpModule,它通常接受请求并检查特定的文件扩展名以及特定会话变量的值.是否可以检测会话中的第一个请求?
我正在尝试运行以下内容.
<?php
$db = mysqli_connect("localhost","user","pw") or die("Database error");
mysqli_select_db($db, "database");
$agtid = $_POST['level'];
$sql = sprintf("call agent_hier(%d)", $agtid);
$result = mysqli_query($db, $sql) or exit(mysqli_error($db));
if ($result) {
echo "<table border='1'>
<tr><th>id</th>
<th>name</th>
<th>parent_id</th>
<th>parent_name</th>
<th>level</th>
<th>email</th></tr>";
while ($row = mysqli_fetch_assoc($result))
{
$aid = $row["id"];
$sql2 = "SELECT * FROM members WHERE MEMNO = '$aid'";
$result2 = mysqli_query($db,$sql2) or exit(mysqli_error($db));
while ($newArray = mysqli_fetch_array($result2)) {
$fname = $newArray['FNAME'];
$lname = $newArray['LNAME'];
$mi = $newArray['MI'];
$address = $newArray['ADDRESS'];
$city = $newArray['CITY'];
$state …Run Code Online (Sandbox Code Playgroud) 我正在做一些解决方案清理,并希望将一些Web引用从一个项目移动到另一个项目.VS2010不允许我将它们从一个项目拖放到另一个项目.移动它们最简单的方法是什么?如果重要的是这些是旧式的asmx Web服务,而不是WCF服务.
在iPad上,我在分割视图控制器的"细节"一侧呈现一个视图,它基本上只是一个UIWebView,它在应用程序包中加载一个HTML文件.应用程序支持旋转并隐藏/显示拆分的"主"侧.
当UIWebView最初以横向模式加载时,其内容似乎正确"大小"......内容高于屏幕,因此您可以垂直滚动,但不能水平滚动.(HTML内容几乎都是用CSS设置的文本,底部只有一个小的~300x50图像.)
如果您然后将屏幕旋转为纵向,HTML内容似乎仍然可以正常 - 垂直滚动条存在,但不是水平,因为它最初.旋转回景观,一切仍然很好.
到现在为止还挺好.
现在,如果UIWebView最初以纵向方向加载,则所有内容也都"正确"(垂直滚动条,没有水平).但是,如果将其旋转为横向,则内容会突然变为水平滚动条,因为其中一段文本比UIWebView的宽度宽.(并非巧合的是,我确定,但是UIWebView当它定向为肖像时,那个长段的尺寸完全适合于略大的宽度.)
我期待/假设iPad的旋转将导致UIWebView其框架被调整大小,并且当它被调整大小时,也适当地调整其HTML内容的大小.(想想拿一个Web浏览器窗口并缩小它.)为什么不发生这种情况?
我想避免使用"Scales Pages to Fit"属性,因为文本非确定性地缩小.
我在html文档中使用Unicode'CHECK MARK'(U + 2713).我发现它在大多数浏览器中都可以正常显示,但偶尔会遇到PC上缺少字体的人.如果字体丢失,是否有任何HTML/JS技巧来指定替代显示字符(或图像)?
使用依赖项注入容器时,执行resolve时会检测到缺少的依赖项.这是在运行时.
本文介绍了部分解决方案.它有助于简化测试,调试和维护,但仍需要执行测试来验证您的行为(特别是如果您使用抽象工厂子解决方案进行运行时解析):
http://blog.ploeh.dk/2010/02/03/ServiceLocatorIsAnAntiPattern.aspx
使用依赖注入容器时,有没有办法静态地确定所有依赖项都将被解析?
我总是认为具有display:noneCSS样式的元素为height()和返回0 width().
但在这个例子中:
<div id="target" style="display:none;">
a
</div>
Run Code Online (Sandbox Code Playgroud)
alert($("#target").height());
Run Code Online (Sandbox Code Playgroud)
他们没有:http://jsfiddle.net/Gts6A/2/
怎么会?我看到过去有很多次回来过.
delayed_job位于http://github.com/collectiveidea/delayed_job
delayed_job能否执行cron任务?比如每天凌晨1点运行一个脚本.或者每1小时运行一次脚本.
如果没有,有什么合适的宝石可以做到这一点?是否可以使用浏览器远程监控,并记录成功和错误?