Skip to content

Instantly share code, notes, and snippets.

View steipete's full-sized avatar

Peter Steinberger steipete

View GitHub Profile
//
// PSDDFormatter.h
// Created by Peter Steinberger on 08.09.10.
//
#import "DDLog.h"
@interface PSDDFormatter : NSObject <DDLogFormatter> {
NSDateFormatter *dateFormatter;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark Key/Value coding
- (id)initWithCoder:(NSCoder *)aCoder {
if (self = [self init]) {
[TPAutoArchiver unarchiveObject:self
withCoder:aCoder];
}
return self;
// some credits go to http://www.mikeash.com/pyblog/friday-qa-2009-08-14-practical-blocks.html
typedef void (^BasicBlock)(void);
void RunAfterDelay(NSTimeInterval delay, BasicBlock block) {
[[[block copy] autorelease] performSelector:@selector(ps_callBlock) withObject:nil afterDelay:delay];
}
@implementation NSObject (BlocksAdditions)
- (void)ps_callBlock {
- (void)login {
// build request
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:url]];
#ifdef MOCK_HANDSHAKE
// create a nice mock
request = [OCMockObject niceMockForClass:[ASIHTTPRequest class]];
NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"mock_handshake" ofType:@"txt"];
NSString *responseString = [NSString stringWithContentsOfFile:modelPath encoding:NSUTF8StringEncoding error:nil];
[[[(id)request stub] andReturn:responseString] responseString];
// only add the http link
NSError *error = nil;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(http[^^]+)" options:NSRegularExpressionCaseInsensitive error:&error];
NSTextCheckingResult *firstMatch = [regex firstMatchInString:responseString options:0 range:NSMakeRange(0, [responseString length])];
if (firstMatch) {
NSRange accessTokenRange = [firstMatch rangeAtIndex:1];
NSString *theUrlString = [responseString substringWithRange:accessTokenRange];
NSLog(theUrlString);
}
// this is implemented, but not declared. we add the category to fix the warning
// (since super cannot be casted any longer in clang)
@interface UINavigationController(AMInternal)
- (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item;
@end
@implementation AMNavigationController
///////////////////////////////////////////////////////////////////////////////////////////////////
@steipete
steipete / Integration.m
Last active September 26, 2015 15:17
Integrating PSPDFKit
#import <PSPDFKit/PSPDFKit.h>
// Create the PSPDFDocument. (container for one or multiple pdfs)
NSURL *documentURL = [NSBundle.mainBundle.resourceURL URLByAppendingPathComponent:@"Sample.pdf"];
PSPDFDocument *document = [PSPDFDocument documentWithURL:documentURL];
// Open view controller. Embed into an UINavigationController to enable the toolbar.
PSPDFViewController *pdfController = [[PSPDFViewController alloc] initWithDocument:document];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:pdfController];
[self presentViewController:navController animated:YES completion:NULL];
@steipete
steipete / Logging.m
Created July 31, 2011 21:29
Logging PSPDFKit
kPSPDFLogLevel = PSPDFLogLevelInfo;
// Available Log Levels: PSPDFLogLevelNothing, PSPDFLogLevelError, PSPDFLogLevelInfo, PSPDFLogLevelVerbose
@steipete
steipete / UIImage+PSPDFKitAdditions.m
Created August 13, 2011 20:52
Preload UIImage for super-smooth interaction. especially great if you use JPGs, which otherwise produce a noticeable lag on the main thread.
- (UIImage *)pspdf_preloadedImage {
CGImageRef image = self.CGImage;
// make a bitmap context of a suitable size to draw to, forcing decode
size_t width = CGImageGetWidth(image);
size_t height = CGImageGetHeight(image);
CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef imageContext = CGBitmapContextCreate(NULL, width, height, 8, width*4, colourSpace,
kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little);
@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];
}