Skip to content

Instantly share code, notes, and snippets.

View V8tr's full-sized avatar

Vadim Bulavin V8tr

View GitHub Profile
@V8tr
V8tr / ios-questions-interview.md
Created January 29, 2016 15:52 — forked from arturlector/ios-questions-interview.md
Вопросы на собеседование iOS разработчика.

Вопросы на собеседование iOS разработчика (дополненное издание):

General:

  • Что такое полиморфизм?

  • Что такое *инкапсуляция? Что такое *нарушение инкапсуляции?

  • Чем абстрактный класс отличается от интерфейса?

  • Расскажите о паттерне MVC. Чем отличается пассивная модель от активной?

//: Playground - noun: a place where people can play
import Foundation
protocol JSONSerializable {
func toJSON() throws -> Any?
}
enum CouldNotSerializeError: Error {
case noImplementation(source: Any, type: String)
@V8tr
V8tr / git_log_graph.txt
Created April 6, 2018 13:16
Git print log as tree
git log --graph --pretty=oneline --abbrev-commit
@V8tr
V8tr / cURL+Request.swift
Created April 24, 2018 09:06 — forked from shaps80/cURL+Request.swift
Generates a cURL command representation of a URLRequest in Swift.
extension URLRequest {
/**
Returns a cURL command representation of this URL request.
*/
public var curlString: String {
guard let url = url else { return "" }
var baseCommand = "curl \(url.absoluteString)"
if httpMethod == "HEAD" {
@V8tr
V8tr / AtomicInteger.swift
Created May 15, 2018 10:43 — forked from nestserau/AtomicInteger.swift
Atomic way to operate on integers in Swift. Inspired by Java's AtomicInteger
/// This is free and unencumbered software released into the public domain.
///
/// Anyone is free to copy, modify, publish, use, compile, sell, or
/// distribute this software, either in source code form or as a compiled
/// binary, for any purpose, commercial or non-commercial, and by any
/// means.
///
/// In jurisdictions that recognize copyright laws, the author or authors
/// of this software dedicate any and all copyright interest in the
/// software to the public domain. We make this dedication for the benefit
{
"usages": [
{
"additionalUsage": 0,
"freeResourcGroups": [
{
"groupId": "1002",
"groupName": "VOICE",
"resourceUnit": "102",
"resources": [
@V8tr
V8tr / AtomicPropertyWithDispatchAndOperationsQueues.swift
Last active July 14, 2018 07:14
Atomic property in Swift using DispatchQueue and OperationQueue. See blog post for more details: http://www.vadimbulavin.com/atomic-properties/
// MARK: - DispatchQueue
class DispatchQueueAtomicProperty {
private let queue = DispatchQueue(label: "com.vadimbulavin.DispatchQueueAtomicProperty")
private var underlyingFoo = 0
var foo: Int {
get {
return queue.sync { underlyingFoo }
}
@V8tr
V8tr / AtomicProperty.swift
Last active July 16, 2018 08:02
Atomic property in Swift using Locks. See blog post for more details: http://www.vadimbulavin.com/atomic-properties/
import Foundation
// MARK: - Locks
protocol Lock {
func lock()
func unlock()
}
extension NSLock: Lock {}
@V8tr
V8tr / AverageBenchmark.swift
Last active July 23, 2018 08:11
Average benchmark for arbitrary block of code in Swift. Used to compensate deviations of individual benchmark iterations. See blog post for more details: http://www.vadimbulavin.com/benchmarking-locking-apis/
func averageBenchmark(iterations: Int, numberOfAttempts: Int, block: (Int) -> Void) -> TimeInterval {
var accumulatedResult: TimeInterval = 0
for _ in 0..<numberOfAttempts {
let result = benchmark {
for i in 0..<iterations {
block(i)
}
}
accumulatedResult += result
@V8tr
V8tr / RefactoringAppDelegate-Mediator.swift
Last active August 2, 2018 14:47
Refactoring Massive App Delegate using Mediator pattern. See blog post for more details: https://www.vadimbulavin.com/refactoring-massive-app-delegate
// MARK: - AppLifecycleListener
protocol AppLifecycleListener {
func onAppWillEnterForeground()
func onAppDidEnterBackground()
func onAppDidFinishLaunching()
}
// MARK: - Mediator