Skip to content

Instantly share code, notes, and snippets.

View openaphid's full-sized avatar
🎯
Focusing

Bo openaphid

🎯
Focusing
View GitHub Profile
@nyoron
nyoron / gist:363423
Created April 12, 2010 10:12
Some sample code for a horizontal paged UIScrollView with a gap between each image, like Photos.app (which looks nicer when paging).
/*
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
@cppforlife
cppforlife / gist:1269501
Created October 7, 2011 05:09
objective-c debugging env variables
[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
@chochos
chochos / build.gradle
Created October 14, 2011 23:53
Gradle script for Finagle projects
apply plugin:'scala'
repositories {
mavenLocal()
mavenCentral()
//This repo is for the Finagle jars
mavenRepo urls:'http://maven.twttr.com'
}
dependencies {
@steipete
steipete / gist:1397553
Created November 27, 2011 13:28
Ugly as hell workaround for UIWebView crashing on non-main thread dealloc (inside a UIView)
- (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];
@jimbojsb
jimbojsb / gist:1630790
Created January 18, 2012 03:52
Code highlighting for Keynote presentations

Step 0:

Get Homebrew installed on your mac if you don't already have it

Step 1:

Install highlight. "brew install highlight". (This brings down Lua and Boost as well)

Step 2:

@odrobnik
odrobnik / gist:1845108
Created February 16, 2012 14:10
ImageIO versus UIImageJPEGRepresentation
// UIImageJPEGRepresentation
NSData *data = UIImageJPEGRepresentation(tileImage, 0.71);
[data writeToURL:cacheURL atomically:YES];
// ImageIO
#import <ImageIO/ImageIO.h>
#import <MobileCoreServices/UTCoreTypes.h>
@ksm
ksm / gist:1875946
Created February 21, 2012 11:20
CALayer shadowPath done the right way
/*
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
@jboner
jboner / latency.txt
Last active June 21, 2024 17:41
Latency Numbers Every Programmer Should Know
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
@hezi
hezi / HZClassUsingEnum.h
Created July 12, 2012 14:06
Objective-C Enum-TO-NSString and Vice versa.
// Declare enums like so:
#define IMAGE_STATUS(XX) \
XX(kDOImageStatusOK, = 0) \
XX(kDOImageStatusCached, )\
XX(kDOImageStatusRetry, )
DECLARE_ENUM(DOImageStatus, IMAGE_STATUS)
@steipete
steipete / gist:3713233
Created September 13, 2012 09:39
I often use dispatch queues for locking, and this function just makes life SO MUCH EASIER. Accidental deadlocks in more complex code paths are a PITA otherwise. But Apple deprecated dispatch_get_current_queue with iOS6?
nline void pspdf_dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_block_t block) {
dispatch_get_current_queue() == queue ? block() : dispatch_sync(queue, block);
}