Skip to content

Instantly share code, notes, and snippets.

View DerAndereAndi's full-sized avatar
💭
Learning ...

Andreas Linde DerAndereAndi

💭
Learning ...
View GitHub Profile
//
// NSObject+BlockObservation.h
// Version 1.0
//
// Andy Matuschak
// andy@andymatuschak.org
// Public domain because I love you. Let me know how you use it.
//
#import <Cocoa/Cocoa.h>
#import "NSString+ConcurrentEnumeration.h"
@implementation NSString (ConcurrentLineEnumeration)
- (void)enumerateConcurrentlyWithOptions:(NSStringEnumerationOptions)options
usingBlock:(void (^)(NSString *substring))block
{
dispatch_group_t group = dispatch_group_create();
[self enumerateSubstringsInRange:NSMakeRange(0, [self length])
@mwaterfall
mwaterfall / gist:953657
Created May 3, 2011 16:24
Runtime iOS Version Checking
/*
* System Versioning Preprocessor Macros
*/
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
@0xced
0xced / NSData+CommonDigest.h
Created May 23, 2011 09:00
NSData+CommonDigest: The most elegant NSData category for cryptographic hash functions
/*
Licensed under the MIT License
Copyright (c) 2011 Cédric Luthi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@landonf
landonf / deadlock.m
Created June 4, 2011 04:02
Deadlocking a signal handler by using ObjC (ARM / x86-32)
#import <Foundation/Foundation.h>
static void unsafe_signal_handler (int signo) {
signal(signo, SIG_DFL);
/* Attempt to use ObjC to fetch the backtrace. Will trigger deadlock. */
[NSThread callStackSymbols];
}
int main(int argc, char *argv[]) {
@landonf
landonf / stackoverflow.m
Created June 17, 2011 22:51
Explanation of why backtrace(3) and stack overflow don't mix.
#import <Foundation/Foundation.h>
#import <pthread.h>
#import <execinfo.h>
#import <string.h>
#import <stdint.h>
/*
* A signal handler that is broken in two ways:
* 1) The handler calls APIs that are not declared to be async-safe and may deadlock or otherwise fail.
@javan
javan / gist:1168475
Created August 24, 2011 16:32
Fix iPhone home button
Found this tip in comment here: http://www.tipb.com/2011/01/04/tipb-bug-home-button-working-iphone/
1.) Open any application
2.) Press and hold the power button until the slide to shutdown swipe bar appears.
3.) Release Power button
4.) Press and hold Home button Lightly
until screen returns to icon screen
@steipete
steipete / gist:1175357
Created August 27, 2011 12:54
Easy [fade] animation for UIImageView.image
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
selected_ = selected;
if (animated) {
CATransition *transition = [CATransition animation];
transition.duration = 0.25f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;
[self.selectionImageView.layer addAnimation:transition forKey:nil];
}
@AlanQuatermain
AlanQuatermain / gist:1211349
Created September 12, 2011 14:14
Sharing UIView subclasses between iPhone and iPad? Make your life easier with device-specific -layoutSubviews (or -drawRect, etc.) methods. Make the Objective-C runtime work for YOU!
+ (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);
}
@steipete
steipete / gist:1239338
Created September 24, 2011 13:44
PSIsCrappyDevice
BOOL PSIsCrappyDevice(void) {
static BOOL isCrappyDevice = YES;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
BOOL isSimulator = NO;
BOOL isIPad2 = (PSIsIpad() && [UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]);
BOOL hasRetina = [[UIScreen mainScreen] scale] > 1.f;
// enable animations on simulator