Skip to content

Instantly share code, notes, and snippets.

View pitiphong-p's full-sized avatar

Pitiphong Phongpattranont pitiphong-p

View GitHub Profile
@tonyarnold
tonyarnold / NSUserDefaultsObjectSubscripting.h
Created July 29, 2012 07:51
Add simple object subscripting to NSUserDefaults
//
// NSUserDefaults+ObjectSubscripting.h
//
// Created by Tony Arnold on 29/07/12.
// Copyright (c) 2012 The CocoaBots. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSUserDefaults (ObjectSubscripting)
@krzysztofzablocki
krzysztofzablocki / gist:3240133
Created August 2, 2012 19:58
Handling dial like rotation on CCNode by using UIPanGestureRecognizer
//! for gesture recognizer support in cocos2d use https://github.com/krzysztofzablocki/CCNode-SFGestureRecognizers
- (void)handlePanGesture:(UIPanGestureRecognizer*)gestureRecognizer
{
CGPoint location = [[CCDirector sharedDirector] convertToGL:[gestureRecognizer locationInView:gestureRecognizer.view]];
static CGPoint oldLocation;
//! this will make sure that oldLocation is initialized
if (gestureRecognizer.state != UIGestureRecognizerStateBegan) {
//! we need to calculate angle difference between previous position and current one in regards to dial center
CGPoint firstDir = ccpSub(oldLocation, dial.position);
@mikeabdullah
mikeabdullah / KSPowerAssertion.h
Created August 4, 2012 15:13
KSPowerAssertion
//
// KSPowerAssertion.h
// Sandvox
//
// Created by Mike on 04/08/2012.
// Copyright (c) 2012 Karelia Software. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <IOKit/pwr_mgt/IOPMLib.h>
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = [email protected]:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@nfarina
nfarina / UIView+FrameAdditions.h
Created August 21, 2012 06:40
UIView Frame helper getter/setter category methods
#import <UIKit/UIKit.h>
@interface UIView (SMFrameAdditions)
@property (nonatomic, assign) CGPoint $origin;
@property (nonatomic, assign) CGSize $size;
@property (nonatomic, assign) CGFloat $x, $y, $width, $height; // normal rect properties
@property (nonatomic, assign) CGFloat $left, $top, $right, $bottom; // these will stretch the rect
@end
@pilky
pilky / gist:3609846
Created September 3, 2012 14:51
NSLayoutConstraint code, done right
//Pass in arrays of views and access with number keys or add attributes for all
NSArray *views = @[ topView, middleView, lastView ];
[containerView setSubviews:views];
[containerView m3_addConstraints:@[
@"$1.top = 0",
@"$2.top = $1.bottom",
@"$3.top = $2.bottom",
@"$3.bottom = 0",
@"$all.(left, right) = (0, 10)", //Assign multiple attributes in one statement
@"$all.height >= 30"
@0xced
0xced / QLPreviewController+NSCodingFix.m
Created September 20, 2012 18:04
Workaround a bug in UIKit that prevents QLPreviewController to be loaded from a nib
#import <QuickLook/QuickLook.h>
#import <objc/runtime.h>
@implementation QLPreviewController (NSCodingFix)
+ (void) load
{
Method initWithCoder = class_getInstanceMethod(self, @selector(initWithCoder_nscodingfix:));
class_addMethod(self, @selector(initWithCoder:), method_getImplementation(initWithCoder), method_getTypeEncoding(initWithCoder));
}
@steipete
steipete / gist:3933090
Created October 22, 2012 18:13
Simple main thread usage detector that I'm using in PSPDFKit to find performance problems early on.
// Smart little helper to find main thread hangs. Enable in appDidFinishLaunching.
// Only available with source code in DEBUG mode.
@interface PSPDFHangDetector : NSObject
+ (void)startHangDetector;
@end
@implementation PSPDFHangDetector
+ (void)startHangDetector {
#ifdef DEBUG
@steipete
steipete / gist:3959770
Created October 26, 2012 16:32
Macro Helpers for atomic read/write of properties.
// Atomic getting/setting of properties.
// See http://www.opensource.apple.com/source/objc4/objc4-371.2/runtime/Accessors.subproj/objc-accessors.h
extern void objc_setProperty(id self, SEL _cmd, ptrdiff_t offset, id newValue, BOOL atomic, BOOL shouldCopy);
extern id objc_getProperty(id self, SEL _cmd, ptrdiff_t offset, BOOL atomic);
extern void objc_copyStruct(void *dest, const void *src, ptrdiff_t size, BOOL atomic, BOOL hasStrong);
#define PSPDFAtomicRetainedSetToFrom(dest, source) objc_setProperty(self, _cmd, (ptrdiff_t)(&dest) - (ptrdiff_t)(self), source, YES, NO)
#define PSPDFAtomicCopiedSetToFrom(dest, source) objc_setProperty(self, _cmd, (ptrdiff_t)(&dest) - (ptrdiff_t)(self), source, YES, YES)
#define PSPDFAtomicAutoreleasedGet(source) objc_getProperty(self, _cmd, (ptrdiff_t)(&source) - (ptrdiff_t)(self), YES)
#define PSPDFAtomicStructToFrom(dest, source) objc_copyStruct(&dest, &source, sizeof(__typeof__(source)), YES, NO)
@jhankin
jhankin / SOInsetLabel.h
Created November 5, 2012 19:11
UILabel subclass encapsulating interior shadow functionality
//
// SOInsetLabel.h
//
// Created by Joseph Hankin on 11/2/12.
// From code posted by Rob Mayoff.
// http://stackoverflow.com/questions/8467141/ios-how-to-achieve-emboss-effect-for-the-text-on-uilabel
// Copyright (c) 2012 Joseph Hankin. All rights reserved.
//