Skip to content

Instantly share code, notes, and snippets.

View gorillka's full-sized avatar
💭
👨🏻‍💻

Artem Orynko gorillka

💭
👨🏻‍💻
View GitHub Profile
@gorillka
gorillka / Singleton.h
Created February 7, 2017 17:33 — forked from virasio/Singleton.h
Singleton (Objective-C with ARC)
@interface MySingleton : NSObject
// ...
+ (instancetype) sharedInstance;
+ (instancetype) alloc __attribute__((unavailable("alloc not available, call sharedInstance instead")));
- (instancetype) init __attribute__((unavailable("init not available, call sharedInstance instead")));
+ (instancetype) new __attribute__((unavailable("new not available, call sharedInstance instead")));
@gorillka
gorillka / .swiftlint.yml
Last active May 10, 2018 16:22
SwiftLint
disabled_rules:
- variable_name
- colon
- comma
- control_statement
excluded:
- Carthage
- Pods
@gorillka
gorillka / Demo.m
Last active June 18, 2018 18:40 — forked from codingrhythm/UIColor+HexString.h
Objective-C class to convert hex string to UIColor. Support: #RGB, #ARGB, #RRGGBB, #AARRGGBB.Usage: [UIColor colorWithHexString:@"#f5e6a1"];
[UIColor colorWithHexString:@"#f5e6a1"];
@gorillka
gorillka / EnumTableViewTutorial_03.swift
Created August 1, 2017 16:08 — forked from ianhirschfeld/EnumTableViewTutorial_03.swift
Example of UITableViewDataSource and UITableViewDelegate using a enum for sections.
extension ViewController: UITableViewDataSource, UITableViewDelegate {
// As long as `total` is the last case in our TableSection enum,
// this method will always be dynamically correct no mater how many table sections we add or remove.
func numberOfSections(in tableView: UITableView) -> Int {
return TableSection.total.rawValue
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// Using Swift's optional lookup we first check if there is a valid section of table.
import Foundation
import PlaygroundSupport
/// A thread-safe array.
public class SynchronizedArray<Element> {
fileprivate let queue = DispatchQueue(label: "io.zamzam.ZamzamKit.SynchronizedArray", attributes: .concurrent)
fileprivate var array = [Element]()
}
// MARK: - Properties
@gorillka
gorillka / m3u.swift
Created October 24, 2018 18:11 — forked from Cosmo/m3u.swift
Swift M3U Parser
struct MediaItem {
var duration: Int?
var title: String?
var urlString: String?
static func parseM3U(contentsOfFile: String) -> [MediaItem]? {
var mediaItems = [MediaItem]()
contentsOfFile.enumerateLines({ line, stop in
if line.hasPrefix("#EXTINF:") {
let infoLine = line.stringByReplacingOccurrencesOfString("#EXTINF:", withString: "")
@gorillka
gorillka / UICollectionView.swift
Created November 29, 2018 09:43 — forked from fuxingloh/UICollectionView.swift
iOS Swift: How to count the width of the UILabel. And how to size UICollectionViewCell dynamically with label.
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let text = collections[indexPath.row].name
let width = UILabel.textWidth(font: titleFont, text: text)
return CGSize(width: width + left + right, height: height)
}
@gorillka
gorillka / Mobius 2019
Created September 14, 2019 05:36 — forked from katleta3000/Mobius 2019
Список материалу к докладу "Работаем с сетью эффективно" Ртищев Евгения для Mobius 2019 22-23 мая
1. Очень крутая книжка по сетям (стек OSI) – Charles Severance “Introduction to Network: How the Internet works”
2. URLCache – https://nshipster.com/nsurlcache/
3. Ресёрч HTTP-кеширования с использованием URLCache https://qnoid.com/2016/04/10/A-primer-in-HTTP-caching-and-its-native-support-by-iOS.html
4. Анализ доступности сети:
* SimplePing – https://developer.apple.com/library/archive/samplecode/SimplePing/Introduction/Intro.html
* https://github.com/dustturtle/RealReachability
* https://github.com/ankitthakur/SwiftPing
* https://github.com/lmirosevic/GBPing
* https://github.com/rwbutler/Connectivity
* Баг с 2009 года – https://lists.apple.com/archives/macnetworkprog/2009/May/msg00056.html
@gorillka
gorillka / type_erasure.swift
Created February 5, 2020 09:46 — forked from Agarunov/type_erasure.swift
Swift Type Erasure example
//: Playground - noun: a place where people can play
protocol ObjectMapper {
associatedtype SourceType
associatedtype ResultType
func map(_ object: SourceType) -> ResultType