Skip to content

Instantly share code, notes, and snippets.

View valexa's full-sized avatar
💼
Open for work

Vlad Alexa valexa

💼
Open for work
View GitHub Profile
- (CAKeyframeAnimation *)negativeShake:(NSRect)frame{
int numberOfShakes = 4;
float durationOfShake = 0.5f;
float vigourOfShake = 0.05f;
CAKeyframeAnimation *shakeAnim = [CAKeyframeAnimation animation];
CGMutablePathRef shakePath = CGPathCreateMutable();
CGPathMoveToPoint(shakePath, NULL, NSMinX(frame), NSMinY(frame));
int index;
Thread 0 Crashed:
0 libSystem.B.dylib 0x30c8e0a0 __kill + 8
1 libSystem.B.dylib 0x30c8e090 *_kill
2 libSystem.B.dylib 0x30c8e082 raise
3 libSystem.B.dylib 0x30ca220a abort
4 libstdc++.6.dylib 0x32944a1c __gnu_cxx::__verbose_terminate_handler() + 376
5 libobjc.A.dylib 0x335657c4 _objc_terminate
6 libstdc++.6.dylib 0x32942dee __cxxabiv1::__terminate(void (*)()) + 46
7 libstdc++.6.dylib 0x32942e42 std::terminate() + 10
8 libstdc++.6.dylib 0x32942f12 __cxa_throw + 78
#import "VAUserDefaults.h"
@implementation VAUserDefaults
- (id)initWithPlist:(NSString *)plist{
if (self = [super init]) {
//listen for notifications
[[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(theEvent:) name:@"VAUserDefaultsTo" object:nil];
NSArray *sortedFirstNames = [firstNames sortedArrayUsingFunction:familyNameCompare context:NULL];
NSInteger familyNameCompare(NSString *one, NSString *two, void *context)
{
NSArray *sortedFamilyNames = [[FirstNamesAndFamilyNames allValues] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
NSString *oneName = [FirstNamesAndFamilyNames objectForKey:one];
NSString *twoName = [FirstNamesAndFamilyNames objectForKey:two];
@interface VAImage : UIView <VAUrlConnectionDelegate> {
VAUrlConnection *conn;
}
- (void) connectionDidFinish:(VAUrlConnection *)theConnection;
@implementation VAImage
@valexa
valexa / editNestedDict
Created April 18, 2011 13:42
a method for changing objects inside deeply nested dictionaries
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
//create a example nested dictionary with just 4 levels
NSMutableDictionary *parent = [[[NSMutableDictionary alloc] init] autorelease];
NSDictionary *thirdChild = [NSDictionary dictionaryWithObjectsAndKeys:@"bi",@"l4",@"nar",@"l4_", nil];
NSDictionary *secondChild = [NSDictionary dictionaryWithObjectsAndKeys:thirdChild,@"l3",@"bar",@"l3_", nil];
NSDictionary *firstChild = [NSDictionary dictionaryWithObjectsAndKeys:secondChild,@"l2",secondChild,@"l2_", nil];
[parent setObject:firstChild forKey:@"l1"];
[parent setObject:firstChild forKey:@"l1_"];
@valexa
valexa / gist:1273279
Created October 9, 2011 04:12
1 to 1 mapping bug
#import "DetailsDataSource.h"
@implementation DetailsDataSource
@synthesize rootItems;
- (id)init
{
self = [super init];
@valexa
valexa / hash or isEqual issue
Created December 17, 2011 14:59
changing [ret description] to ret does not work as expected
NSMutableArray *ivarPrevious = [NSMutableArray arrayWithCapacity:1];
-(void)foo
{
NSMutableArray *newivarPrevious = [NSMutableArray arrayWithCapacity:1];
for (...){
NSMutableDictionary *ret = [NSMutableDictionary dictionaryWithCapacity:1];
[ret setObject:foo forKey:@"foo"];
[ret setObject:bar forKey:@"bar"];
[newivarPrevious addObject:[ret description]];
@valexa
valexa / gist:1808794
Created February 12, 2012 14:29
self accessor gotcha
@interface AppDelegate : NSObject <NSApplicationDelegate> {
NSMutableString *retainedProperty; //explicitly declaring ivar backing is only required for the 32 bit runtime, is automatically added by the compiler for 64 bit
}
@property (retain) NSMutableString *retainedProperty;
@end
@implementation AppDelegate
@valexa
valexa / gist:1809438
Created February 12, 2012 16:23
nsstrings
NSString *foo = @"foo";
NSString *bar = [NSString stringWithString:@"bar"];
NSString *baz = [[NSString alloc] initWithString:@"baz"];
NSMutableString *bax = [NSMutableString stringWithString:@"bax"];
NSData *objData = [NSData dataWithBytes:foo length:malloc_size(foo)];
NSLog(@"%s foo contains %@, hash %lu, retain %i",class_getName(object_getClass(foo)),objData,[foo hash],[foo retainCount]);
objData = [NSData dataWithBytes:bar length:malloc_size(bar)];
NSLog(@"%s bar contains %@, hash %lu, retain %i",class_getName(object_getClass(bar)),objData,[bar hash],[bar retainCount]);