Get Homebrew installed on your mac if you don't already have it
Install highlight. "brew install highlight". (This brings down Lua and Boost as well)
| /* | |
| Some sample code for a horizontal paged UIScrollView with a gap between each image (which looks nicer). Note - not using contentInset, we want each page to fill the iPhone screen and the gap only to be visible when scrolling (like Photos.app). | |
| Taking the iPhone status bar into account - our viewport is 320x460 | |
| Our UIScrollView is therefore set in Interface Builder to 340x460 with a -10 X offset (so it's larger than the viewport but still centred) | |
| Then we do the following... | |
| */ | |
| // Our image filenames |
| [schwa@ungoliant] ~$ export OBJC_HELP=1 | |
| [schwa@ungoliant] ~$ /Applications/Safari.app/Contents/MacOS/Safari | |
| objc[10559]: Objective-C runtime debugging. Set variable=YES to enable. | |
| objc[10559]: OBJC_HELP: describe available environment variables | |
| objc[10559]: OBJC_PRINT_OPTIONS: list which options are set | |
| objc[10559]: OBJC_PRINT_IMAGES: log image and library names as they are loaded | |
| objc[10559]: OBJC_PRINT_LOAD_METHODS: log calls to class and category +load methods | |
| objc[10559]: OBJC_PRINT_INITIALIZE_METHODS: log calls to class +initialize methods | |
| objc[10559]: OBJC_PRINT_RESOLVED_METHODS: log methods created by +resolveClassMethod: and +resolveInstanceMethod: | |
| objc[10559]: OBJC_PRINT_CLASS_SETUP: log progress of class and category setup |
| apply plugin:'scala' | |
| repositories { | |
| mavenLocal() | |
| mavenCentral() | |
| //This repo is for the Finagle jars | |
| mavenRepo urls:'http://maven.twttr.com' | |
| } | |
| dependencies { |
| - (void)dealloc { | |
| webView_.delegate = nil; // delegate is self here, so first set to nil before call stopLoading. | |
| [webView_ stopLoading]; | |
| // UIWebView must be released in the main thread, or we get: | |
| // Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now... | |
| // This is less evil than the proposed http://stackoverflow.com/questions/945082/uiwebview-in-multithread-viewcontroller | |
| // Calling removeFromSuperview in a dealloc is ugly and evil, but else UIView has a strong reference to UIWebView and our main-release call would be irrelevant. | |
| if (![NSThread isMainThread]) { | |
| [webView_ performSelectorOnMainThread:@selector(removeFromSuperview) withObject:nil waitUntilDone:YES]; |
Get Homebrew installed on your mac if you don't already have it
Install highlight. "brew install highlight". (This brings down Lua and Boost as well)
| // UIImageJPEGRepresentation | |
| NSData *data = UIImageJPEGRepresentation(tileImage, 0.71); | |
| [data writeToURL:cacheURL atomically:YES]; | |
| // ImageIO | |
| #import <ImageIO/ImageIO.h> | |
| #import <MobileCoreServices/UTCoreTypes.h> |
| /* | |
| Source: Apple Developer - Understanding iOS View Compositing | |
| */ | |
| // setup the layer | |
| CALayer *layer = view.layer; | |
| layer.bounds = sublayer_bounds; | |
| layer.backgroundColor = random_color(); | |
| // set the shadow properties on the layer |
| Latency Comparison Numbers (~2012) | |
| ---------------------------------- | |
| L1 cache reference 0.5 ns | |
| Branch mispredict 5 ns | |
| L2 cache reference 7 ns 14x L1 cache | |
| Mutex lock/unlock 25 ns | |
| Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
| Compress 1K bytes with Zippy 3,000 ns 3 us | |
| Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
| Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |
| // Declare enums like so: | |
| #define IMAGE_STATUS(XX) \ | |
| XX(kDOImageStatusOK, = 0) \ | |
| XX(kDOImageStatusCached, )\ | |
| XX(kDOImageStatusRetry, ) | |
| DECLARE_ENUM(DOImageStatus, IMAGE_STATUS) |
| nline void pspdf_dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_block_t block) { | |
| dispatch_get_current_queue() == queue ? block() : dispatch_sync(queue, block); | |
| } |