Skip to content

Instantly share code, notes, and snippets.

@doskoi
doskoi / gist:595071
Created September 24, 2010 08:51
unicode enum
int i;
NSMutableString *string = [NSMutableString string];
for (i = 32; i < 55296; i++) {
if (!(i % 10)) [string appendString:@"\n"];
[string appendFormat:@"(%04X:%i)%C, ", i, i, i];
}
NSLog(@"%@", string);
@doskoi
doskoi / gist:944547
Created April 27, 2011 16:06
Log Last Object
#ifdef DEBUG
-(BOOL) respondsToSelector:(SEL)aSelector {
printf("SELECTOR: %s\n", [NSStringFromSelector(aSelector) UTF8String]);
return [super respondsToSelector:aSelector];
}
#endif
#ifdef DEBUG
#define DLog(...) NSLog(@"%s %@", __PRETTY_FUNCTION__, [NSString stringWithFormat:__VA_ARGS__])
#define ALog(...) [[NSAssertionHandler currentHandler] handleFailureInFunction:[NSString stringWithCString:__PRETTY_FUNCTION__ encoding:NSUTF8StringEncoding] file:[NSString stringWithCString:__FILE__ encoding:NSUTF8StringEncoding] lineNumber:__LINE__ description:__VA_ARGS__]
#else
#define DLog(...) do { } while (0)
#define ALog(...) NSLog(@"%s %@", __PRETTY_FUNCTION__, [NSString stringWithFormat:__VA_ARGS__])
#endif
@doskoi
doskoi / UIImage+Extras
Created May 17, 2011 18:19
UIImage Resize and Crop
@implementation UIImage (Extras)
#pragma mark -
#pragma mark Scale and crop image
- (UIImage*)imageByScalingAndCroppingForSize:(CGSize)targetSize
{
UIImage *sourceImage = self;
UIImage *newImage = nil;
CGSize imageSize = sourceImage.size;
//
// SynthesizeSingleton.h
// CocoaWithLove
//
// Created by Matt Gallagher on 20/10/08.
// Copyright 2009 Matt Gallagher. All rights reserved.
//
// Permission is given to use this source code file without charge in any
// project, commercial or otherwise, entirely at your risk, with the condition
// that any redistribution (in part or whole) of source code must retain
@doskoi
doskoi / gist:1069240
Created July 7, 2011 10:12
Unity3D GUI Resolution
function OnGUI() {
var screenScale: float = Screen.width / 480.0;
var scaledMatrix: Matrix4x4 = Matrix4x4.identity.Scale(Vector3(screenScale,screenScale,screenScale));
GUI.matrix = scaledMatrix;
// then do the rest of your GUI as per normal, using the 480x320 screen size you had for your standard res iPhone app
}
Here are some regex script use in vim to help you translate objc code to cpp version.It is not perfect since it just could translate nearly 80% code correctly.
how to use it :
1.open mac terminal
2.run vim open the objec-code file
3.copy the regex below
4.click the edit->paste on the terminal menu
5.prees enter key
6.repeat step 4 - 5 seviral times
7.done
@doskoi
doskoi / gist:1653030
Created January 21, 2012 15:12
Turn FIXME, TODO, and !!! comments into compiler warnings within xcode
KEYWORDS="TODO|FIXME|\?\?\?:|\!\!\!:"
find ${SRCROOT} \( -name "*.h" -or -name "*.m" \) -print0 | \
xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*\$" | \
perl -p -e "s/($KEYWORDS)/ warning: \$1/"
@doskoi
doskoi / gist:1653064
Created January 21, 2012 15:26
Convert an Image (UIImage) to Grayscale
- (UIImage *)convertImageToGrayScale:(UIImage *)image
{
// Create image rectangle with current image width/height
CGRect imageRect = CGRectMake(0, 0, image.size.width, image.size.height);
// Grayscale color space
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
// Create bitmap content with current image size and grayscale colorspace
CGContextRef context = CGBitmapContextCreate(nil, image.size.width, image.size.height, 8, 0, colorSpace, kCGImageAlphaNone);
@doskoi
doskoi / gist:1653073
Created January 21, 2012 15:30
Device Detection
#import <sys/utsname.h>
enum {
MODEL_IPHONE_SIMULATOR,
MODEL_IPOD_TOUCH,
MODEL_IPHONE,
MODEL_IPHONE_3G
};
@interface DeviceDetection : NSObject