This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'rubygems' | |
require 'open4' | |
# catch SIGCHLD (child process terminated) signals and handle them | |
trap("CHLD") do | |
begin | |
Process.wait(-1, Process::WNOHANG) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSDictionary * args = [[NSDictionary alloc] initWithObjectsAndKeys: [NSNumber numberWithDouble: self.pageRange.start], @"START", [NSNumber numberWithDouble: self.pageRange.end], @"END", self.contentItem.contentID, @"CONTENT_ID", [self.chapterInfo.destinationURL path], @"FILE_NAME", nil]; | |
static NSPredicate * template = nil; | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
template = [[NSPredicate predicateWithFormat: @"(pageStartPercent BETWEEN {$START, $END} OR pageEndPercent BETWEEN {$START, $END}) AND SUBQUERY(chapter, $chapter, $chapter.contentID == $CONTENT_ID AND $chapter.chapterFileName == $FILE_NAME).@count > 0"] retain]; | |
}); | |
[myFetchRequest setPredicate: [template predicateWithSubstitutionVariables: args]]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (void) initialize | |
{ | |
if ( self != [KBCommentEditorView class] ) | |
return; | |
// install the device-appropriate version of -layoutSubviews | |
Method m1 = class_getInstanceMethod(self, @selector(layoutSubviews)); | |
Method m2 = class_getInstanceMethod(self, IsPad() ? @selector(layoutSubviewsIPad) : @selector(layoutSubviewsIPhone)); | |
method_exchangeImplementations(m1, m2); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (NSFetchRequest *) findPageNoteWithRangeRequestWithVariables: (NSDictionary *) variables context: (NSManagedObjectContext *) context | |
{ | |
// template does something like the following: | |
/* | |
$pageLen = ($pageEnd - $pageStart); | |
$halfPageLen = $pageLen / 2; | |
$boundStart = $PAGE_START - $halfPageLen; | |
$boundEnd = $PAGE_END + $halfPageLen; | |
return "(contentItem.contentID == $CONTENT_ID) AND (chapterFileName == $CHAPTER_FILE_NAME) AND (pageStart BETWEEN {$boundStart, $PAGE_END}) AND (pageEnd BETWEEN {$PAGE_START, $boundEnd})"; | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.m | |
// BlocksRuntime | |
// | |
// Created by Jim Dovey on 11-07-22. | |
// Copyright 2011 Jim Dovey. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[managedObjectContext setMergePolicy: NSMergeByPropertyObjectTrumpMergePolicy]; | |
[managedObjectContext setPersistentStoreCoordinator: coordinator]; | |
- StoreManagedObjectContextForCurrentThread( managedObjectContext ); // store in thread dictionary | |
+ | |
+ if ( [NSThread isMainThread] ) | |
+ StoreManagedObjectContextForCurrentThread(managedObjectContext); // store in thread dictionary | |
+ else | |
+ dispatch_sync(dispatch_get_main_queue(), ^{ StoreManagedObjectContextForCurrentThread(managedObjectContext); }); | |
// set some flags in the store metadata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#import <dispatch/dispatch.h> | |
#import "MAZeroingWeakRef.h" | |
@interface KBMultiDispatchSource : NSObject | |
{ | |
dispatch_source_t _dispatch; | |
dispatch_queue_t _queue; | |
dispatch_source_type_t _type; | |
CFMutableDictionaryRef _eventObservers; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (void) load | |
{ | |
if ( dispatch_barrier_async == 0 ) | |
return; | |
// switch in the dispatch_barrier_async() versions since they're available | |
Method m1 = class_getInstanceMethod(self, @selector(handleEventsForObserver:usingBlock:)); | |
Method m2 = class_getInstanceMethod(self, @selector(_barrier_handleEventsForObserver:usingBlock:)); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
coverImage = [[KBImageCacheManager sharedManager] cachedImageForImageObject: imageObject type: imageType]; | |
if ( coverImage == nil ) | |
{ | |
MAKE_WEAK_SELF(); | |
_imageObserver = [[imageObject registerImageUpdateObserverUsingBlock: ^(UIImage *image, NSString *imageID, NSString *type) { | |
USE_WEAK_SELF(); | |
self->_coverImageView.image = image; | |
[[KBImageCacheManager sharedManager] removeObserver: _imageObserver]; | |
[_imageObserver release]; _imageObserver = nil; | |
}] retain]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if __has_feature(arr) | |
# if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_5_0 | |
# define block_unretained(obj) id _block_##obj __weak = (obj) | |
# else | |
# define block_unretained(obj) id _block_##obj __unsafe_unretained = (obj) | |
#else | |
# define block_unretained(obj) id _block_##obj __block = (obj) | |
#endif |