Skip to content

Instantly share code, notes, and snippets.

View Rostmen's full-sized avatar
🍄
Working from home

Rostyslav Kobizsky Rostmen

🍄
Working from home
View GitHub Profile
@Rostmen
Rostmen / cblis.m
Created January 31, 2014 16:35 — forked from jchris/cblis.m
//
// CBLIncrementalStore.m
// CBLIncrementalStore
//
// Created by Christian Beer on 21.11.13.
// Copyright (c) 2013 Christian Beer. All rights reserved.
//
#import "CBLIncrementalStore.h"
@Rostmen
Rostmen / debounce-throttle.swift
Created July 10, 2018 03:53 — forked from simme/debounce-throttle.swift
Swift 3 debounce & throttle
//
// debounce-throttle.swift
//
// Created by Simon Ljungberg on 19/12/16.
// License: MIT
//
import Foundation
extension TimeInterval {
@Rostmen
Rostmen / UnsignedInteger.kt
Last active November 30, 2018 07:41
Unsigned Integer Kotlin
/**
* Rostyslav Kobyzskyi
* Unsigned Integer Utils
*/
private fun UByte.toByteArray() = toUInt().toByteArray(UByte.SIZE_BYTES)
private fun UShort.toByteArray() = toUInt().toByteArray(UShort.SIZE_BYTES)
private fun UInt.toByteArray() = toUInt().toByteArray(UInt.SIZE_BYTES)
private fun ByteArray.toUInt() = toUByteArray()
.mapIndexed { index, uByte -> uByte.toUInt() shl (UByte.SIZE_BITS * (count() - index - 1)) }
@Rostmen
Rostmen / distribute-coins-in-binary-tree.swift
Last active March 9, 2019 22:20
Distribute Coins in Binary Tree
/**
* Definition for a binary tree node.
* public class TreeNode {
* public var val: Int
* public var left: TreeNode?
* public var right: TreeNode?
* public init(_ val: Int) {
* self.val = val
* self.left = nil
* self.right = nil
@Rostmen
Rostmen / ShareReplayScope.swift
Last active July 12, 2020 21:29
ShareReplay Publisher with scope for Combine framework
import Foundation
import Combine
enum ShareReplayScope {
case forever
case whileConnected
}
extension Publishers {
final class ShareReplayScopePublisher<Upstream: Publisher>: Publisher {
@Rostmen
Rostmen / Enumerated.swift
Last active July 12, 2020 23:54
Enumerated Publisher based on scan for Combine framework
extension Publisher {
func enumerated() -> AnyPublisher<(Int, Self.Output), Self.Failure> {
scan(Optional<(Int, Self.Output)>.none) { acc, next in
guard let acc = acc else { return (0, next) }
return (acc.0 + 1, next)
}
.map { $0! }
.eraseToAnyPublisher()
}
}
extension Publisher {
public func retryWhen<P>(
_ handler: @escaping (AnyPublisher<Self.Failure, Never>) -> P
) -> Publishers.RetryWhen<Self, P>
where P: Publisher, P.Failure == Self.Failure {
Publishers.RetryWhen(source: self, handler: handler)
}
}
extension Publishers {