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
// http://stackoverflow.com/questions/969130/how-to-print-out-the-method-name-and-line-number-and-conditionally-disable-nslog/969291#969291
#ifdef DEBUG
# define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
#else
# define DLog(...)
#endif
// ALog always displays output regardless of the DEBUG setting
#define ALog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
@onmyway133
onmyway133 / Suppress unused warning
Created July 26, 2014 13:16
Suppress unused warning
// http://stackoverflow.com/questions/3599160/unused-parameter-warnings-in-c-code
#define UNUSED(x) (void)(x)
@onmyway133
onmyway133 / Singleton Macro
Last active August 29, 2015 14:04
Singleton Macro
#define OMNIA_SINGLETON_H(name) + (instancetype)name;
#define OMNIA_SINGLETON_M(name) + (instancetype)name { static dispatch_once_t onceToken; static id instance = nil; dispatch_once(&onceToken, ^{ instance = [[self alloc] init]; }); return instance; }
// Taken from the commercial iOS PDF framework http://pspdfkit.com.
// Copyright (c) 2013 Peter Steinberger. All rights reserved.
// Licensed under MIT (http://opensource.org/licenses/MIT)
//
// You should only use this in debug builds. It doesn't use private API, but I wouldn't ship it.
#import <objc/runtime.h>
#import <objc/message.h>
// Compile-time selector checks.
//
// NSArray+NegativeIndexes.m
// Allow Negative Array Literals
//
// Created by Matthew Robinson on 25th October 2012.
// Copyright (c) 2012 Matthew Robinson. All rights reserved.
//
// WARNING: This is a proof of concept and should not be used
// in production code. This could break at anytime.
@onmyway133
onmyway133 / Keyboard frame convert
Created August 13, 2014 14:47
Keyboard frame convert
// http://stackoverflow.com/questions/9746417/keyboard-willshow-and-willhide-vs-rotation/14351009#14351009
- (void) keyboardWillShow:(NSNotification *)aNotification
{
CGRect keyboardFrame = [[[aNotification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
CGRect convertedFrame = [self.view convertRect:keyboardFrame fromView:self.view.window];
......
/* Do whatever you want now with the new frame.
* The width and height will actually be correct now
@onmyway133
onmyway133 / switchRootViewController
Created August 25, 2014 09:09
switchRootViewController
- (void)switchRootViewController:(UIViewController *)viewController
animated:(BOOL)animated
completion:(void (^)())completion
{
UIWindow *window = self.appDelegate.window;
if (animated) {
[UIView transitionWithView:window
duration:0.3
options:UIViewAnimationOptionTransitionCrossDissolve
@onmyway133
onmyway133 / circularImageWithColor:radius
Created August 28, 2014 06:54
circularImageWithColor:radius
// FLEXUtitlity
+ (UIImage *)circularImageWithColor:(UIColor *)color radius:(CGFloat)radius
{
CGFloat diameter = radius * 2.0;
UIGraphicsBeginImageContextWithOptions(CGSizeMake(diameter, diameter), NO, 0.0);
CGContextRef imageContext = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(imageContext, [color CGColor]);
CGContextFillEllipseInRect(imageContext, CGRectMake(0, 0, diameter, diameter));
UIImage *circularImage = UIGraphicsGetImageFromCurrentImageContext();
@onmyway133
onmyway133 / visibleKeyboardHeight
Created August 28, 2014 10:04
visibleKeyboardHeight
// SVProgressHUD
- (CGFloat)visibleKeyboardHeight {
UIWindow *keyboardWindow = nil;
for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
if(![[testWindow class] isEqual:[UIWindow class]]) {
keyboardWindow = testWindow;
break;
}
@onmyway133
onmyway133 / extern
Created September 5, 2014 09:01
extern
FOUNDATION_EXPORT NSString *const NSKeyValueChangeKindKey;