Skip to content

Instantly share code, notes, and snippets.

View ethanbing's full-sized avatar

Eric ethanbing

View GitHub Profile
@ethanbing
ethanbing / 判断是不是空行
Created July 11, 2013 02:20
Mac判断是不是空行
if ([[str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length]<=0) {
}
@ethanbing
ethanbing / Mac判断按下空格键
Created July 11, 2013 02:21
Mac判断按下空格键
NSString* keysPressed = [theEvent characters];
if ( [keysPressed isEqualToString:@" "] )
{
if(theEvent.type==NSKeyDown)
NSLog(@"spaceDown");
if(theEvent.type==NSKeyUp)
NSLog(@"spaceUp");
}
@ethanbing
ethanbing / Mac创建文件夹
Created July 11, 2013 02:22
Mac创建文件夹
BOOL bo = [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
bo ? : NSLog(@"创建失败");
@ethanbing
ethanbing / gist:9829815
Created March 28, 2014 10:35
获取程序的Documents路径
/**
 Returns the path to the application's documents directory.
 */
- (NSString *)applicationDocumentsDirectory {
     
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
    return basePath;
}
@ethanbing
ethanbing / gist:9887461
Created March 31, 2014 08:04
获得appDelegat单例对象
+ (AppDelegate *)sharedAppDelegate {
return (AppDelegate *)[[UIApplication sharedApplication] delegate];
}
@ethanbing
ethanbing / gist:9927019
Created April 2, 2014 02:30
AFNetwork上传图片
AFHTTPRequestOperation * operation = [_AFManager POST:[_baseURL stringByAppendingString:MCSetavatarInterface] parameters:dic constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileURL:[dic objectForKey:@"url"] name:@"avatar" error:nil];
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];
@ethanbing
ethanbing / gist:10970615
Created April 17, 2014 10:05
iOS 常用数学函数
1、 三角函数 
  double sin (double);正弦 
  double cos (double);余弦 
  double tan (double);正切 
  2 、反三角函数 
  double asin (double); 结果介于[-PI/2, PI/2] 
  double acos (double); 结果介于[0, PI] 
  double atan (double); 反正切(主值), 结果介于[-PI/2, PI/2] 
  double atan2 (double, double); 反正切(整圆值), 结果介于[-PI, PI] 
  3 、双曲三角函数 
//绘制三角
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextBeginPath(context);
CGContextMoveToPoint (context, CGRectGetMinX(rect), CGRectGetMaxY(rect));
CGContextAddLineToPoint(context, CGRectGetMidX(rect), CGRectGetMinY(rect));
CGContextAddLineToPoint(context, CGRectGetMaxX(rect), CGRectGetMaxY(rect));
CGContextClosePath(context);
@ethanbing
ethanbing / 0_reuse_code.js
Created August 23, 2014 05:13
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@ethanbing
ethanbing / shi
Created August 23, 2014 08:05
调整8小时差
NSDate *date = [NSDate date];
// 调整8小时时差
NSTimeZone *zone = [NSTimeZone systemTimeZone];
NSInteger interval = [zone secondsFromGMTForDate:date];
NSDate *localeDate = [date dateByAddingTimeInterval: interval];