Skip to content

Instantly share code, notes, and snippets.

View ariok's full-sized avatar
🧠
CodeLoving

Yari @bitwaker ariok

🧠
CodeLoving
View GitHub Profile
// Playground - noun: a place where people can play
import Cocoa
/* Node class implementation */
class Node
{
var data:String?
var link:Node?
@ariok
ariok / [CoreAnimation]AnimationGroup.m
Created December 30, 2013 21:49
Group of animations in CA
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"opacity"];
anim.fromValue = @(0.0);
anim.toValue = @(1.0);
CGPoint point = [self createPosition]
CABasicAnimation *anim2 = [CABasicAnimation animationWithKeyPath:@"position"];
anim2.fromValue = [NSValue valueWithCGPoint:label.position];
anim2.toValue = [NSValue valueWithCGPoint:point];
CAAnimationGroup *group = [CAAnimationGroup animation];
@ariok
ariok / [CoreAnimation]PropertiesAnimation.m
Created December 30, 2013 18:14
Animate a property of a layer and implicitly animate the result.
@dynamic theProperty; //The property should set as dynamic
- (id)initWithLayer:(id)layer {
if (self = [super initWithLayer:layer]) {
if ([layer isKindOfClass:[PieMask class]]) {
YourLayer *currentPresentation = (YourLayer *)layer;
self.theProperty = currentPresentation.theProperty;
@ariok
ariok / [CoreData]CustomProperties.m
Created December 16, 2013 18:09
Setter method for NSManagedObject subclass properties.
// This assumes we have an NSManagedObject with the NSDate* date property
- (void)setDate:(NSDate *)date{
[self willChangeValueForKey:@"date"];
[self setPrimitiveValue:date forKey:@"date"];
[self didChangeValueForKey:@"date"];
//If needed
//[self updateOtherData];
}
@ariok
ariok / INDEX.md
Created December 11, 2013 12:12
Testing the Gists Indexer by KilianC (https://github.com/kilianc/yari-gists-indexer)
@ariok
ariok / [Localization]ForceFallbackLanguage.m
Created December 11, 2013 11:25
Force the translation to a defined language. (I use this function to force the fallback language to Italian. I didn't find a way to make NSLocalizedString work with italian as fallback. your comments/suggestions are welcome :) )
NSString * L(NSString * translation_key, NSString * lang) {
NSString * s = NSLocalizedString(translation_key, nil);
// Force translation as "Lang" language if no translations are found
if ([s isEqualToString:translation_key]) {
NSString * path = [[NSBundle mainBundle] pathForResource:lang ofType:@"lproj"];
NSBundle * languageBundle = [NSBundle bundleWithPath:path];
s = [languageBundle localizedStringForKey:translation_key value:@"" table:nil];
}
@ariok
ariok / [pattern]Singleton.m
Created December 8, 2013 11:21
Basic Singleton pattern implementation
+ (AnythingManager*)sharedAnythingManager{
static AnythingManager *anythingManager;
static dispatch_once_t token;
dispatch_once(&token, ^{
anythingManager = [[AnythingManager alloc]init];
});
return anythingManager;
@ariok
ariok / [Date]AddingMonths.m
Created December 6, 2013 13:11
Adding some months to an existent date.//
+ (NSDate*)dateAddingMonths:(NSInteger)months{
NSDateComponents* dateComponents = [[NSDateComponents alloc]init];
[dateComponents setMonth:months];
NSCalendar* calendar = [NSCalendar currentCalendar];
NSDate* newDate = [calendar dateByAddingComponents:dateComponents toDate:self options:0]; //NSDate category
return newDate;
}
@ariok
ariok / [CoreData]newobject.m
Created December 5, 2013 15:48
Add a new object in Core Data.
Entry *entry = [NSEntityDescription insertNewObjectForEntityForName:@"Entry" inManagedObjectContext:self.managedObjectContext];
entry.amount = [NSNumber numberWithFloat:[self.UI_amountTextField.text floatValue]];
[self.managedObjectContext save:&error];
@ariok
ariok / [Date]MonthsNames.m
Last active December 30, 2015 03:29
Get an array with months names
- (NSArray*)monthsNames{
if (!_monthsNames) {
NSDateFormatter * df = [[NSDateFormatter alloc] init];
[df setLocale:[[NSLocale alloc] initWithLocaleIdentifier:[[NSLocale preferredLanguages] objectAtIndex:0]]];
_monthsNames = [df monthSymbols];
}
return _monthsNames;
}