Skip to content

Instantly share code, notes, and snippets.

View NSArray+ NullReplacement
#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++) {
View detect.m
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 gist:2bc4fb18b7e8aadac7aa
#import <Foundation/Foundation.h>
void method1(NSArray *numbers)
{
NSArray *sorted = [numbers sortedArrayUsingSelector:@selector(compare:)];
}
void method2(NSArray *numbers)
{
NSNumber *max=[numbers valueForKeyPath:@"@max.doubleValue"];
@dnnta
dnnta / UIView+Frame.h
Last active Aug 29, 2015
UIView Frame Category
View UIView+Frame.h
//
// UIView+Frame.h
//
//
// Created by xxxx on 14-5-28.
// Copyright (c) 2014年 TBJ. All rights reserved.
//
#import <UIKit/UIKit.h>
@dnnta
dnnta / layer.m
Created Jul 14, 2014
Pause and resume CABasicAnimations
View layer.m
-(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 db随机值
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()
@dnnta
dnnta / gist:2586370
Created May 3, 2012
计算时间差
View gist:2586370
#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)
@dnnta
dnnta / regex
Created Jun 28, 2012
web regex
View regex
//
// Config.h
// ZanSe
//
// Created by dnnta on 12-12-13.
// Copyright (c) 2012年 NightWish. All rights reserved.
//
//
// Config.h
@dnnta
dnnta / UIColor hex
Created Jun 29, 2012
UIColor with HEX value
View UIColor hex
[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 graphic_util.h
/*
* graphic_util.h
* radikker
*
* Created by saiten on 09/11/26.
* Copyright 2009 __MyCompanyName__. All rights reserved.
*
*/
#ifndef __SYUN_GRAPHICS_H__