Skip to content

Instantly share code, notes, and snippets.

@delebedev
delebedev / gist:1670310
Created January 24, 2012 14:03
Reversed array enumeration
NSArray *array = [NSArray array];
NSEnumerator *enumerator = [array reverseObjectEnumerator];
for (id element in enumerator) {
if ([element isKindOfClass:[NSString class]]) {
break;
}
}
@delebedev
delebedev / DLBaseTableViewCell.h
Created June 9, 2012 20:34
Handy table view cells dequeuing + custom NIB support
//
// DLBaseTableViewCell.h
// Kawiky
//
// Created by Denis Lebedev on 2/24/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
@interface DLBaseTableViewCell : UITableViewCell
@delebedev
delebedev / PorterStemmer.h
Created November 6, 2012 11:58
Porter's stemmer for Russian language (Objective-C)
//
// PorterStemmer.h
// PorterStemmer
//
// Created by Denis Lebedev on 11/5/12.
// Copyright (c) 2012 Denis Lebedev. All rights reserved.
//
#import <Foundation/Foundation.h>
@delebedev
delebedev / TestSemaphor.h
Last active December 10, 2015 04:18
unit testing of completion blocks
//
// TestSemaphor.h
// BillsApp
//
// Created by Marin Todorov on 17/01/2012.
// Copyright (c) 2012 Marin Todorov. All rights reserved.
//
#import <Foundation/Foundation.h>
@delebedev
delebedev / gist:4663488
Created January 29, 2013 11:05
alloc for non-NSObject subclass
+ (id)alloc
{
MAObject *obj = calloc(1, class_getInstanceSize(self));
obj->isa = self;
obj->retainCount = 1;
return obj;
}
#import "KWHCMatcher.h"
#import "KWMessageTracker.h"
#import "Kiwi.h"
@interface NSNotificationMatcher : NSObject <HCMatcher>
{
NSDictionary *_userInfo;
}
+ (id)matcherWithUserInfo:(NSDictionary *)dictionary;
@delebedev
delebedev / gist:7265957
Created November 1, 2013 14:09
Bind RAC to AFNetworking
- (RACSignal *)enqueueRequestWithMethod:(NSString *)method path:(NSString *)path parameters:(NSDictionary *)parameters cacheTime:(NSTimeInterval)expirationTime {
NSAssert(self.cluster, @"cluster should be set before request.");
NSAssert(self.applicationID.length != 0, @"applicationID should be set before request.");
NSMutableURLRequest *request = [self requestWithMethod:method path:path parameters:parameters];
RACSignal *signal = [RACSignal createSignal:^(id<RACSubscriber> subscriber) {
AFHTTPRequestOperation *operation;
operation = [self HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *op, id JSON) {
NSDictionary *errorDictionary = JSON[@"error"];
@delebedev
delebedev / gist:7266332
Created November 1, 2013 14:36
NSURLCache trick to control cache on client side
typedef NSCachedURLResponse * (^WGNCachedResponseBlock)(NSURLConnection *connection, NSCachedURLResponse *cachedResponse);
- (WGNCachedResponseBlock)cacheResponseBlockWithTime:(NSTimeInterval)time {
return ^NSCachedURLResponse *(NSURLConnection *connection, NSCachedURLResponse *cachedResponse) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)[cachedResponse response];
NSDictionary *headers = [httpResponse allHeaderFields];
NSString *cacheControl = [headers valueForKey:@"Cache-Control"];
NSString *expires = [headers valueForKey:@"Expires"];
if((cacheControl == nil) && (expires == nil)) {
@delebedev
delebedev / OHHTTPStubs+ShortBlocks.h
Created November 1, 2013 16:01
OHTTPStubs+ShortBlocks
void (^stubResponseWithHeaders)(NSString *, NSString *, NSDictionary *);
void (^stubResponse)(NSString *, NSString *);
void (^stubResponseWithStatusCode)(NSString *, int);
#import <Kiwi/Kiwi.h>
#import "WGTitleView.h"
//открываем доступ к внутренним свойствам
@interface WGTitleView ()
@property (strong, nonatomic) UILabel *titleLabel;
@property (strong, nonatomic) UILabel *subtitleLabel;