Skip to content

Instantly share code, notes, and snippets.

View onmyway133's full-sized avatar
๐Ÿ˜‡
What you don't know is what you haven't learned

Khoa onmyway133

๐Ÿ˜‡
What you don't know is what you haven't learned
View GitHub Profile
@onmyway133
onmyway133 / how do I force Xcode to rebuild the Info.plist file in my project every time I build the project?
Created September 14, 2014 09:13
how do I force Xcode to rebuild the Info.plist file in my project every time I build the project?
// http://w3facility.info/question/how-do-i-force-xcode-to-rebuild-the-info-plist-file-in-my-project-every-time-i-build-the-project/#answer-18578076
# ---------------------------- IMPORTANT ----------------------------
# You must set GITHash to something like 'Set by build script' in the file
# file '<Project Name>-Info.plist' in the 'Supporting Files' group
# -------------------------------------------------------------------
#
# Get the version number from the tag in git and the number of commits as the build number
#
@onmyway133
onmyway133 / NSStringf
Created September 22, 2014 15:50
NSStringf
// http://ioscodesnippet.com/2011/08/27/nsstringf-simpler-printf-styled-nsstring/
NSString *NSStringf(NSString *format, ...) {
va_list ap;
NSString *str;
va_start(ap,format);
str=[[NSString alloc] initWithFormat:format arguments:ap];
va_end(ap);
return [str autorelease];
@onmyway133
onmyway133 / UAMacros.h
Last active August 29, 2015 14:06 — forked from hjue/UAMacros.h
#define UA_isIPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define UA_isIPhone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define UA_isRetinaDevice ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] >= 2)
#define UA_isMultiTaskingSupported ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)] && [[UIDevice currentDevice] isMultitaskingSupported])
#define UA_runOnMainThread if (![NSThread isMainThread]) { dispatch_sync(dispatch_get_main_queue(), ^{ [self performSelector:_cmd]; }); return; };
@onmyway133
onmyway133 / xopen
Created September 25, 2014 01:32
xopen
// http://paul-samuels.com/blog/2012/10/13/simple-developer-happiness-gains/
#!/usr/bin/env ruby
require 'shellwords'
proj = Dir['*.xcworkspace'].first
proj = Dir['*.xcodeproj'].first unless proj
if proj
@onmyway133
onmyway133 / FTGPopoverController
Last active March 20, 2016 16:44
FTGPopoverController, a popover that works on both iOS 7 and iOS 8
//FTGPopoverController.h
@interface FTGPopoverController : NSObject
- (instancetype)initWithContentVC:(UIViewController *)contentVC contentSize:(CGSize)contentSize;
- (void)presentInVC:(UIViewController *)vc fromButton:(UIButton *)button;
- (void)dismiss;
- (BOOL)isVisible;
@end
@onmyway133
onmyway133 / SUPPRESS_PERFORM_SELECTOR_LEAK_WARNING
Created October 12, 2014 03:14
SUPPRESS_PERFORM_SELECTOR_LEAK_WARNING
#define SUPPRESS_PERFORM_SELECTOR_LEAK_WARNING(code) \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \
code; \
_Pragma("clang diagnostic pop") \
#define SUPPRESS_UNDECLARED_SELECTOR_LEAK_WARNING(code) \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wundeclared-selector\"") \
code; \
@onmyway133
onmyway133 / Circle shadow view
Created October 12, 2014 14:42
Circle shadow view
// http://stackoverflow.com/questions/18403578/how-can-i-add-shadow-to-a-circle-uiimageview
```
[self.imageView.layer setCornerRadius:60.0];
[self.imageView.layer setMasksToBounds:YES];
self.imageView.clipsToBounds = YES;
self.container.backgroundColor = [UIColor clearColor];
self.container.layer.shadowColor = [UIColor blackColor].CGColor;
self.container.layer.shadowOffset = CGSizeMake(5,15);
@onmyway133
onmyway133 / FTGActionSheetController
Last active August 29, 2015 14:07
FTGActionSheetController
// .h
#import <Foundation/Foundation.h>
typedef void (^FTGHandler)();
@interface FTGActionSheetController : NSObject
- (instancetype)initWithTitle:(NSString *)title;
- (instancetype)initWithTitle:(NSString *)title
cancelButtonTitle:(NSString *)cancelButtonTitle
@onmyway133
onmyway133 / FTGAlertController
Last active August 29, 2015 14:07
FTGAlertController
// .h
#import <Foundation/Foundation.h>
typedef void (^FTGHandler)();
@interface FTGAlertController : NSObject
- (instancetype)initWithTitle:(NSString *)title
message:(NSString *)message;
- (instancetype)initWithTitle:(NSString *)title
@onmyway133
onmyway133 / constraintForAttribute
Created November 23, 2014 03:54
constraintForAttribute
- (NSLayoutConstraint *)constraintForAttribute:(NSLayoutAttribute)attribute
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"firstAttribute = %d && (firstItem = %@ || secondItem = %@)", attribute, self, self];
NSArray *constraintArray = [self.superview constraints];
if (attribute == NSLayoutAttributeWidth || attribute == NSLayoutAttributeHeight) {
constraintArray = [self constraints];
}
NSArray *fillteredArray = [constraintArray filteredArrayUsingPredicate:predicate];