View UIColor hex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[UIColor colorWithRed:((float)((hex & 0xFF0000) >> 16))/255.0 | |
green:((float)((hex & 0xFF00) >> 8))/255.0 | |
blue:((float)(hex & 0xFF))/255.0 alpha:1.0] |
View regex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Config.h | |
// ZanSe | |
// | |
// Created by dnnta on 12-12-13. | |
// Copyright (c) 2012年 NightWish. All rights reserved. | |
// | |
// | |
// Config.h |
View gist:2586370
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "NSDate+Formatting.h" | |
#define SECONDS_PER_MINUTE 60.0 | |
#define SECONDS_PER_HOUR 3600.0 | |
#define SECONDS_PER_DAY 86400.0 | |
#define SECONDS_PER_MONTH 2592000.0 | |
#define SECONDS_PER_YEAR 31536000.0 | |
@implementation NSDate (formatting) |
View db随机值
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
oracle: select * from table_name order by dbms_random.value | |
#扫描记录时给每条记录生成一个随机值,然后根据这个值进行排序 | |
mssql: select top N * from table_name order by newid() | |
mysql: select * from table_name order by rand() | |
#mysql用随机值更新记录 | |
update articles set views = rand()* 1000 | |
sqlite3: select * from table_name order by random() |
View layer.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void)pauseLayer:(CALayer*)layer | |
{ | |
CFTimeInterval pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil]; | |
layer.speed = 0.0; | |
layer.timeOffset = pausedTime; | |
} | |
-(void)resumeLayer:(CALayer*)layer | |
{ | |
CFTimeInterval pausedTime = [layer timeOffset]; |
View UIView+Frame.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UIView+Frame.h | |
// | |
// | |
// Created by xxxx on 14-5-28. | |
// Copyright (c) 2014年 TBJ. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> |
View gist:2bc4fb18b7e8aadac7aa
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
void method1(NSArray *numbers) | |
{ | |
NSArray *sorted = [numbers sortedArrayUsingSelector:@selector(compare:)]; | |
} | |
void method2(NSArray *numbers) | |
{ | |
NSNumber *max=[numbers valueForKeyPath:@"@max.doubleValue"]; |
View detect.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static NSInteger currentTopVisibleSection = -1; | |
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { | |
NSIndexPath *topCellPath = [[tableView indexPathsForVisibleRows] objectAtIndex:0]; | |
if (currentTopVisibleSection != topCellPath.section) { | |
currentTopVisibleSection = topCellPath.section; | |
NSLog(@"current section on top is %d", currentTopVisibleSection); | |
} | |
NSString *header = [NSString stringWithFormat:@"Section %d", section]; |
View NSArray+ NullReplacement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "NSArray+NullReplacement.h" | |
#import "NSDictionary+NullReplacement.h" | |
@implementation NSArray (NullReplacement) | |
- (NSArray *)arrayByReplacingNullsWithBlanks { | |
NSMutableArray *replaced = [self mutableCopy]; | |
const id nul = [NSNull null]; | |
const NSString *blank = @""; | |
for (int idx = 0; idx < [replaced count]; idx++) { |
NewerOlder