Skip to content

Instantly share code, notes, and snippets.

View steipete's full-sized avatar

Peter Steinberger steipete

View GitHub Profile
@0xced
0xced / gist:372236
Created April 20, 2010 09:34
Automatically show keyboard in MFMailComposeViewController
@try
{
id textView = [mailComposeViewController valueForKeyPath:@"internal.mailComposeView.textView"];
if ([textView respondsToSelector:@selector(becomeFirstResponder)])
[textView becomeFirstResponder];
}
@catch (NSException *e) {}
@fpillet
fpillet / NSManagedObjectContext+FP.m
Created December 20, 2010 11:30
Core data helpers to log errors and changes to a context (using NSLogger)
- (void)logDetailedError:(NSError *)error from:(id)caller selector:(SEL)selector
{
#if DEBUG
LogMessage(@"coredata", 0, @"*** CORE DATA ERROR: a data store operation failed");
LogMessage(@"coredata", 0, @"*** Caller was: %@ %p %@", [caller class], caller, NSStringFromSelector(selector));
LogMessage(@"coredata", 0, @"*** Error: %@", [error localizedDescription]);
NSArray* detailedErrors = [[error userInfo] objectForKey:NSDetailedErrorsKey];
if ([detailedErrors count] > 0)
{
for(NSError* detailedError in detailedErrors)
@AlanQuatermain
AlanQuatermain / gist:830865
Created February 17, 2011 02:59
All the external private APIs referenced by iBooks.app version 1.2.1
From PrivateFrameworks/Bom.framework:
U _BOMCopierCopyWithOptions
U _BOMCopierCountFilesInArchive
U _BOMCopierFree
U _BOMCopierNew
U _BOMCopierSetCopyFileFinishedHandler
U _BOMCopierSetCopyFileStartedHandler
U _BOMCopierSetCopyFileUpdateHandler
U _BOMCopierSetFatalErrorHandler
U _BOMCopierSetFatalFileErrorHandler
@evadne
evadne / uiwebview_fullscreen_media_playback_with_autororation_workaround.m
Created February 22, 2011 14:31
UIWebView Full-Screen Movie Post-Autorotation-Dismissal Layout Fix
@implementation IRWebViewController (irFullscreenMediaPlaybackAutorotationLayoutFix)
- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
// There is a bug, where launching a media player from the web view, fullscreening it, then rotating the device, and tapping on the media to see the timelime, causes the layout to go all berserk. This is a hack to combat that.
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
if ((!self.view.superview) || (self.parentViewController.modalViewController != self) || (self.modalPresentationStyle != UIModalPresentationFullScreen)) {
@nathansmith
nathansmith / parseint.js
Created June 15, 2011 15:52
Makes parseInt default to radix of 10.
// Protect against parseInt being used
// without radix, by defaulting to 10.
// Conditionally check value, in case
// future implementations of parseInt
// provide native base-10 by default.
(function(window) {
var _parseInt = window.parseInt;
@MSch
MSch / LogHelper.h
Created July 3, 2011 23:17
The ultimate awesome logging method
#import <Cocoa/Cocoa.h>
#include <stdarg.h>
// by @MSch <martin@schuerrer.org>
// From http://stackoverflow.com/questions/2632300/looping-through-macro-varargs-values
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
/* C99-style: anonymous argument referenced by __VA_ARGS__, empty arg not OK */
@AlanQuatermain
AlanQuatermain / gist:1063948
Created July 4, 2011 21:08
An example of how to use the prior gist
coverImage = [[KBImageCacheManager sharedManager] cachedImageForImageObject: imageObject type: imageType];
if ( coverImage == nil )
{
MAKE_WEAK_SELF();
_imageObserver = [[imageObject registerImageUpdateObserverUsingBlock: ^(UIImage *image, NSString *imageID, NSString *type) {
USE_WEAK_SELF();
self->_coverImageView.image = image;
[[KBImageCacheManager sharedManager] removeObserver: _imageObserver];
[_imageObserver release]; _imageObserver = nil;
}] retain];
@eaigner
eaigner / gist:1228804
Created September 20, 2011 10:22
Blocks as action target
// Assuming ARC is enabled.
// |button| is of type UIButton (works with NSButton as well).
[button addTarget:[^{ NSLog(@"Block invoked."); } copy]
action:@selector(invoke)
forControlEvents:UIControlEventTouchUpInside];
-(UIImage*)image:(UIImage*)image scaleAndRotateImageToMaxResolution:(int)resolution
{
int kMaxResolution = resolution; // Or whatever
CGImageRef imgRef = image.CGImage;
CGFloat width = CGImageGetWidth(imgRef);
CGFloat height = CGImageGetHeight(imgRef);
@joshaber
joshaber / dct_weak.h
Created December 29, 2011 05:22 — forked from rowanj/dct_weak.h
ARC macros for weak references
#ifndef _DCT_WEAK_H
#define _DCT_WEAK_H
// Macros for portable support of notionally weak properties with ARC
// Forked from https://gist.github.com/1354106
// Updated by Rowan James
// Available at https://gist.github.com/1530868
// Defines:
// dct_weak to be used as a replacement for the 'weak' keyword:
// @property (dct_weak) NSObject* propertyName;