Skip to content

Instantly share code, notes, and snippets.

View azonov's full-sized avatar

Andrey azonov

  • DataArt
  • Russia
View GitHub Profile
@azonov
azonov / gist:0ed8c433aac661344024
Created December 7, 2015 14:01 — forked from MrRooni/gist:4988922
UITableView and NSFetchedResultsController: Updates Done Right
@interface SomeViewController ()
// Declare some collection properties to hold the various updates we might get from the NSFetchedResultsControllerDelegate
@property (nonatomic, strong) NSMutableIndexSet *deletedSectionIndexes;
@property (nonatomic, strong) NSMutableIndexSet *insertedSectionIndexes;
@property (nonatomic, strong) NSMutableArray *deletedRowIndexPaths;
@property (nonatomic, strong) NSMutableArray *insertedRowIndexPaths;
@property (nonatomic, strong) NSMutableArray *updatedRowIndexPaths;
@end
rm -rf "${HOME}/Library/Caches/CocoaPods"
rm -rf "`pwd`/Pods/"
pod update
po Realm.Configuration.defaultConfiguration.fileURL
public struct Formatters {
public enum DateFormatterType {
case ISO8601
case medium
}
static func string(from date: Date, for type: DateFormatterType) -> String {
return formatter(for: type).string(from: date)
}
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
@dynamicMemberLookup
@dynamicCallable
class Dsl<UrlsType> {
private let urls: UrlsType
private var components: [String] = []
init(urls: UrlsType) {
self.urls = urls
}
@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)
}
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 / 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
@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