Skip to content

Instantly share code, notes, and snippets.

View azonov's full-sized avatar

Andrey azonov

  • DataArt
  • Russia
View GitHub Profile
extension StringProtocol {
subscript(_ offset: Int) -> String.Element {
if offset >= 0 {
self[index(startIndex, offsetBy: offset)]
} else {
self[index(endIndex, offsetBy: offset)]
}
}
struct Weakify<Object: AnyObject> {
weak var object: Object?
}
func weak<Object: AnyObject>(_ object: Object) -> Weakify<Object> {
Weakify(object: object)
}
//
// ViewController.swift
// Demo
//
// Created by Andey on 04.01.2023.
//
import Combine
import UIKit
import UIKit
public class ScrollableStackView: UIView {
// MARK: Private Properties
private lazy var scrollView: UIScrollView = {
let scrollView = UIScrollView(frame: .zero)
scrollView.backgroundColor = .clear
scrollView.translatesAutoresizingMaskIntoConstraints = false
@azonov
azonov / m1
Created November 26, 2021 14:41
post_install do |installer|
installer.pods_project.build_configurations.each do |config|
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
end
end
@azonov
azonov / sublime text.sh
Created December 4, 2020 13:18
Setup sublime text editor for terminal
# - Download Sublime https://www.sublimetext.com/
# - Install Sublime (move Sublime.app to Application folder)
# - Allow sublime to open files from terminal
$ ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/sublime
# - Open ./.zshrc via TextEdit
$ open ~/.zshrc
#or
$ touch ~/.zshrc
extension Sequence {
public func sortedAscending<T: Comparable>(by keyPath: KeyPath<Element, T>) -> [Element] {
sorted(by: keyPath, comparator: <)
}
public func sortedDescending<T: Comparable>(by keyPath: KeyPath<Element, T>) -> [Element] {
sorted(by: keyPath, comparator: >)
}
@azonov
azonov / Weakify.swift
Created September 12, 2019 10:03
Weak self capturing in Swift closures
func weak<T: AnyObject>(_ obj: T, _ block: @escaping (T) -> () -> Void) -> () -> Void {
return { [weak obj] in
obj.map(block)?()
}
}
func weak<T: AnyObject, Argument>(_ obj: T, _ block: @escaping (T) -> (Argument) -> Void) -> (Argument) -> Void {
return { [weak obj] a in
obj.map(block)?(a)
}
@dynamicMemberLookup
@dynamicCallable
class Dsl<UrlsType> {
private let urls: UrlsType
private var components: [String] = []
init(urls: UrlsType) {
self.urls = urls
}
on zero_pad(value, string_length)
set string_zeroes to ""
set digits_to_pad to string_length - (length of (value as string))
if digits_to_pad > 0 then
repeat digits_to_pad times
set string_zeroes to string_zeroes & "0" as string
end repeat
end if
set padded_value to string_zeroes & value as string
return padded_value