出于学习目的,我正在研究在Perl中构建事件驱动程序的想法,并注意到如果注册为事件处理程序的子例程在失败时只能为其自身安排另一个调用它可能会很好时间.到目前为止,我想出了类似的东西:
my $cb;
my $try = 3;
$cb = sub {
my $rc = do_stuff();
if (!$rc && --$try) {
schedule_event($cb, 10); # schedule $cb to be called in 10 seconds
} else {
do_other_stuff;
}
};
schedule_event($cb, 0); # schedule initial call to $cb to be performed ASAP
Run Code Online (Sandbox Code Playgroud)
有没有办法让sub中的代码可以访问该sub的coderef,所以我可以不使用额外的变量?我想安排这样的初始通话.
schedule_event( sub { ... }, 0);
Run Code Online (Sandbox Code Playgroud)
我首先考虑使用caller(0)[3],但这只给了我一个函数名称(__ANON__如果没有名称),而不是附加了pad的代码引用.
如果您正在开发一个大型的进化多模块maven项目,那么在poms中给出一些不必要的依赖关系似乎是不可避免的,因为它们被其他依赖项传递包含在内.例如,如果你有一个最初包含C的模块A,就会发生这种情况.稍后你重构并让A依赖于模块B,而模块B又取决于C.如果你不够小心,你最终会同时使用B和C A的依赖列表.但是当然你不需要将C放入A的pom中,因为无论如何它都是可传递的.是否有工具可以找到这种不必要的依赖项?
(这些依赖关系实际上并没有受到伤害,但它们可能会模糊您的实际模块结构,并且在pom中使用较少的东西通常会更好.:-)
我将应用程序移植到C中的ARM平台,该应用程序也在x86处理器上运行,并且必须向后兼容.
我现在有一些变量对齐的问题.我已经阅读了gcc手册,因为
__attribute__((aligned(4),packed))我解释了所说的内容,因为struct的开头与4字节边界对齐,并且由于packed语句,内部保持不变.
最初我有这个,但偶尔它与4字节边界不对齐.
typedef struct
{
unsigned int code;
unsigned int length;
unsigned int seq;
unsigned int request;
unsigned char nonce[16];
unsigned short crc;
} __attribute__((packed)) CHALLENGE;
Run Code Online (Sandbox Code Playgroud)
所以我把它改成了这个.
typedef struct
{
unsigned int code;
unsigned int length;
unsigned int seq;
unsigned int request;
unsigned char nonce[16];
unsigned short crc;
} __attribute__((aligned(4),packed)) CHALLENGE;
Run Code Online (Sandbox Code Playgroud)
该明白我前面所说似乎是不正确的,这两个结构是现在对齐到4字节边界,和现在的内部数据对齐到四个字节边界,但因为尾结构,该结构的大小已增加大小从42到44个字节.这个大小是至关重要的,因为我们有其他依赖于结构为42字节的应用程序.
有些人可以向我描述如何执行我需要的操作.任何帮助深表感谢.
我有两个表:
我想从用户表中选择所有值,但我想显示特定用户的状态(例如id = 2),而其他用户保持为NULL。例如:如果我有用户:
? first_name last_name
------------------------
1 John Smith
2 Tom Summers
3 Amy Wilson
Run Code Online (Sandbox Code Playgroud)
在网络中:
user_id friend_id status
------------------------------
2 1 friends
Run Code Online (Sandbox Code Playgroud)
我想搜索所有其他用户的John Smith,所以我想得到:
id first_name last_name status
------------------------------------
2 Tom Summers friends
3 Amy Wilson NULL
Run Code Online (Sandbox Code Playgroud)
我尝试先执行LEFT JOIN,然后执行WHERE语句,但是它不起作用,因为它排除了与其他用户(而非该用户)有关系的行。
我可以使用UNION语句来执行此操作,但是我想知道如果没有UNION的话是否有可能做到这一点。
我的资源中有img1和img2.我很容易在btn属性中将btn.backgroundImage设置为img1.图像路径是:c:\ Project\Resources ...
现在我不知道如何将btn.backgroundImage设置为img2,我想在事件"MouseEnter"上进行.所以我会提供完整的代码,因为我对此非常了解......
我赞成任何给定的想法......
是否可以以任何方式在Silverlight中使用Windows phone 7的相机?
我在做一些蠢事吗?我可以预先填写并发送电子邮件,但在电子邮件中忽略"\ r \n":
- (void) sendEventInEmail
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
NSString *emailSubject = [eventDictionary objectForKey:EVENT_NAME_KEY];
[picker setSubject:emailSubject];
// Fill out the email body text
NSString *iTunesLink = @"http://itunes.apple.com/gb/app/whats-on-reading/id347859140?mt=8"; // Link to iTune App link
NSString *content = [eventDictionary objectForKey:@"Description"];
NSString *emailBody = [NSString stringWithFormat:@"%@\r\nSent using <a href = '%@'>What's On Reading</a> for the iPhone.", content, iTunesLink];
[picker setMessageBody:emailBody isHTML:YES];
picker.navigationBar.barStyle = UIBarStyleBlack;
[self presentModalViewController:picker animated:YES];
[picker release];
}
Run Code Online (Sandbox Code Playgroud)
问候
戴夫
我遇到了if语句不起作用的问题.在第一个代码行之后,变量包含值"(null)",因为从他的iphone地址簿中选择联系人的用户没有为此联系人设置国家/地区密钥,所以这么好.
但如果我检查变量,它将不会是真的,但值肯定是"(null)"...有人有想法吗?
NSString *country = [NSString [the dict objectForKey:(NSString *)kABPersonAddressCountryKey]];
if(country == @"(null)")
{
country = @"";
}
Run Code Online (Sandbox Code Playgroud)
谢谢提前
肖恩
我有两个实体:患者和工作.患者与Job有很多关系称为"工作",Job与患者有一对一的关系称为"患者".Job具有名为'dueDate'(Date)和'completed'(BOOL)的属性,Patient具有属性'firstName'和'lastName'(两个字符串).
我正在尝试为我的NSFetchedResultsController创建一个获取请求/谓词,我们抓取所有尚未完成的作业(即已完成==否)并按患者姓名划分它们.这是我的代码:
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Job" inManagedObjectContext:moc];
[fetchRequest setEntity:entity];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(completed == NO)"];
[fetchRequest setPredicate:predicate];
NSSortDescriptor *patientDescriptor = [[NSSortDescriptor alloc] initWithKey:@"patient" ascending:YES];
NSSortDescriptor *dueDateDescriptor = [[NSSortDescriptor alloc] initWithKey:@"dueDate" ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:patientDescriptor, dueDateDescriptor, nil];
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:moc sectionNameKeyPath:@"patient" cacheName:@"Jobs"];
Run Code Online (Sandbox Code Playgroud)
这是我的titleForHeaderInSection方法:
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:section];
NSString *firstName = [[(Job *)[fetchedResultsController objectAtIndexPath:indexPath] patient] firstName];
NSString *lastName = [[(Job *)[fetchedResultsController objectAtIndexPath:indexPath] patient] lastName];
return …Run Code Online (Sandbox Code Playgroud) iphone core-data objective-c uitableview nsfetchedresultscontroller
iphone ×3
arm ×1
button ×1
c ×1
c# ×1
c++ ×1
core-data ×1
dependencies ×1
gcc ×1
gcc4 ×1
if-statement ×1
image ×1
maven-2 ×1
mfmailcomposeviewcontroller ×1
modularity ×1
module ×1
null ×1
objective-c ×1
perl ×1
pointers ×1
silverlight ×1
sql ×1
uitableview ×1