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
require 'iconv' | |
module AppleBinaryPropertyList | |
MIME_TYPE = 'application/octet-stream' # Don't know what to use, so use a very generic type for now | |
CFData = Struct.new(:data) # For marking strings as binary data which will be decoded as a CFData object | |
# Convert a Ruby data structure into an OS X binary property list file. (.plist) | |
# Works as you'd expect. Integers are limited to 4 bytes, even though the format implies longer values can be written. |
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)webViewDidFinishLoad:(UIWebView *)webView | |
{ | |
if (webView.subviews.count > 0) | |
{ | |
id aView = [webView.subviews objectAtIndex:0]; | |
if ([aView respondsToSelector:@selector(setScrollEnabled:)]) | |
{ | |
((UIScrollView*)aView).scrollEnabled = NO; | |
} |
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
CGSize imageSize = CGSizeMake(1000, 1000); | |
CGColorSpaceRef colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); | |
CGContextRef theContext = CGBitmapContextCreate(NULL, imageSize.width, imageSize.height, 8, 4*imageSize.width, colorSpace, kCGImageAlphaPremultipliedLast); | |
[layerView.layer renderInContext:theContext]; | |
// Layer tree has backgroundFilters set on some of the CALayers | |
// When it's rendered in the Bitmap Context, none of these filters are applied. |
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
UIImage* newImage = [UIImage imageNamed:context]; | |
// set up an animation for the transition the content | |
CATransition *animation = [CATransition animation]; | |
[animation setDuration:0.25]; | |
[animation setType:kCATransitionPush]; | |
[animation setSubtype:kCATransitionFromRight]; | |
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; | |
[[self.contentImageView layer] addAnimation:animation forKey:@"SwitchToView1"]; |
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
NSArray* stringArray = [NSArray arrayWithObjects:@"One", @"Two", @"Three", @"Four", nil]; | |
[stringArray enumerateObjectsUsingBlock:^(NSString* obj, NSUInteger idx, BOOL *stop) { | |
NSLog(@"%@", obj); | |
}]; |
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
__block NSManagedObject* object = nil; | |
[privateQueueContext performBlockAndWait:^{ | |
object = [SomeClass methodThatExecutesFetchRequestReturningObjectUsingContext:privateQueueContext]; | |
}]; | |
// Is it safe to use object here? | |
NSLog(@"object: %@", object); |
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
// When the dom node is [object HTMLObjectElement] | |
// element is not a valid object ==> crash | |
- (void)mouseMoved:(NSEvent *)theEvent { | |
NSPoint mouseLocation = [self.webView convertPoint:[theEvent locationInWindow] fromView:nil]; | |
mouseLocation.y = [self.webView frame].size.height - mouseLocation.y; | |
id element2 = [[self.webView windowScriptObject] evaluateWebScript:[NSString stringWithFormat:@"document.elementFromPoint(%f,%f);", mouseLocation.x, mouseLocation.y]]; | |
id element = [[self.webView windowScriptObject] evaluateWebScript:[NSString stringWithFormat:@"\"result: \" + document.elementFromPoint(%f,%f)", mouseLocation.x, mouseLocation.y]]; |
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
static NSString *MYObservationContext = @"MYObservationContext"; | |
[object addObserver:self forKeyPath:@"key.path" options:(NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew) context:(void*)&MYObservationContext]; | |
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { | |
if (context == &MYObservationContext) { | |
id oldValue = [change objectForKey:NSKeyValueChangeOldKey]; | |
id newValue = [change objectForKey:NSKeyValueChangeNewKey]; | |
// Do something | |
} |
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
/* When adding the persistent store to a PSC | |
pragmaOptions = [[NSDictionary alloc] initWithObjectsAndKeys:@"WAL", @"journal_mode", nil]; | |
storeOptions = [[NSDictionary alloc] initWithObjectsAndKeys:pragmaOptions, NSSQLitePragmasOption, nil]; | |
This will allow multiple readers, and at most writer to connect to the Sqlite DB. Default journalling only allows multiple readers OR 1 writer (ie. writing blocks all reading). | |
*/ |
OlderNewer