Skip to content

Instantly share code, notes, and snippets.

View pavelosipov's full-sized avatar

Pavel Osipov pavelosipov

View GitHub Profile
@pavelosipov
pavelosipov / sketch.m
Created June 5, 2015 08:09
Resend profile requests
- (RACSignal *)updateState {
return [[self updateCheckWithDelay:0.0f] catch:^RACSignal *(NSError *error) {
[[self updateCheckUntilSucceded] subscribeNext:^(id x) {
NSLog(@"new profile: %@", x);
}];
return [RACSignal error:error];
}];
}
- (RACSignal *)updateCheckWithDelay:(NSTimeInterval)delaySec {
@pavelosipov
pavelosipov / main.m
Last active August 29, 2015 14:22
Refresh profile
- (void)refreshProfile {
RACSignal *fetchSignal = [[self fetchProfile] replayLast];
[fetchSignal subscribeNext:^(id x) {
// update profile
// goto itunes
// etc.
}];
[[fetchSignal filter:^BOOL(id value) {
return [value isEqualToNumber:@(499)];
}] subscribeNext:^(id x) {
@pavelosipov
pavelosipov / Endpoint.m
Last active August 29, 2015 14:23
Endpoints
@protocol CMRRequest <NSObject>
@property (nonatomic, readonly) id CMRHTTPOptions;
- (NSMutableURLRequest *)buildRequestWithBaseURL:(NSURL* )baseURL;
@end
@protocol CMREndpoint <NSObject>
@pavelosipov
pavelosipov / open_word.m
Created July 3, 2015 10:25
MS Word Integration
// CloudShare SharePoint
NSString *kCSFolderURL = @"http://uvo13v3ow3jmtx8iunr.env.cloudshare.com/Shared Documents/";
NSString *kCSFilename = @"85b5a608d1e533af644251901044da15.docx";
// Mail.Ru SharePoint
NSString *kMRFolderURL = @"https://owa.attachmail.ru/Shared Documents/";
NSString *kMRFilename = @"1.docx";
// Target SharePoint
BOOL useMRSP = YES;
@pavelosipov
pavelosipov / NSURLRequestDemo.m
Last active December 19, 2015 21:13
Embedding NSInputStream into NSURLRequest
- (NSURLSessionUploadTask *)uploadData:(NSData *)data toURL:(NSURL *)URL {
NSMutableHTTPRequest *request = [[NSMutableHTTPRequest alloc] initWithURL:URL];
request.HTTPMethod = @"PUT";
request.HTTPBodyStream = [NSInputStream inputStreamWithData:data];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionUploadTask *task = [session uploadTaskWithStreamedRequest:request]
return task;
}
@pavelosipov
pavelosipov / NSInputStream+MRC.m
Last active December 20, 2015 15:31
Custom NSInputStream factory method
@interface NSInputStream (MRC)
+ (instancetype)mrc_inputStreamWithData:(NSData *)data;
@end
@implementation NSInputStream (MRC)
+ (instancetype)mrc_inputStreamWithData:(NSData *)data {
MRCDataStreamDataSource *dataSource = [[MRCDataStreamDataSource alloc] initWithData:data];
POSBlobInputStream *stream = [[POSBlobInputStream alloc] initWithDataSource:dataSource];
stream.shouldNotifyCoreFoundationAboutStatusChange = NO;
return stream;
@pavelosipov
pavelosipov / MRCDataStreamDataSource.h
Last active December 20, 2015 15:32
Custom NSInputStream
#import <POSInputStreamLibrary/POSBlobInputStreamDataSource.h>
@interface MRCDataStreamDataSource : NSObject <POSBlobInputStreamDataSource>
// The designated initializer.
- (nonnull instancetype)initWithData:(nonnull NSData *)data;
// Hidden initializers.
- (nonnull instancetype)init NS_UNAVAILABLE;
+ (nonnull instancetype)new NS_UNAVAILABLE;
@end
@pavelosipov
pavelosipov / AssetConversion.m
Created August 12, 2016 07:52
ALAsset from PHAsset
@implementation PHImageManager (MRCApp)
+ (RACSignal *)p_fetchALAssetForVideoAsset:(PHAsset *)asset {
POSRX_CHECK(asset);
PHVideoRequestOptions *options = [PHVideoRequestOptions new];
options.version = PHVideoRequestOptionsVersionCurrent;
options.deliveryMode = PHVideoRequestOptionsDeliveryModeHighQualityFormat;
options.networkAccessAllowed = YES;
return [self p_fetchALAssetForAsset:asset withURL:asset.mrc_videoAssetURL];
}
@interface POSThreadWatchDogReporter ()
@property (nonatomic, readonly) NSTimeInterval threshold;
@property (nonatomic, readonly) POSThreadWatchDog *watchDog;
@end
@implementation POSThreadWatchDogReporter
- (instancetype)initWithThreshold:(NSTimeInterval)threshold {
POSRX_CHECK([NSThread isMainThread]);
thread_t thread = mach_thread_self();
@pavelosipov
pavelosipov / MRCDataStreamDataSource.m
Created December 20, 2015 15:28
Custom NSInputStream implementation
#import "MRCDataStreamDataSource.h"
@interface MRCDataStreamDataSource ()
@property (nonatomic, readonly) NSData *data;
@property (nonatomic) NSUInteger readOffset;
@property (nonatomic, getter = isOpenCompleted) BOOL openCompleted;
@property (nonatomic) NSError *error;
@end
@implementation MRCDataStreamDataSource