Skip to content

Instantly share code, notes, and snippets.

View leviathan's full-sized avatar

Jörg Polakowski leviathan

View GitHub Profile
// Taken from the commercial iOS PDF framework http://pspdfkit.com.
// Copyright (c) 2013 Peter Steinberger. All rights reserved.
// Licensed under MIT (http://opensource.org/licenses/MIT)
//
// You should only use this in debug builds. It doesn't use private API, but I wouldn't ship it.
#import <objc/runtime.h>
#import <objc/message.h>
// Compile-time selector checks.
@leviathan
leviathan / DiscoverAppModuleClasses.m
Last active August 29, 2015 14:05
Object discovery
#import <objc/runtime.h>
- (NSArray *)discoverAppModuleClasses
{
NSMutableArray *appModuleClasses = [NSMutableArray array];
// Integrate all classes which comply to the provider protocol
unsigned int count = 0;
Class *classList = objc_copyClassList(&count);
for (NSUInteger index = 0; index < count; index++)
@leviathan
leviathan / heroku dyno_worker setup
Created September 14, 2010 17:34
heroku dyno & worker setup from within the rails app
require "heroku"
client = Heroku::Client.new("username", "password")
# Update the number of dynos used by the application
# app_name = the name of the application
# x = the integer number of dynos you want to set, e.g. 3
client.set_dynos("app_name", x)
# Update the number of workers used by the application
@leviathan
leviathan / NSNotificationCenter+MainThread.h
Created November 6, 2010 16:40
A category to send NSNotifications in the UI thread
// NSNotificationCenter+MainThread.h
@interface NSNotificationCenter (MainThread)
- (void)postNotificationOnMainThread:(NSNotification *)notification;
- (void)postNotificationOnMainThreadName:(NSString *)aName object:(id)anObject;
- (void)postNotificationOnMainThreadName:(NSString *)aName object:(id)anObject userInfo:(NSDictionary *)aUserInfo;
@end
@leviathan
leviathan / Load UIView with nib
Created January 7, 2011 14:53
Loading a custom UIView class with a custom nib file.
QPickOneView* myView = nil;
NSArray* nibViews = [[NSBundle mainBundle] loadNibNamed:@"QPickOneView" owner:self options:nil];
for (id currentObject in nibViews) {
if ([currentObject isKindOfClass:[QPickOneView class]]) {
myView = (QPickOneView *) currentObject;
break;
}
}
// Initialize namespaces ---------------------
if (!window.mm) {
mm = {};
}
// avoid window. use this if you "think" you are in root closure. makes encapsulation possible and code executable without DOM (like node...)
if (!this.mm) {
mm = {};
}
@leviathan
leviathan / mountain-lion-brew-setup.markdown
Created September 27, 2012 09:17 — forked from myobie/mountain-lion-brew-setup.markdown
Get Mountain Lion and Homebrew to Be Happy

Get Mountain Lion and Homebrew to Be Happy

1) Install XCode 4.4 into /Applications

Get it from the App Store.

2) Install Command Line Tools

In XCode's Preferences > Downloads you can install command line tools.

@leviathan
leviathan / SectionArray.h
Last active December 17, 2015 08:49
Objective-C Grid Array Wrapper
//
// Created by Jörg Polakowski on 25/04/13.
// Copyright (c) 2013 Jörg Polakowski. All rights reserved.
//
@interface SectionArray : NSObject
#pragma mark -
#pragma mark Factory
@leviathan
leviathan / MeasureBlockExecutionTime.m
Created November 29, 2013 06:59
Macro for Measuring Execution Time
NS_INLINE void MVComputeTimeWithNameAndBlock(const char *caller, void (^block)()) {
CFTimeInterval startTimeInterval = CACurrentMediaTime();
block();
CFTimeInterval nowTimeInterval = CACurrentMediaTime();
NSLog(@"%s - Time Running is: %f", caller, nowTimeInterval - startTimeInterval);
}
#define MVComputeTime(...) MVComputeTimeWithNameAndBlock(__PRETTY_FUNCTION__, (__VA_ARGS__))
@leviathan
leviathan / CacheFormatter.m
Created December 2, 2013 08:24
Cache NSDateFormatter on Class level for performance. http://nshipster.com/nsformatter/
+ (NSNumberFormatter *)numberFormatter {
static NSNumberFormatter *_numberFormatter = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_numberFormatter = [[NSNumberFormatter alloc] init];
[_numberFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
});
return _numberFormatter;
}