Skip to content

Instantly share code, notes, and snippets.

@interface UIColor (fromHex)
+ (UIColor *)colorwithHexString:(NSString *)hexStr alpha:(CGFloat)alpha;
@end
@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];
}
@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 / 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 / .gitconfig
Created October 28, 2013 01:50
Git config
[user]
name = holysin
email = furyng@gmail.com
[alias]
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %C(blue)%s%Creset %C(dim cyan)<%an>%Creset %C(dim white)(%ci)%Creset' --abbrev-commit
st = status -sb
co = checkout
br = branch
mg = merge
ci = commit
@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)
@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 / 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;
}
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 / 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>