Skip to content

Instantly share code, notes, and snippets.

@matnogaj
matnogaj / NSObject+IsNull.h
Last active August 29, 2015 14:02
NSObject+IsNull : check for nil and NSNull with one method
#import <Foundation/Foundation.h>
@interface NSObject (IsNull)
- (BOOL)isNull;
- (BOOL)isNotNull;
@end
@matnogaj
matnogaj / NSString+Compare.h
Last active August 29, 2015 14:02
Compare strings even if one of them is nil or NSNull
@interface
+ (BOOL)compareStringA:(NSString *)A andB:(NSString *)B;
@end
@matnogaj
matnogaj / gist:1f63f2f27bc724967521
Created October 7, 2014 07:47
CIFilter example
+ (UIImage *)something:(COProductCollectionViewCell *)view {
static EAGLContext *myEAGLContext;
static NSDictionary *options;
static CIContext *myContext;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
myEAGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
options = @{ kCIContextWorkingColorSpace : [NSNull null] };
- (CATransform3D)perspectiveTransformForProgress:(CGFloat)progress {
CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
rotationAndPerspectiveTransform = CATransform3DTranslate(rotationAndPerspectiveTransform, progress * [self menuWidth], 0.0f, 0.0f);
float scale = 1.0f - ((1.0f - kPerspectiveScale) * progress);
rotationAndPerspectiveTransform = CATransform3DScale(rotationAndPerspectiveTransform, scale, scale, 1.0f);
rotationAndPerspectiveTransform.m34 = (1.0f * kPerspectiveDistortionStrength) / -1000.0f;
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform,
@matnogaj
matnogaj / active architecture only
Created January 30, 2015 10:39
Setting project to build only active arch to NO during pods update
post_install do |installer_representation|
installer_representation.project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO'
end
end
end
@matnogaj
matnogaj / UIView+AnimatedConstraints.swift
Last active April 16, 2016 15:27
Change constraints and then call this method.
extension UIView {
func animateConstraints(animation:(()->())? = nil, completion:(()->())? = nil) {
setNeedsUpdateConstraints()
UIView.animateWithDuration(0.3,
animations: {
animation?()
self.layoutIfNeeded()
}) { _ in
completion?()
}
@matnogaj
matnogaj / gist:53b737aa3ad3e51d4f24
Created December 16, 2015 12:18
[Typhoon] Test assembly for testing
@implementation IntegrationTestUtils
+ (TyphoonComponentFactory*)testAssembly
{
TyphoonComponentFactory* factory = [[TyphoonBlockComponentFactory alloc] initWithAssemblies:@[
[MyAppAssembly assembly],
[MyAppKernel assembly],
[MyAppNetworkComponents assembly],
[MyAppPersistenceComponents assembly]
]];
@matnogaj
matnogaj / picker.swift
Last active March 14, 2022 05:58
Custom date picker with "infinite" hours and minutes
import UIKit
@objc protocol CustomDatePickerSourceDelegate:NSObjectProtocol {
func datePickerDidSelectDate(date:NSDate)
}
@objc class CustomDatePickerSource: NSObject {
enum Component:Int {
@matnogaj
matnogaj / NSDateFormatter+Cache.swift
Created February 13, 2016 00:01
NSDateFormatter cache
import Foundation
extension NSDateFormatter {
private static var cache:[String:NSDateFormatter] = [:]
static func dateFormatterForKey(key:String, initialize:((NSDateFormatter)->())? = nil) -> NSDateFormatter {
if let formatter = NSDateFormatter.cache[key] {
return formatter
} else {
let formatter = NSDateFormatter()
@matnogaj
matnogaj / NSNumberFormatter+Cache.swift
Created February 13, 2016 00:15
NSNumberFormatter+Cache
extension NSNumberFormatter {
private static var cache:[String:NSNumberFormatter] = [:]
static func numberFormatterForKey(key:String, initialize:((NSNumberFormatter)->())? = nil) -> NSNumberFormatter {
if let formatter = NSNumberFormatter.cache[key] {
return formatter
} else {
let formatter = NSNumberFormatter()
NSNumberFormatter.cache[key] = formatter
initialize?(formatter)