Skip to content

Instantly share code, notes, and snippets.

View sssbohdan's full-sized avatar
❤️

Bohdan Savych sssbohdan

❤️
View GitHub Profile
@sssbohdan
sssbohdan / IteratorProtocolExample.swift
Created January 17, 2021 11:12
IteratorProtocolExample
let arr = [1, 2, 3]
var iterator = arr.makeIterator()
while let num = iterator.next() {
//
}
@sssbohdan
sssbohdan / IteratorProtocol.swift
Created January 17, 2021 10:49
IteratorProtocol
public protocol IteratorProtocol {
associatedtype Element
mutating func next() -> Self.Element?
}
@sssbohdan
sssbohdan / AudioRecorder.swift
Created January 3, 2019 18:24
Audio recorder with simple interface, Swift 4
import Foundation
import AVFoundation
protocol AudioRecorder {
func checkPermission(completion: ((Bool) -> Void)?)
/// if url is nil audio will be stored to default url
func record(to url: URL?)
func stopRecording()
@sssbohdan
sssbohdan / QuickSort.swift
Created October 26, 2018 10:05
QuickSort
func quickSort<T: Comparable>(arr: [T]) -> [T] {
if arr.count <= 1 {
return arr
} else if arr.count == 2 {
return arr[0] > arr[1] ? [arr[1], arr[0]] : arr
} else if arr.count == 3 {
let firstIndex = arr[0] <= arr[1] && arr[0] <= arr[2] ? 0 : arr[1] <= arr[2] ? 1 : 2
let secondIndex = (arr[0] <= arr[1] && arr[0] >= arr[2]) || (arr[0] >= arr[1] && arr[0] <= arr[2])
? 0
@sssbohdan
sssbohdan / debounce-throttle.swift
Last active January 17, 2019 09:19 — forked from simme/debounce-throttle.swift
Swift 3 debounce & throttle
//
// debounce-throttle.swift
//
// Created by Bohdan Savych on 19/12/18.
// License: MIT
//
import Foundation
extension TimeInterval {
for family in UIFont.familyNames {
print("\(family)")
for name in UIFont.fontNames(forFamilyName: family) {
print(" \(name)")
}
}
@sssbohdan
sssbohdan / 1-Functor-and-Monad.md
Created October 8, 2017 19:01 — forked from mbrandonw/1-Functor-and-Monad.md
Swift Functor and Monad

Copy and paste the swift code below into a playground to experiment.

This is a very close emulation of Functor and Monad typeclasses in swift. However, it is very fragile (i.e. easy to crash the compiler).

For example, instance methods of fmap will run fine, but attempting to use a globally defined fmap that acts on Functor types will cause a crash. Similarly for bind. Unfortunately this means we cannot define the nice infix operator versions of these functions.

@sssbohdan
sssbohdan / .swift
Created October 5, 2017 09:38
SideShadowLayer
//
// SideShadowLayer.swift
// Rolique
//
// Created by Bohdan Savych on 10/5/17.
// Copyright © 2017 Rolique. All rights reserved.
//
import UIKit
@sssbohdan
sssbohdan / .swift
Created October 4, 2017 13:53
ConstraintsSettings
//
// ConstraintsSettings.swift
// Rolique
//
// Created by Bohdan Savych on 9/29/17.
// Copyright © 2017 Rolique. All rights reserved.
//
import UIKit
import UIKit
import RxSwift
import RxCocoa
let requiredUserNameLength = 5
let requiredPasswordLength = 5
let limitUserNameLength = 20
class ValidationViewController: UIViewController {