Skip to content

Instantly share code, notes, and snippets.

View kostiakoval's full-sized avatar

Kostiantyn Koval kostiakoval

View GitHub Profile
@kostiakoval
kostiakoval / NSManagedObject+RFObject.h
Created January 9, 2014 10:08
ManagedObject Category
//
// NSManagedObject+RFObject.h
// PocketID
//
// Created by Konstantin Koval on 09/01/14.
// Copyright (c) 2014 Rocketfarm. All rights reserved.
//
#import <CoreData/CoreData.h>
@kostiakoval
kostiakoval / LanguageManager.h
Last active January 3, 2016 03:09
Localized Bundle strings for country ISO code
#import <Foundation/Foundation.h>
NSString* LocalizedStringForLanguage(NSString *countryCode, NSString * string);
@kostiakoval
kostiakoval / NSDictionary+Networking.h
Created January 20, 2014 10:31
NSDictionary+Networking
//
// NSDictionary+Networking.h
// PocketID
//
// Created by Konstantin Koval on 20/01/14.
// Copyright (c) 2014 Rocketfarm. All rights reserved.
//
#import <Foundation/Foundation.h>
@kostiakoval
kostiakoval / 0_reuse_code.js
Created February 24, 2014 08:35
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@kostiakoval
kostiakoval / swizzle.m
Created March 29, 2014 15:45
Method swizzling
+ (void)sf_swapSelector:(SEL)aOriginalSelector withSelector:(SEL)aSwappedSelector
{
Method originalMethod = class_getInstanceMethod(self, aOriginalSelector);
Method swappedMethod = class_getInstanceMethod(self, aSwappedSelector);
SEL newSelector = NSSelectorFromString([NSString stringWithFormat:@"sf_original_%@", NSStringFromSelector(aOriginalSelector)]);
class_addMethod([self class], newSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
class_replaceMethod([self class], aOriginalSelector, method_getImplementation(swappedMethod), method_getTypeEncoding(swappedMethod));
}
@kostiakoval
kostiakoval / mogenerator
Created March 29, 2014 15:47
mogenerator script example
mogenerator -m -O -M /autogenerated -H --template-var arc=true
// Reall example
mogenerator -m Model/Model.xcdatamodeld/Model.xcdatamodel -O Model -M Model/autogenerated -H Model --template-var arc=true
@kostiakoval
kostiakoval / StringEncryption.java
Created March 29, 2014 15:48
Encrypted SHA1 string for android
package no.rocketfarm.festivalcore.util;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class StringEncryption {
private static String convertToHex(byte[] data) {
StringBuilder buf = new StringBuilder();
@kostiakoval
kostiakoval / PrefUtils.java
Created March 29, 2014 15:49
SharedPreferences util
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
public class PrefUtils {
/**
* Called to save supplied value in shared preferences against given key.
* @param context Context of caller activity
@kostiakoval
kostiakoval / Associated-NSNumber.codesnippet
Last active August 29, 2015 13:57
Associated object. Associated-NSNumber.m and Associated.m are code snippets for creating methods for property with associated object. KKNSObject+Associated.h is a macro that can be use to automatically create associated methods for property.
- (<#type#>)<#propertyName#> {
return [objc_getAssociatedObject(self, _cmd) <#NSNumberMethod#>];
}
- (void)set<#propertyName#>:(<#type#>)object
{
objc_setAssociatedObject(self, @selector(<#propertyName#>), [NSNumber numberWith:object], OBJC_ASSOCIATION_);
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
attributes:(NSDictionary *)attributeDict
{
NSString *ident = [attributeDict objectForKey:@"id"];
KMLStyle *style = [_placemark style] ? [_placemark style] : _style;
// Style and sub-elements