This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func moveZeros(array l: [Int]) -> [Int] { | |
var array = l | |
var zeroPointer = array.count - 1 | |
var i = array.count - 1 | |
while i >= 0 { | |
if array[i] != 0 { | |
array[zeroPointer] = array[i] | |
zeroPointer -= 1 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// recursively with redundant calculations | |
func fibo(n: Int) -> Int { | |
if n < 2 { return n } | |
return fibo(n: n - 1) + fibo(n: n - 2) | |
} | |
// with memoization | |
var memo = Dictionary<Int, Int>() | |
func fibMemo(_ n: Int) -> Int { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in AppDelegate.swift | |
private func setupApplicationController() { | |
window = UIWindow() | |
window?.makeKeyAndVisible() | |
let vc = UINavigationController(rootViewController: MainController()) | |
window?.rootViewController = vc | |
} | |
private func setupApplicationAppearance() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ViewController: UIViewController { | |
@IBOutlet private weak var cardView: UIView! | |
private var animator: UIDynamicAnimator! | |
private var snapping: UISnapBehavior! | |
override func viewDidLoad() { | |
super.viewDidLoad() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class ViewController: UIViewController { | |
override func loadViewIfNeeded() { | |
super.loadViewIfNeeded() | |
print(#line) | |
// Loads the view controller's view if it has not already been set. | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
class EntitiesFinder { | |
/** | |
Find if in the given `string` exists any term from the `array` | |
- Parameter array: set of strings to find with in the string | |
- Parameter string: target text where to find the entities | |
- Returns: array of ranges with every found entity, Range => (location, length) | |
*/ | |
class func findEntitiesRanges(for array: Set<String>, in string: String) -> [NSRange] { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
typealias Matrix = [[Bool]] | |
typealias Vector = [Bool] | |
func fractal(n: Int) { | |
let width = 63 | |
let height = width / 2 + 1 | |
var matrix = createMatrix(w: width, h: height) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
open class PullUpController: UIViewController { | |
public enum Action { | |
/** | |
The action used when the pull up controller's view is added to its parent view | |
*/ | |
case add | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import Foundation | |
extension UIImage { | |
func tintedImage(imageColor: UIColor) -> UIImage { | |
UIGraphicsBeginImageContextWithOptions(size, false, UIScreen.main.scale) | |
let context = UIGraphicsGetCurrentContext() | |
context?.translateBy(x: 0, y: size.height) | |
context?.scaleBy(x: 1.0, y: -1.0) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
public extension UIColor { | |
/** | |
Creates a color from red, green, blue and alpha | |
- Parameter red: number <0 to 255> indicating red | |
- Parameter green: number <0 to 255> indicating green | |
- Parameter blue: number <0 to 255> indicating blue | |
- Parameter alpha: number <0 to 1> indicating alpha, default 1 | |
- Returns: a color formed with given values |
OlderNewer