Skip to content

Instantly share code, notes, and snippets.

//
// KeychainBehaviourTests.m
//
// Created by Roman Baulin on 25/04/2017.
// Copyright © 2017. All rights reserved.
//
//
// see SecBase.h and osstatus.com and to investigate keychain error codes
//
@rbaulin
rbaulin / UIImage+ImageEffects.h
Last active January 9, 2017 09:38
UIImage+ImageEffects.m presented on WWDC 2013
/*
File: UIImage+ImageEffects.h
Abstract: This is a category of UIImage that adds methods to apply blur and tint effects to an image. This is the code you’ll want to look out to find out how to use vImage to efficiently calculate a blur.
Version: 1.0
Copyright (C) 2013 Apple Inc. All Rights Reserved.
*/
@import UIKit;
@implementation NSArray (FDMapping)
// import, array diff
// https://github.com/glebd/google-toolbox-for-mac/blob/master/Foundation/GTMNSArray%2BMerge.m
// https://github.com/Wondermall/Doppelganger
// https://github.com/Basket/BKDeltaCalculator/blob/master/BKDeltaCalculator/BKDeltaCalculator.m
+ (void)ag_mapSourceArray:(NSArray *)source toDestArray:(NSArray *)dest sourceKey:(id (^)(id obj))sourceKeyBlock destKey:(id (^)(id obj))destKeyBlock compare:(NSComparisonResult (^)(id, id))compareBlock match:(void (^)(id, id))matchBlock {
NSArray *sortedSource = [source sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
@rbaulin
rbaulin / rand-nsstring.m
Last active June 6, 2016 17:54
random NSString in objective-c
NSString *rand_str() {
NSString *alphabet = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXZY0123456789";
u_int32_t len = arc4random_uniform(20) + 5;
NSMutableString *s = [NSMutableString stringWithCapacity:len];
for (NSUInteger i = 0U; i < len; i++) {
u_int32_t r = arc4random() % [alphabet length];
unichar c = [alphabet characterAtIndex:r];
[s appendFormat:@"%C", c];
}
return s;
@rbaulin
rbaulin / ps_build_icons.js
Last active February 22, 2016 13:56
Create icon pack for iOS or Android devices. Recommended source image size is 1024x1024 px 72 dp, make sure visible layer is selected. Workflow: source image is flattened, bicubic resize applied for each size, results saved in /output folder in source directory. Best practice: create photoshop Action with script, bind it to some hotkey.
// Created by Roman Baulin on 17.05.2012
#target photoshop
// in case we double clicked the file
app.bringToFront();
var doc = app.activeDocument;
var startState = doc.activeHistoryState; // save for undo
var initialPrefs = app.preferences.rulerUnits; // will restore at end
- (instancetype)init
{
self = [super initWithStyle:UITableViewStyleGrouped];
if (self) {
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
@rbaulin
rbaulin / macros.h
Last active December 25, 2015 11:09
Urgent macros
#define IS_7_0 (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1)
#define IS_PAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_PHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_IPHONE_5 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 568.0f)
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
#ifdef DEBUG
# define LOG_MESSAGE(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
@rbaulin
rbaulin / ReactiveCocoaPower.m
Last active December 17, 2015 18:29
Find out what is item's URL and load it when ready. Oh yeah, and show me a loading screen if it takes more than 1 second for preparation. And call off the fuss if item has changed. Hell yeah, ReactiveCocoa.
self.currentItem = item;
RACSignal *itemChanged = [[RACObserve(self, currentItem) skip:1] take:1];
// prepare item until switched to other item
RACSignal *itemReady = [[item rac_prepareItem] takeUntil:itemChanged];
// show description if preparation takes more than 1 second
[[[[[RACSignal interval:1.] take:1]
takeUntil:itemReady]
deliverOn:[RACScheduler mainThreadScheduler]]
@rbaulin
rbaulin / multilineLabel.m
Last active December 17, 2015 18:09
Label with multiple lines, constrained to width. Use with -sizeToFit.
@interface MultilineLabel : UILabel
@property (nonatomic) CGFloat maximumWidth;
@end
@implementation MultilineLabel
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
_maximumWidth = 200;