Skip to content

Instantly share code, notes, and snippets.

@dnnta
dnnta / NSArray+ NullReplacement
Created May 28, 2014 05:30
NSDictionary或者NSArray中Null处理 Replace all NSNull objects in an NSDictionary http://stackoverflow.com/questions/8075147/replace-all-nsnull-objects-in-an-nsdictionary#16702060
#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++) {
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];
#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 August 29, 2015 14:03
UIView Frame Category
//
// 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 July 14, 2014 05:48
Pause and resume CABasicAnimations
-(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];
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 15:12
计算时间差
#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 June 28, 2012 03:44
web 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 June 29, 2012 02:09
UIColor with HEX value
[UIColor colorWithRed:((float)((hex & 0xFF0000) >> 16))/255.0
green:((float)((hex & 0xFF00) >> 8))/255.0
blue:((float)(hex & 0xFF))/255.0 alpha:1.0]
@dnnta
dnnta / graphic_util.h
Created July 13, 2012 07:35
graphic_util.h
/*
* graphic_util.h
* radikker
*
* Created by saiten on 09/11/26.
* Copyright 2009 __MyCompanyName__. All rights reserved.
*
*/
#ifndef __SYUN_GRAPHICS_H__