Skip to content

Instantly share code, notes, and snippets.

View vl4dimir's full-sized avatar

Vladimir Mitrović vl4dimir

View GitHub Profile
@interface ExtendedManagedObject : NSManagedObject {
BOOL traversed;
}
@property (nonatomic, assign) BOOL traversed;
- (NSDictionary*) toDictionary;
- (void) populateFromDictionary:(NSDictionary*)dict;
+ (ExtendedManagedObject*) createManagedObjectFromDictionary:(NSDictionary*)dict
inContext:(NSManagedObjectContext*)context;
@interface UIImage (Resizing)
- (UIImage*) resizedImageWithSize:(CGSize)size;
@end
#import "UIImage+Resizing.h"
@implementation UIImage (Resizing)
/**
* Creates a resized, autoreleased copy of the image, with the given dimensions.
* @return an autoreleased, resized copy of the image
*/
- (UIImage*) resizedImageWithSize:(CGSize)size
{
#import <CoreData/CoreData.h>
@interface Photo : NSManagedObject {
}
@property (nonatomic, retain) NSString * imagePath;
@property (nonatomic, retain) NSString * thumbnailPath;
@property (nonatomic, retain) UIImage* image;
@property (nonatomic, retain, readonly) UIImage* thumbnail;
#import "UIImage+Resizing.h"
@implementation Photo
@dynamic imagePath;
@dynamic thumbnailPath;
static const CGFloat kThumbnailWidth = 75.0f;
static const CGFloat kThumbnailHeight = 75.0f;
static const CGFloat kJPEGQuality = 0.85f;
@vl4dimir
vl4dimir / AsyncTest.h
Created November 20, 2010 14:44
Example asynchronous GHUnit test.
#import <SenTestingKit/SenTestingKit.h>
@interface AsyncTests : SenTestCase {
NSCondition* condition;
BOOL operationSucceeded;
}
@end
@vl4dimir
vl4dimir / Singleton.h
Created December 17, 2010 13:23
An Objective-C singleton class.
//
// Singleton.h
//
#import <Foundation/Foundation.h>
@interface Singleton : NSObject {
}
@vl4dimir
vl4dimir / Stopwatch.h
Created January 4, 2011 15:29
Stopwatch class used for cumulative runtime timing.
#import <Foundation/Foundation.h>
@interface Stopwatch : NSObject {
// Name to be used for logging
NSString* name;
// Total run time
NSTimeInterval runTime;
// The start date of the currently active run
#import <Foundation/Foundation.h>
/**
SaneRSA abstracts away the gory details of the RSA algorithm and exposes a clean, minimal interface
to the outside world. The only data that needs to be fed into a SaneRSA instance is the desired RSA
key size and the remote end's RSA public key (which obviously needs to have the same key size).
*/
@interface SaneRSA : NSObject
@property (nonatomic, readonly) NSData* publicKey;
@vl4dimir
vl4dimir / VectorFieldInterpolation.cs
Last active November 6, 2016 21:51
The math for interpolating a vector on an arbitrary location inside a vector field.
public Vector3 VectorAt(float x, float y, float z) {
if (x < 0f) x = Mathf.Abs(x);
if (y < 0f) y = Mathf.Abs(y);
if (z < 0f) z = Mathf.Abs(z);
int floorX = Mathf.FloorToInt(x);
float tx = x - floorX;
floorX %= Dimension;
int ceilX = Mathf.CeilToInt(x) % Dimension;