我的instance_variable_get方法有问题,因为它总是返回一个对象实例为nil的对象。这是我的代码:
logger.info "ASDF: " + @d_tree.inspect
logger.info "ASDF: " + @d_tree.instance_variable_get(:@content);
Run Code Online (Sandbox Code Playgroud)
输出为:
ASDF: #<DTree id: 11, parent_id: nil, content: "bababababa", subsidiary_info: "", deep_info: "blabla", title: "hello", direction: 1, created_at: "2010-10-26 19:27:32", updated_at: "2010-11-01 23:14:31", color: 2, cell_color: 2, howtoinfo: "howtoinfooo", textinfo: "textInfooo", locationinfo: "locationInfoooo", productinfo: "productinfoooo">
TypeError (can't convert nil into String):
/app/controllers/d_trees_controller.rb:38:in `+'
Run Code Online (Sandbox Code Playgroud)
根据检查,该对象似乎很好,但是instance_variable_get返回一个nil对象
谢谢你的帮助!
我正在尝试设置一个包含4个div的div.我想设置容器的宽度和一些包含的div来设置值,但它们似乎只是取内容的宽度.
<html>
<head>
<style>
div {
border: 1px solid #888;
}
.container {
width: 300px;
position: relative;
}
.container div {
display: inline;
}
.div1 {
width: 20px;
overflow: hidden;
}
.div2 {
width: 80px;
overflow: hidden;
}
.div3 {
width: 160px;
overflow: hidden;
}
.div4 {
width: 20px;
overflow: hidden;
position: absolute;
top:0px;
right: 0px;
}
</style>
</head>
<body>
<div class="container">
<div class="div1"><img src="1x1.gif" width="1" height="1"/></div>
<div class="div2"><span>date</span></div>
<div class="div3"><span>text</span></div>
<div class="div4"><span>twistie</span></div>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
结果如下:
+--+----+----+------------------------+---+
| |date|text| …
Run Code Online (Sandbox Code Playgroud) 我有一个整数矩阵,应该像一个缓冲区:
x = {{0, 0, 0, 0, 0}, {1, 1, 1, 1, 1}, {2, 2, 2, 2, 2}};
现在,如果我添加一个新行{3, 3, 3, 3, 3}
,新矩阵应如下所示:
x = {{1, 1, 1, 1, 1}, {2, 2, 2, 2, 2}, {3, 3, 3, 3, 3}};
有没有一种巧妙的方法可以在不复制所有元素的情况下做到这一点?
我有一个日志文件,并希望创建一个网页(可能是Python但不严格),它将像unix"tail -f filename"命令一样工作(当它们被写入文件时显示新的日志行).
这样用户就可以在浏览器中不断看到日志.
你会如何实现这个?
当我阅读Guido van Rossum的文章"优化轶事"时,它就开始了.
决定在JavaScript中尝试相同的事情,我计时如下:
numbers.map(function(x){ return String.fromCharCode(x); });
Run Code Online (Sandbox Code Playgroud)
这已经非常快了,但为什么不完全消除匿名函数并将String.fromCharCode直接传递给map():
numbers.map(String.fromCharCode);
Run Code Online (Sandbox Code Playgroud)
我把它计时了...... 这比以前的版本慢了约100倍.怎么会?
以某种方式将此本机函数直接传递给Array.map()比将其包装到另一个函数中并将其传递给Array.map()慢得多.
它不是特定于浏览器:在Chrome,Firefox和Opera中测试过.
它不是特定于map():尝试forEach(),其行为类似.
它并不特定于内置函数:尝试过Math.round()和Math.sin() - 这些结果如人们所期望的那样:直接将函数传递给Array.map()比使用中间函数快一点匿名功能.
似乎问题出在String.fromCharCode上.
这里发生了什么?
PS.最初在Hacker News主题中提出了这个问题,但由于相关文章是关于Python的,我认为在发布时会更多地接触JavaScript开发人员.很抱歉交叉发布.
我有一个C++项目需要编辑.这是变量的声明:
// Attachment
OFSTRUCT ofstruct;
HFILE hFile = OpenFile( mmsHandle->hTemporalFileName , &ofstruct , OF_READ );
DWORD hFileSize = GetFileSize( (HANDLE) hFile , NULL );
LPSTR hFileBuffer = (LPSTR)GlobalAlloc(GPTR, sizeof(CHAR) * hFileSize );
DWORD hFileSizeReaded = 0;
ReadFile( (HANDLE) hFile , hFileBuffer, hFileSize, &hFileSizeReaded, NULL );
CloseHandle( (HANDLE) hFile );
Run Code Online (Sandbox Code Playgroud)
我需要检查文件是否附加(我想我需要检查hFile是否有任何值),但不知道如何.我尝试过,hFile == NULL
但这不起作用.
谢谢,
Ile
我想要一个属性到当前的项目ICollectionView
我该怎么办?将ICollectionView
用于绑定到一个组合框,我怎么可以绑定其他控件到ICollectionView
所选项目的?
我的大脑一直在我一直在研究的线段与圆柱体相交程序中融化。
/// Line segment VS <cylinder>
// - cylinder (A, B, r) (start point, end point, radius)
// - line has starting point (x0, y0, z0) and ending point (x0+ux, y0+uy, z0+uz) ((ux, uy, uz) is "direction")
// => start = (x0, y0, z0)
// dir = (ux, uy, uz)
// A
// B
// r
// optimize? (= don't care for t > 1)
// <= t = "time" of intersection
// norm = surface normal of intersection point …
Run Code Online (Sandbox Code Playgroud) TIMESTAMP WITH TIME ZONE
我的应用程序可以(或应该)将 Oracle 列类型映射到哪些 Java 数据类型TIMESTAMP WITH LOCAL TIME ZONE
?Oracle JDBC驱动程序可以将这些类型映射到Date
或Calendar
对象吗?是否Calendar
保留时区值Date
而不保留?
我使用SplitView模板创建了我的iPad应用程序.我想知道将我的应用程序限制为横向模式的最佳方法是什么?
我试过shouldAutorotateToInterfaceOrientation:
在DetailViewController.m中重写 方法
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
Run Code Online (Sandbox Code Playgroud)
但是4.2 GM仍然是有缺陷的,它无法显示控制器视图.我还有其他选择吗?
提前致谢.
UPDATE1
我已经提交了错误报告: 错误ID#8620135
我的应用程序几乎已经完成,我必须找到一个工作周期,因为我认为他们不会在4.2正式发布之前解决这个问题(GM已经出局!)
为了重新创建bug,只需在任何UIViewControllers(RootViewController或DetailViewControllers)中使用SplitView模板并覆盖上面的方法
UPDATE2
我找到了解决办法.(有关完整的解决方法,请参阅UPDATE3)
设置UISupportedInterfaceOrientations仅支持横向,这将强制应用程序以横向模式启动,允许DetailViewController正确启动(因此显示正确)
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
Run Code Online (Sandbox Code Playgroud)
但是如果你旋转设备,它会变成肖像模式!!!,所以仍然需要覆盖 shouldAutorotateToIntercafeOrientation
:如上所述
讨论:
如果这不是一个错误,我会期望在视图控制器不支持的方向启动应用程序时出现警告或执行错误,异常或其他问题.此外,为什么只有DetailViewController不显示?如果这是规范,那么RootViewController也应该无法加载.你不觉得吗?谢谢你的帮助...;)
UPDATE3
经过进一步测试后,我意识到上述解决办法在某些情况下不起作用.例如,当设备处于横向状态时启动应用程序将无法正常工作!真正的问题似乎是在iOS4.2GM中,UISplitViewController需要其所有控制器在其加载时具有所有旋转.因此有必要欺骗他,以便在横向模式下加载,然后不允许他旋转其视图控制器.
所以这是烦人的iBug的新解决方案.
第1步:像这样设置Info.plist:
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
Run Code Online (Sandbox Code Playgroud)
Step2在DetailViewController.m或.h中设置一个新标志(来自SplitView模板)
BOOL lockRotation = NO; //WORK-ARROUND: Bug ID# 8620135.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
//WORK-ARROUND: Bug ID# 8620135.
if (lockRotation) {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}else{
return YES;
}
}
- (void)viewDidLoad {
[super viewDidLoad];
//set NO here since this …
Run Code Online (Sandbox Code Playgroud) c++ ×2
optimization ×2
.net-3.5 ×1
3d ×1
c ×1
cocoa-touch ×1
css ×1
file ×1
html ×1
intersection ×1
ipad ×1
iphone ×1
java ×1
javascript ×1
jdbc ×1
landscape ×1
math ×1
matrix ×1
oracle ×1
orientation ×1
ruby ×1
shift ×1
sqldatatypes ×1
tail ×1
winapi ×1
wpf ×1