Skip to content

Instantly share code, notes, and snippets.

View pavelosipov's full-sized avatar

Pavel Osipov pavelosipov

View GitHub Profile
@pavelosipov
pavelosipov / clone.sh
Created July 10, 2021 14:45
Cloning folder with related history
# Let's consider some demo repository contains foo folder in its
# root along with some other stuff. We want to make clone of foo
# and preserve the history of commits for the files inside it.
# The new name for the foo's clone will be bar.
# The steps
# 1. Installing required dependency https://github.com/newren/git-filter-repo
# brew install git-filter-repo
@pavelosipov
pavelosipov / main.swift
Created June 8, 2021 14:15
PartitioningIndex Index Benchmarks
import Algorithms
import CollectionsBenchmark
// Adaptation of original solution at
// https://github.com/objcio/OptimizingCollections/blob/master/Sources/SortedArray.swift
extension Collection {
@inlinable
func partitioningIndex2(
where belongsInSecondPartition: (Element) throws -> Bool
) rethrows -> Index where Index == Int {
@pavelosipov
pavelosipov / MRCAppDelegate.m
Last active April 17, 2019 12:20
Leak aware resetting root ViewController.
@implementation MRCAppDelegate
- (void)p_updateWindowWithRootViewController:(nullable UIViewController *)controller
completionBlock:(nullable dispatch_block_t)completionBlock {
if (!self.window) {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible];
}
val rootViewController = self.window.rootViewController;
val resetRootViewControllerBlock = ^{
@pavelosipov
pavelosipov / POSLens.m
Created December 29, 2018 06:05
POSLens with data race inside
//
// POSLens.m
// POSLens
//
// Created by Pavel Osipov on 06/02/2018.
// Copyright © 2018 Pavel Osipov. All rights reserved.
//
#import "POSLens.h"
@pavelosipov
pavelosipov / crash.log
Created December 29, 2018 05:44
RWLock sample crashlog
Incident Identifier: CE2D3A63-9CB2-4885-9AF8-694903467129
CrashReporter Key: 4EA4EE9A-0B10-411B-8144-593752693588
Hardware Model: iPhone7,2
Process: MRCloudApp [2572]
Path: /var/containers/Bundle/Application/4CE776FA-A9E3-4B87-B660-32D90786733A/MRCloudApp.app/MRCloudApp
Identifier: ru.mail.cloud
Version: 6.2.6 (6951)
Code Type: ARM-64
Parent Process: ??? [1]
@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 / 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];
}
@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.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
@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;
}