Skip to content

Instantly share code, notes, and snippets.

Avatar

Petro Korienev soxjke

View GitHub Profile
@soxjke
soxjke / main.swift
Created Apr 26, 2020
InvertBinaryTree(Leetcode)
View main.swift
/**
* 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
@soxjke
soxjke / Task.md
Last active Apr 9, 2020
Test task
View Task.md

Test assignment description

Hi!

You're proposed to create simple grocery shopping cart application with two screens:

  • Shop catalog screen
  • Shopping cart screen

Application communicates with API server located at http://13.48.127.170:3000/ and performs few operations (described below in API section). Prelimiary application designs can be found here:

  • PNG screens:
@soxjke
soxjke / main.swift
Created Mar 20, 2020
DispatchQueue.recursiveSync
View main.swift
extension DispatchQueue {
private struct Const {
static let rSyncKey = DispatchSpecificKey<NSString>()
}
var recursiveSyncEnabled: Bool {
set { self.setSpecific(key: Const.rSyncKey, value: newValue ? (label as NSString) : nil)}
get { self.getSpecific(key: Const.rSyncKey) != nil }
}
func recursiveSync(_ closure: @escaping () -> ()) {
let specific = DispatchQueue.getSpecific(key: Const.rSyncKey)
View Debouncer.swift
public class Debouncer<T: Equatable> {
private(set) var value: T?
private var valueTimestamp: Date = Date()
private var interval: TimeInterval
private var queue: DispatchQueue
private var callbacks: [(T) -> ()] = []
private var debounceWorkItem: DispatchWorkItem = DispatchWorkItem {}
public init(_ interval: TimeInterval,
on queue: DispatchQueue = .main) {
View ViewController+Throttler.swift
private(set) var searchTermThrottle = Throttler<String>(1.5)
override func viewDidLoad() {
super.viewDidLoad()
searchField.addTarget(self, action: #selector(textDidChange(_:)), for: .editingChanged)
searchTermThrottle.on { (searchTerm) in
GithubAPI.search(term: searchTerm) { [weak self] result in
switch (result) {
case .success(let models): self?.onSuccess(models)
case .failure(let error): self?.onError(error)
View Throttler.swift
import Foundation
public class Throttler<T> {
private(set) var value: T? = nil
private var valueTimestamp: Date? = nil
private var interval: TimeInterval
private var queue: DispatchQueue
private var callbacks: [(T) -> ()] = []
public init(_ interval: TimeInterval, on queue: DispatchQueue = .main) {
self.interval = interval
View Throttled.swift
private var valueTimestamp: Date? = nil
private let interval: TimeInterval = 1.5
...
@objc func textDidChange(_ sender: UITextField) {
searchTerm = sender.text ?? ""
if let valueTimestamp = valueTimestamp {
if Date().timeIntervalSince(valueTimestamp) > interval {
self.valueTimestamp = nil
View ViewController.swift
import UIKit
class ViewController: UIViewController {
private(set) var data: [GithubAPI.Response.Model] = []
private(set) var searchTerm: String = ""
@IBOutlet private var tableView: UITableView!
@IBOutlet private var searchField: UITextField!
@IBOutlet private var errorLabel: UILabel!
override func viewDidLoad() {
@soxjke
soxjke / main.swift
Created Nov 28, 2019
Arabic-2-Roman
View main.swift
extension Int {
enum RomanDigits: Int, CaseIterable {
case I = 1
case IV = 4
case V = 5
case IX = 9
case X = 10
case XL = 40
case L = 50
case XC = 90
@soxjke
soxjke / AWSIdentityManager+Fixtures.h
Last active Apr 8, 2019
AWSAuthCore crash workaround
View AWSIdentityManager+Fixtures.h
#import <AWSAuthCore/AWSAuthCore.h>
@interface AWSIdentityManager (Fixtures)
@end
You can’t perform that action at this time.