Skip to content

Instantly share code, notes, and snippets.

@holysin
holysin / DaysBetweenDates.m
Created June 26, 2014 05:53
days between dates
+ (NSInteger)daysBetweenDate:(NSDate*)fromDateTime andDate:(NSDate*)toDateTime
{
NSDate *fromDate;
NSDate *toDate;
NSCalendar *calendar = [NSCalendar currentCalendar];
[calendar rangeOfUnit:NSDayCalendarUnit startDate:&fromDate
interval:NULL forDate:fromDateTime];
[calendar rangeOfUnit:NSDayCalendarUnit startDate:&toDate
@holysin
holysin / ns_num.h
Created May 12, 2014 08:20
Cocoa NS_NUM
typedef NS_ENUM(NSInteger, UITableViewCellStyle) {
UITableViewCellStyleDefault,
UITableViewCellStyleValue1,
UITableViewCellStyleValue2,
UITableViewCellStyleSubtitle
};
@holysin
holysin / color
Created March 14, 2014 12:38
random color
UIColor* color()
{
CGFloat hue = ( arc4random() % 256 / 256.0 ); // 0.0 to 1.0
CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from white
CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from black
return [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
}
@interface UIColor (fromHex)
+ (UIColor *)colorwithHexString:(NSString *)hexStr alpha:(CGFloat)alpha;
@end
@holysin
holysin / void PrintObjectMethods
Created January 18, 2014 07:14
Print NSObject selectors
void PrintObjectMethods() {
unsigned int count = 0;
Method *methods = class_copyMethodList([NSObject class], &count);
for (unsigned int i = 0; i < count; ++i) {
SEL sel = method_getName(methods[i]);
const char *name = sel_getName(sel);
printf(“%s\n”, name);
}
free(methods);
}
@holysin
holysin / Emoji.plist
Created January 16, 2014 03:02 — forked from mattt/Emoji.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>People</key>
<array>
<string>😄</string>
<string>😃</string>
<string>😀</string>
<string>😊</string>
UIFont * GetVariationOfFontWithTrait(UIFont *baseFont, CTFontSymbolicTraits trait) {
CGFloat fontSize = [baseFont pointSize];
CFStringRef baseFontName = (__bridge CFStringRef)[baseFont fontName];
CTFontRef baseCTFont = CTFontCreateWithName(baseFontName, fontSize, NULL);
CTFontRef ctFont = CTFontCreateCopyWithSymbolicTraits(baseCTFont, 0, NULL, trait, trait);
NSString *variantFontName = CFBridgingRelease(CTFontCopyName(ctFont, kCTFontPostScriptNameKey));
UIFont *variantFont = [UIFont fontWithName:variantFontName size:fontSize];
CFRelease(ctFont);
CFRelease(baseCTFont);
return variationFont;
@holysin
holysin / unsigned countOfCores
Created January 14, 2014 13:18
Get the core number of iPhone
unsigned int countOfCores() {
unsigned int ncpu;
size_t len = sizeof(ncpu);
sysctlbyname(“hw.ncpu”, &ncpu, &len, NULL, 0);
return ncpu;
}
@holysin
holysin / CALayer+RNAnimations.h
Last active January 2, 2016 22:09
CALayer Basic Animation
#import <QuartzCore/QuartzCore.h>
@interface CALayer (RNAnimations)
- (void)setValue:(id)value forKeyPath:(NSString *)keyPath duration:(CFTimeInterval)duration delay:(CFTimeInterval)delay;
@end
@holysin
holysin / Const.h
Created December 31, 2013 03:19
macros for iOS
#define IS_IPHONE_5 ([[UIScreen mainScreen] bounds].size.height == 568 )
#define SYSTEM_VERSION ([[[UIDevice currentDevice] systemVersion] floatValue])
#define IS_IOS7_ORLATER (SYSTEM_VERSION >= 7.0)
#define SYSTEM_CALL(TEL) ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"telprompt://%@", (TEL)]]])
#define kAppDelegate ((AppDelegate *)[[UIApplication sharedApplication] delegate])
#define NavigationBar_HEIGHT 44
#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)