Skip to content

Instantly share code, notes, and snippets.

View hamsternik's full-sized avatar
:bowtie:
chasing on web x2

Nikita Khomitsevych hamsternik

:bowtie:
chasing on web x2
View GitHub Profile
@hamsternik
hamsternik / homebrew-permissions-issue.md
Created June 14, 2022 14:02 — forked from irazasyed/homebrew-permissions-issue.md
Homebrew: Permissions Denied Issue Fix (OS X / macOS)

Homebrew Permissions Denied Issues Solution

sudo chown -R $(whoami) $(brew --prefix)/*

@hamsternik
hamsternik / TabBarView.swift
Created April 27, 2022 22:32
Improved implementation considering iOS 15 (latest) update
/// NOTE: based on the StackOverflow answer
/// https://stackoverflow.com/a/60107650/3527499
import SwiftUI
struct TabBarView: View {
var items: [TabBarItem]
@State var selectedIndex = 0
init(_ items: [TabBarItem]) {
/// # UIKit basic implementation
open class UIScrollView : UIView, NSCoding, UIFocusItemScrollableContainer {
open var contentOffset: CGPoint // default CGPointZero
open var contentSize: CGSize // default CGSizeZero
open var contentInset: UIEdgeInsets // default UIEdgeInsetsZero. add additional scroll area around content
// all another code ...
}
@hamsternik
hamsternik / hard-skills-mistake-3.swift
Created December 28, 2020 02:02
mistake #3 - breaking the SOLID rules
final class UserDetailsViewController: UIViewController {
// Define the public API ...
override func viewDidLoad() {
super.viewDidLoad()
navigationController?.presentationController?.delegate = self
navigationItem.titleView = navigationTitleLabel
@hamsternik
hamsternik / hard-skills-mistake-1.swift
Created December 28, 2020 01:56
mistake #1 - forget to use `weak` memory modifier for the delegate variable
protocol UserDetailsViewControllerDelegate: class {
func update(with user: User)
}
final class UserDetailsViewController: UIViewController {
var delegate: UserDetailsViewControllerDelegate?
// some code below ...
@IBAction func didTapContinueButton(_ sender: UIButton) {
let user = // get new instance of the User or use the existing one
delegate?.update(with: user)
import UIKit
import RxSwift
import RxCocoa
class AddDiscountTableViewCell: UITableViewCell {
@IBOutlet weak var discountTypeDropDown: SelectionDropDownView!
@IBOutlet weak var amountTextField: PrimaryTextField!
@IBOutlet weak var itemsDropDown: SelectionDropDownView!
#{Re-map default prefix: 'C-b' to 'C-a'}
unbind C-b
set -g prefix C-a
bind C-a send-prefix
### Main Options
###########################################################################
#{Scroll History}
set -g history-limit 50000
// MARK: - Throttler
public class Throttler {
private let queue: DispatchQueue = DispatchQueue.global(qos: .background)
private var job: DispatchWorkItem = DispatchWorkItem(block: {})
private var previousRun: Date = Date.distantPast
private var maxInterval: Double
init(seconds: Double) {
self.maxInterval = seconds
}
import Foundation
/// One-parameter currying from two arguments function
typealias EscapingClosure<A, B> = (A) -> B
func curry<A, B, C>(_ f: @escaping (A, B) -> C) -> EscapingClosure<A, (B) -> C> {
return { (a: A) -> ((_ b: B) -> C) in
return { (b: B) -> C in f(a, b) }
}
}
import Foundation
public protocol EnumerableEnum: RawRepresentable where RawValue == Int {
static var firstIndex: Int { get }
}
public extension EnumerableEnum {