有没有更好的方法在Mercurial中提取当前版本哈希值
hg log -l1|grep changeset|cut -d: -f3
?
我的部分webapp部署脚本使用其唯一的修订哈希"标记"上传的应用程序tarball.
我正在使用OCMock 1.70,并且在模拟返回BOOL值的简单方法时出现问题.这是我的代码:
@interface MyClass : NSObject
- (void)methodWithArg:(id)arg;
- (BOOL)methodWithBOOLResult;
@end
@implementation MyClass
- (void)methodWithArg:(id)arg {
NSLog(@"methodWithArg: %@", arg);
}
- (BOOL)methodWithBOOLResult {
NSLog(@"methodWithBOOLResult");
return YES;
}
@end
- (void)testMock {
id real = [[[MyClass alloc] init] autorelease];
[real methodWithArg:@"foo"];
//=> SUCCESS: logs "methodWithArg: foo"
id mock = [OCMockObject mockForClass:[MyClass class]];
[[mock stub] methodWithArg:[OCMArg any]];
[mock methodWithArg:@"foo"];
//=> SUCCESS: "nothing" happens
NSAssert([real methodWithBOOLResult], nil);
//=> SUCCESS: logs "methodWithBOOLResult", YES returned
BOOL boolResult = YES;
[[[mock stub] andReturn:OCMOCK_VALUE(boolResult)] methodWithBOOLResult];
NSAssert([mock methodWithBOOLResult], …Run Code Online (Sandbox Code Playgroud) 当使用它来管理多对多关系时,Apple的文档-setPrimitiveValue:forKey:在两个方面含糊不清.
首先他们说:
如果您尝试设置与新NSMutableSet对象的多对多关系,它将(最终)失败.
最后?那有什么意思?它会在以后失败-[NSManagedObjectContext save:]吗?当托管对象变成故障然后再回来时?什么时候?我是否可以编写一个测试用例来持续按需重新创建失败?
其次,提供示例代码以正确处理这种情况,他们写道:
首先使用现有的set
primitiveValueForKey:(确保方法不返回nil)
我应该怎么做,如果/当方法不返回零?assert()它并立即失败,因为这意味着整个对象图已损坏,保存将导致数据丢失?NSAssert()在它上面作为对来电者的警告,但按下(默默无为)?
现在我只是NS[Mutable]Set在那种情况下直接分配我想要的东西,就像这样:
- (void)setChildren:(NSSet*)value_ {
NSMutableSet *mutableRelationshipSet = [[[self primitiveValueForKey:@"children"] mutableCopy] autorelease];
if (mutableRelationshipSet) {
[mutableRelationshipSet setSet:value_];
[self setPrimitiveValue:mutableRelationshipSet forKey:@"children"];
} else {
[self setPrimitiveValue:value_ forKey:@"children"];
}
}
Run Code Online (Sandbox Code Playgroud)
那是错的吗?
从评论processIdentifier中NSRunningApplication.h:
并非所有应用程序都有pid.
咦?
我可以在NSRunningApplication表示已终止进程(runningProcess.terminated == YES)的特定情况下看到这种情况,但我想不到正在运行的应用程序没有进程ID的示例.这就是Unix 101.
文档错误或我错过了什么?
nginx的变化0.8.35 2010年4月1日
Run Code Online (Sandbox Code Playgroud)*) Change: now the charset filter runs before the SSI filter. *) Feature: the "chunked_transfer_encoding" directive.
这很好,因为我试图通过nginx反向代理将git更改推送到git-http-backend进程.由于客户端效率原因, Git HTTP利用了分块传输编码.
但是,我无法让它发挥作用.我在Debian Lenny上使用nginx 0.8.44并进行以下配置调用:
./configure \
--sbin-path=/usr/sbin \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--user=www-data \
--group=www-data \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-http_realip_module
Run Code Online (Sandbox Code Playgroud)
以下conf文件:
server {
server_name example.com;
location / {
proxy_pass http://192.168.0.10;
include /etc/nginx/proxy.conf;
chunked_transfer_encoding on;
}
}
Run Code Online (Sandbox Code Playgroud)
我proxy.conf看起来像这样:
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header …Run Code Online (Sandbox Code Playgroud) 有没有办法检测用户在执行javascript书签时是否按住shift键(或其他修饰键)?
在我对Safari 3.1和Firefox 3的测试中,window.event总是未定义的.
在Xcode 6b3上使用Swift时,我只是简单地插入一个具有一对一关系的NSManagedObject.
我把我在GitHub上的摄制,但失败的代码(在SwiftCoreDataRelationshipReproTests.swift的testSwiftToOne单元测试方法)归结为:
let momURL : NSURL = NSBundle.mainBundle().URLForResource("SwiftCoreDataRelationshipRepro",
withExtension: "momd")
let mom : NSManagedObjectModel = NSManagedObjectModel(contentsOfURL: momURL)
let psc : NSPersistentStoreCoordinator = NSPersistentStoreCoordinator(managedObjectModel: mom);
let ps : NSPersistentStore = psc.addPersistentStoreWithType(
NSInMemoryStoreType,
configuration: nil,
URL: nil,
options: nil,
error: nil)
let moc : NSManagedObjectContext = NSManagedObjectContext()
moc.persistentStoreCoordinator = psc
// This throws an NSInvalidArgumentException: "An NSManagedObject of class 'NSManagedObject' must have a valid NSEntityDescription."
NSManagedObject(
entity: NSEntityDescription.entityForName("Pet", inManagedObjectContext: moc),
insertIntoManagedObjectContext: moc)
Run Code Online (Sandbox Code Playgroud)
这似乎应该有效.没有什么棘手的.
我Person …
我知道Objective-C不允许您使用C数组作为属性类型.在这种情况下,我得到了我期望的编译器错误.
但我对结构属性中的C数组的行为感到惊讶:
info malloc不知道它,不确定它是否是未初始化的内存或什么.但我会发现崩溃或显然工作,虽然内存损坏).我把它煮成了这个示例代码:
#import <Foundation/Foundation.h>
#ifndef sizeofA
#define sizeofA(array) (sizeof(array)/sizeof(array[0]))
#endif
@interface IncludeCArrayDirectly : NSObject // Doesn't even compile
// Uncomment below to see the compilation error for yourself.
//@property(nonatomic, assign) int8_t f[9]; // ERROR: Property cannot have array or function type 'int8_t [9]'
@end
@interface IncludeCArrayInStruct : NSObject // Compiles (no warning) and runs but is amazingly broken.
@property(nonatomic, assign) int normalProperty;
@property(nonatomic, assign) struct { int f[9]; } p;
- (void*)normalPropertysAddress;
@end …Run Code Online (Sandbox Code Playgroud) cocoa ×3
core-data ×2
objective-c ×2
arrays ×1
bookmarklet ×1
firefox ×1
hash ×1
ivar ×1
javascript ×1
keyboard ×1
mercurial ×1
nginx ×1
ocmock ×1
pid ×1
properties ×1
revision ×1
safari ×1
swift ×1
unit-testing ×1
unix ×1