Skip to content

Instantly share code, notes, and snippets.

View cristhianleonli's full-sized avatar

Cristhian Leon cristhianleonli

View GitHub Profile
@cristhianleonli
cristhianleonli / moveZeros.swift
Last active August 29, 2019 18:42
Given the array [1,0,9,8,5,4,0,0,5] move all zeros to the left side of the array
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
}
// 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 {
@cristhianleonli
cristhianleonli / application.swift
Last active May 16, 2018 10:59
Starts the application without storyboard, using navBar and tabBar
// in AppDelegate.swift
private func setupApplicationController() {
window = UIWindow()
window?.makeKeyAndVisible()
let vc = UINavigationController(rootViewController: MainController())
window?.rootViewController = vc
}
private func setupApplicationAppearance() {
class ViewController: UIViewController {
@IBOutlet private weak var cardView: UIView!
private var animator: UIDynamicAnimator!
private var snapping: UISnapBehavior!
override func viewDidLoad() {
super.viewDidLoad()
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.
}
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] {
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)
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
/**
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)
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