Skip to content

Instantly share code, notes, and snippets.

Alexander Grebenyuk kean

Block or report user

Report or block kean

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View multi-platform-framework.xcconfig
// Configuration settings file format documentation can be found at:
// https://help.apple.com/xcode/#/dev745c5c974
SUPPORTED_PLATFORMS = iphoneos macosx appletvos watchos iphonesimulator appletvsimulator watchsimulator
SWIFT_VERSION = 4.2
IPHONEOS_DEPLOYMENT_TARGET = 9.0
MACOSX_DEPLOYMENT_TARGET = 10.11
View AsyncAwaitTest.swift
class AsyncAwaitTests: XCTestCase {
func testAsyncAwait() {
XCTAssertEqual(fakeAsyncAwait().wait().value, 3)
}
}
func fakeAsyncAwait() -> Future<Int, Error> {
return Future.async {
// Add delay to demonstrate that `await` for `Future<_, Never>` don't
@kean
kean / CancellationToken.swift
Last active Nov 15, 2018
CancellationToken
View CancellationToken.swift
// MARK: - CancellationTokenSource
/// Manages cancellation tokens and signals them when cancellation is requested.
///
/// All `CancellationTokenSource` methods are thread safe.
final class CancellationTokenSource {
/// Returns `true` if cancellation has been requested.
var isCancelling: Bool {
_lock.lock(); defer { _lock.unlock() }
return _observers == nil
@kean
kean / spacers.swift
Last active Jan 10, 2018
Stacks and Spacers
View spacers.swift
public typealias Stack = UIStackView
public extension Stack {
@nonobjc public convenience init(_ views: UIView..., with: (UIStackView) -> Void = { _ in }) {
self.init(arrangedSubviews: views)
with(self)
}
@nonobjc public convenience init(_ views: [UIView], axis: UILayoutConstraintAxis = .horizontal, spacing: CGFloat = 0, alignment: UIStackViewAlignment = .fill, distribution: UIStackViewDistribution = .fill) {
self.init(arrangedSubviews: views)
@kean
kean / AutoRetry.swift
Last active Oct 23, 2019
Smart Auto Retry using RxSwift
View AutoRetry.swift
// The MIT License (MIT)
//
// Copyright (c) 2017 Alexander Grebenyuk (github.com/kean).
import Foundation
import RxSwift
import RxCocoa
extension ObservableType {
@kean
kean / CancellationToken.swift
Last active Dec 17, 2017
Cancellation Token in Swift
View CancellationToken.swift
// The MIT License (MIT)
//
// Copyright (c) 2017 Alexander Grebenyuk (github.com/kean).
import Foundation
/// Manages cancellation tokens and signals them when cancellation is requested.
///
/// All `CancellationTokenSource` methods are thread safe.
public final class CancellationTokenSource {
View Client.swift
// The MIT License (MIT)
//
// Copyright (c) 2017 Alexander Grebenyuk (github.com/kean).
import Foundation
import Alamofire
import RxSwift
import RxCocoa
@kean
kean / CtCI-6h-problem-4.9.markdown
Last active Nov 14, 2019
CtCI 6h Edition, Problem 4.9: BST Sequences.
View CtCI-6h-problem-4.9.markdown

Problem 4.9. BST Sequences: A binary search tree was created by traversing through an array from left to right and inserting each element. Given a binary search tree with distinct elements, print all possible arrays that could have led to this tree.

Solution.

Let's start with an example.

    4
   / \
  2   5 
@kean
kean / List.swift
Last active Feb 14, 2017
Proof-of-concept List as Swift Enum
View List.swift
// The MIT License (MIT)
//
// Copyright (c) 2017 Alexander Grebenyuk (github.com/kean).
import Foundation
/// Proof-of-concept List implementation, not optimized in any way.
///
/// Usage:
///
@kean
kean / Nuke.podspec
Last active Sep 16, 2016
Nuke 4.0-beta3 iOS 8
View Nuke.podspec
Pod::Spec.new do |s|
s.name = 'Nuke'
s.version = '4.0-beta3'
s.summary = 'A powerful image loading and caching framework'
s.description = <<-EOS
A powerful image loading and caching framework.
Has full featured UI extensions, support for image filters, optional Alamofire and FLAnimatedImage plugins and [more](https://github.com/kean/Nuke).
EOS
You can’t perform that action at this time.