Skip to content

Instantly share code, notes, and snippets.

View onevcat's full-sized avatar
🐭

Wei Wang onevcat

🐭
View GitHub Profile
@onevcat
onevcat / sysVersion
Created February 6, 2012 05:52
系统版本判别
// System Versioning Preprocessor Macros
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
@onevcat
onevcat / TestFlight+NSLogger
Created February 18, 2012 11:32
TestFlight+NSLogger
#ifdef DEBUG
#ifdef TESTFLIGHT
#define LOG_NETWORK(level, ...) TFLog((@"%s [Line %d] " __FORMAT__), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
#define LOG_GENERAL(level, ...) TFLog((@"%s [Line %d] " __FORMAT__), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
#define LOG_GRAPHICS(level, ...) TFLog((@"%s [Line %d] " __FORMAT__), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
#define LOG_MEMORY(level, ...) TFLog((@"%s [Line %d] " __FORMAT__), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
#else
#define LOG_NETWORK(level, ...) {LogMessageF(__FILE__,__LINE__,__FUNCTION__,@"network",level,__VA_ARGS__);LoggerFlush(NULL,YES);}
#define LOG_GENERAL(level, ...) {LogMessageF(__FILE__,__LINE__,__FUNCTION__,@"general",level,__VA_ARGS__);LoggerFlush(NULL,YES);}
#define LOG_GRAPHICS(level, ...) {LogMessageF(__FILE__,__LINE__,__FUNCTION__,@"graphics",level,__VA_ARGS__);LoggerFlush(NULL,YES);}
@onevcat
onevcat / system_lang
Created February 23, 2012 12:56
当前系统语言
-(NSString *) currentLanguage
{
return [NSUserDefaults standardUserDefaults][@"AppleLanguages"][0];
}
@onevcat
onevcat / NSData+Base64.h
Created February 24, 2012 15:11 — forked from 0xced/NSData+Base64.h
NSData Base64 category
//
// Created by Cédric Luthi on 2012-02-24.
// Copyright (c) 2012 Cédric Luthi. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSData (Base64)
+ (id) dataWithBase64Encoding_xcd:(NSString *)base64String;
@onevcat
onevcat / nslogger
Created March 6, 2012 14:16
NSLogger配置
#import "LoggerClient.h"
#ifdef DEBUG
#define LOG_NETWORK(level, ...) {LogMessageF(__FILE__,__LINE__,__FUNCTION__,@"network",level,__VA_ARGS__);LoggerFlush(NULL,YES);}
#define LOG_GENERAL(level, ...) {LogMessageF(__FILE__,__LINE__,__FUNCTION__,@"general",level,__VA_ARGS__);LoggerFlush(NULL,YES);}
#define LOG_GRAPHICS(level, ...) {LogMessageF(__FILE__,__LINE__,__FUNCTION__,@"graphics",level,__VA_ARGS__);LoggerFlush(NULL,YES);}
#define LOG_MEMORY(level, ...) {LogMessageF(__FILE__,__LINE__,__FUNCTION__,@"memory",level,__VA_ARGS__);LoggerFlush(NULL,YES);}
#else
#define LOG_NETWORK(...) do{}while(0)
#define LOG_GENERAL(...) do{}while(0)
#define LOG_GRAPHICS(...) do{}while(0)
@onevcat
onevcat / opencv-for-ios-build-script.sh
Created March 29, 2012 14:03
opencv for ios script
#!/bin/bash
################################################################################
# This script will create universal binaries for OpenCV library for
# iOS-based devices (iPhone, iPad, iPod, etc).
# As output you obtain debug/release static libraries and include headers.
#
# This script was written by Eugene Khvedchenya
# And distributed under GPL license
# Support site: http://computer-vision-talks.com
################################################################################</p>
@onevcat
onevcat / gist:2437689
Created April 21, 2012 15:18
intropection1
id obj = someInstance;
if ([obj isKindOfClass:someClass])
{
someClass *classSpecifiedInstance = (someClass *)obj;
// Do Something to classSpecifiedInstance which now is an instance of someClass
//...
}
@onevcat
onevcat / gist:2462760
Created April 22, 2012 08:42
dynamicMethod
void dynamicMethodIMP(id self, SEL _cmd)
{
// implementation ....
}
//该方法在OC消息转发生效前被调用
+ (BOOL) resolveInstanceMethod:(SEL)aSEL
{
if (aSEL == @selector(resolveThisMethodDynamically))
{
+(BOOL)swizze {
Method oldMethod = class_getInstanceMethod(self, @selector(loadNibNamed:owner:options:));
if (!oldMethod) {
return NO;
}
Method newMethod = class_getInstanceMethod(self, @selector(loadPadNibNamed:owner:options:));
if (!newMethod) {
return NO;
}
-(NSArray *)loadPadNibNamed:(NSString *)name owner:(id)owner options:(NSDictionary *)options {
NSString *newName = [name stringByReplacingOccurrencesOfString:@"@pad" withString:@""];
newName = [newName stringByAppendingFormat:@"@pad"];
//判断是否存在
NSFileManager *fm = [NSFileManager defaultManager];
NSString* filepath = [[NSBundle mainBundle] pathForResource:newName ofType:@"nib"];
//这里调用的loadPadNibNamed:owner:options:实际为为交换后的方法,即loadNibNamed:owner:options:
if ([fm fileExistsAtPath:filepath]) {