Skip to content

Instantly share code, notes, and snippets.

View jeksys's full-sized avatar

Eugene Yagrushkin jeksys

View GitHub Profile
@jeksys
jeksys / UISearchBar.m
Created July 7, 2011 19:53
Detecting when clear is clicked in UISearchBar (X button)
- (void)viewDidLoad {
//find the UITextField view within searchBar (outlet to UISearchBar)
//and assign self as delegate
for (UIView *view in searchBar.subviews){
if ([view isKindOfClass: [UITextField class]]) {
UITextField *tf = (UITextField *)view;
tf.delegate = self;
break;
}
}
@jeksys
jeksys / gist:1072578
Created July 8, 2011 19:15
scaleImage
- (UIImage *)scaleImage:(UIImage *)image toSize:(CGSize)newSize
{
UIGraphicsBeginImageContextWithOptions(newSize, YES, 0.0);
CGRect imageRect = {{0.0, 0.0}, newSize};
[image drawInRect:imageRect];
UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return scaledImage;
}
@jeksys
jeksys / gist:1077945
Created July 12, 2011 13:11
Singleton Objects - Lazy ini
Singleton Objects
Lazy initialization is common
@implementation FooController
// #1
+ (FooController *)sharedInstance
{
static dispatch_once_t once;
static FooController *instance;
dispatch_once(&once, ^{
@jeksys
jeksys / gist:1081144
Created July 13, 2011 19:32
dispatch_async Useful pattern to avoid blocking the main thread
Nested invocations provide asynchronous callbacks
• Communication between subsystems
-(IBAction)onClick:(NSButton *)sender
{
dispatch_async(account->queue,
^{
NSImageRep *image = renderAccountStatement(account);
dispatch_async(dispatch_get_main_queue(),^{
@jeksys
jeksys / gist:1095655
Created July 20, 2011 19:02
CALayer shadows
myView.layer.shadowOpacity = 0.8;
myView.layer.shadowRadius = 5.0;
myView.layer.shadowOffset = CGSizeZero;
myView.layer.shadowPath = [UIBezierPath bezierPathWithRect:myView.layer.bounds].CGPath;
@jeksys
jeksys / gist:1107826
Created July 26, 2011 19:56
Accelerometer
- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration{
static float prevX=0, prevY=0;
float accelX = acceleration.x * kFilterFactor + (1- kFilterFactor)*prevX;
float accelY = acceleration.y * kFilterFactor + (1- kFilterFactor)*prevY;
prevX = accelX;
prevY = accelY;
pitch = accelX;
}
@jeksys
jeksys / Lightning.h
Created August 23, 2011 19:19
Lighting, cocos2D
//
// Lightning.h
// Trundle
//
// Created by Robert Blackwood on 12/1/09.
// Copyright 2009 Mobile Bros. All rights reserved.
//
#import "cocos2d.h"
@jeksys
jeksys / gist:1268284
Created October 6, 2011 18:55
Log GCRect and GCPoint
#define NSLogFrame(description,aFrame) NSLog(@"%@ - {%0.0f:%0.0f}{%0.0f:%0.0f}", description, aFrame.origin.x, aFrame.origin.y, aFrame.size.width, aFrame.size.height);
#define NSLogPoint(description,aFrame) NSLog(@"%@ - {%0.0f:%0.0f}{%0.0f:%0.0f}", description, aFrame.origin.x, aFrame.origin.y, aFrame.size.width, aFrame.size.height);
@jeksys
jeksys / LoaderURL.h
Created October 7, 2011 18:40
Download URL
@interface LoaderURL : NSObject
{
NSMutableData *responseData;
NSURLConnection *connectionXML;
}
@property (nonatomic, copy) NSString *xmlFileName;
- (BOOL) updateFile;
@jeksys
jeksys / gist:1313867
Created October 25, 2011 19:03
Xcode log macros
#define CMLog(format, ...) NSLog(@"%s:%@", __PRETTY_FUNCTION__,[NSString stringWithFormat:format, ## __VA_ARGS__]);
#define MARK CMLog(@"%s", __PRETTY_FUNCTION__);
#define START_TIMER NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate];
#define END_TIMER(msg) NSTimeInterval stop = [NSDate timeIntervalSinceReferenceDate]; CMLog([NSString stringWithFormat:@"%@ Time = %f", msg, stop-start]);