Skip to content

Instantly share code, notes, and snippets.

View xNekOIx's full-sized avatar
🇺🇦

Konstantin Bychkov xNekOIx

🇺🇦
View GitHub Profile
@xNekOIx
xNekOIx / AutoLocalize.h
Last active December 18, 2015 00:29 — forked from sma/AutoLocalize.h
//
// AutoLocalize.h
// AutoLocalize
//
// Created by Stefan Matthias Aust on 05.08.11.
// Copyright 2011 I.C.N.H. All rights reserved.
//
#import <UIKit/UIKit.h>
@xNekOIx
xNekOIx / iOSAutoLayoutDebug
Last active July 7, 2020 17:45
iOS AutoLayout debug
po [[UIWindow keyWindow] _autolayoutTrace] // prints layouts ambiguity
po [UIViewController _printHierarchy] // prints view controllers hierarchy
po [view constraintsAffectingLayoutForAxis:0] // horizontal
po [view constraintsAffectingLayoutForAxis:1] // vertical
[view hasAmbiguousLayout] // BOOL
[view exerciseAmbiguityInLayout] // visualizing ambiguity
UIViewAlertForUnsatisfiableConstraints // symbolic breakpoint
UIConstraintBasedLayoutDebugging // symbolic breakpoint
@xNekOIx
xNekOIx / PSFormValidation.h
Last active December 20, 2015 16:49
Form Validation
#import <Foundation/Foundation.h>
extern NSString* const PSFormValidationErrorDomain;
typedef NS_ENUM(NSInteger, PSFormValidationError) {
PSFormValidationErrorUndefined = 0,
PSFormValidationErrorEmailEmpty,
PSFormValidationErrorUsernameEmpty,
PSFormValidationErrorPasswordEmpty,
PSFormValidationErrorPasswordTooShort,
// Inspired by Mattt
@interface NOLoggingAssertionHandler : NSAssertionHandler
@end
// make image from color
#import <UIKit/UIKit.h>
@interface UIImage (NKOGraphics)
+ (UIImage*)nko_imageWithColor:(UIColor*)color;
+ (UIImage*)nko_imageWithColor:(UIColor*)color size:(CGSize)size;
+ (UIImage*)nko_imageWithColor:(UIColor*)color size:(CGSize)size cornerRadius:(CGFloat)radius;
+ (UIImage*)nko_gradientImageWithTopColor:(UIColor*)topColor bottomColor:(UIColor*)bottomColor size:(CGSize)size radius:(CGFloat)radius;
@xNekOIx
xNekOIx / UIDevice+NKOSVersionCheck.h
Last active August 29, 2015 14:02
iOS version check
#import <Foundation/Foundation.h>
@interface UIDevice(NKOSVersionCheck)
+ (BOOL)nko_isRunningOnIOS7OrLater;
@end
@xNekOIx
xNekOIx / Regex.swift
Last active August 29, 2015 14:12 — forked from mattt/regex.swift
Swift String literal regular expression + switch pattern match operator
//
// Mattt's example from NSHipster updated for 8.1 API. (NSHipster article http://nshipster.com/swift-literal-convertible/ )
// Additions for pattern matching for use in switch statements taken from http://lesstroud.com/swift-using-regex-in-switch-statements/
//
// -------
// xNekOIx
//
import Foundation
@xNekOIx
xNekOIx / RenameImages
Created May 12, 2015 10:16
Batch rename images
sudo ls | sed 's/\(.*\)\(\..*\)/mv "\1\2" "\1@2x\2"/p' | sh
@xNekOIx
xNekOIx / PewPew.swift
Last active August 29, 2015 14:22
Declare class inside function.
protocol SomeProtocol: class {
func pew() -> String
}
class SomeClass {
func someFunc() -> SomeProtocol {
let someClosure = { () -> SomeProtocol in
class PewPew: SomeProtocol {
func pew() -> String {
@xNekOIx
xNekOIx / DotsActivity.m
Created July 31, 2015 15:39
Dots activity indicator
RACSignal* activitySignal = [[RACObserve(self, viewModel.inProgress) map:^id(NSNumber* value) {
if (value.boolValue == NO) return [RACSignal return:@""];
return [[RACSignal interval:0.5 onScheduler:[RACScheduler mainThreadScheduler]]
scanWithStart:@"."
reduce:^id(NSString* previous, id current) {
if (previous.length > 2) return @".";
return [previous stringByAppendingString:@"."];
}];
}] switchToLatest];