Skip to content

Instantly share code, notes, and snippets.

@jamztang
jamztang / UIApplicationAddition.h
Last active October 5, 2015 18:29
Handy marco to return supported UIInterfaceOrientation for your View Controllers
// Created by Jamz Tang 2012-06-02
// http://ioscodesnippet.com/post/24203288551/quickly-switch-supported-uiinterfaceorientation-for
// Convert UIInterfaceOrientation to NSString, so we can compare it
static inline NSString *NSStringFromUIInterfaceOrientation(UIInterfaceOrientation orientation) {
switch (orientation) {
case UIInterfaceOrientationPortrait: return @"UIInterfaceOrientationPortrait";
case UIInterfaceOrientationPortraitUpsideDown: return @"UIInterfaceOrientationPortraitUpsideDown";
case UIInterfaceOrientationLandscapeLeft: return @"UIInterfaceOrientationLandscapeLeft";
case UIInterfaceOrientationLandscapeRight: return @"UIInterfaceOrientationLandscapeRight";
# show log tree (one-line per commit)
git config --global alias.logtree "log --graph --pretty=oneline --abbrev-commit"
# show log tree (detailed)
git config --global alias.logtreelong "log --graph"
@jamztang
jamztang / ViewController.m
Created May 16, 2012 10:16
Handle UIPopoverController for interface orientation changes
//
// The blog post which described this dedicated problem
// http://mystcolor.me/post/23158981244/uipopovercontroller-and-orientation-positioning-problem
//
typedef void (^PopoverControllerPresentationBlock)(void);
@interface ViewController () <UIPopoverControllerDelegate>
@property (nonatomic, strong) UIPopoverController *popoverController;
@property (nonatomic, copy) PopoverControllerPresentationBlock popoverControllerPresentationBlock;
@jamztang
jamztang / nsincrementalstore.markdown
Created May 9, 2012 04:24 — forked from chriseidhof/nsincrementalstore.markdown
Accessing an API using CoreData's NSIncrementalStore

Accessing an API using CoreData's NSIncrementalStore

Note: the original location of this article is on my blog, however, it is posted here too for better readability.

In this article, we will see how to use Core Data for accessing your API. We will use the Bandcamp API as our running example. I've only been experimenting with this code for a few days, so there might be mistakes in there.

//
// NSObject+PropertyListing.h
// PropertyFun
//
// Created by Andrew Sardone on 8/27/10.
//
#import <Foundation/Foundation.h>
@jamztang
jamztang / UIColorFromHex.m
Created May 7, 2012 14:53 — forked from dstnbrkr/UIColorFromRGB
Convert hex value to UIColor
UIColor* UIColorFromHex(NSInteger colorInHex) {
// colorInHex should be value like 0xFFFFFF
return [UIColor colorWithRed:((float) ((colorInHex & 0xFF0000) >> 16)) / 0xFF
green:((float) ((colorInHex & 0xFF00) >> 8)) / 0xFF
blue:((float) (colorInHex & 0xFF)) / 0xFF
alpha:1.0];
}
@jamztang
jamztang / gist+example.m
Created May 5, 2012 16:46
Embedding Gist example
//
// gist+example.m
// This is an example of embedding an objective-c implementation file in gist
- (BOOL)testMethod {
// Supports syntax highlighting
return YES;
}
@jamztang
jamztang / gist:2587002
Created May 3, 2012 16:28 — forked from lxcid/gist:2586763
Based on https://gist.github.com/2215212, a method helper to unit test AFNetworking operations in SenTestingKit.
// Call theResume() to stop the semaphore from blocking/waiting.
// Failure to call theResume() will cause the test to hang.
// This is needed to test asynchronous operations. See https://gist.github.com/2215212
- (void)dispatchSemaphoreInBlock:(void (^)(void (^theResume)(void)))theBlock {
dispatch_semaphore_t theSemaphore = dispatch_semaphore_create(0);
theBlock(^{ dispatch_semaphore_signal(theSemaphore); });
while (dispatch_semaphore_wait(theSemaphore, DISPATCH_TIME_NOW)) {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
}
dispatch_release(theSemaphore);
@jamztang
jamztang / MethodSwizzle.m
Created May 2, 2012 02:06
Handly method swizzling method
// Original Reference: http://stackoverflow.com/questions/1637604/method-swizzle-on-iphone-device
#import <objc/runtime.h>
#import <objc/message.h>
//....
void Swizzle(Class c, SEL orig, SEL new)
{
Method origMethod = class_getInstanceMethod(c, orig);
Method newMethod = class_getInstanceMethod(c, new);
@jamztang
jamztang / LICENSE
Created March 26, 2012 14:40
JTTargetActionBlock - Adding blocks support for UIControl target/action mechanism
Copyright (c) 2013 Jamz Tang <[email protected]>
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 furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all