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
//: Playground - noun: a place where people can play | |
import Foundation | |
import UIKit | |
func fib(_ n: Int) -> Int { | |
if n == 0 { return 0 } | |
if n == 1 { return 1 } | |
return fib(n - 1) + fib(n - 2) | |
} |
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
//: Playground - noun: a place where people can play | |
// Inspiration: http://cslibrary.stanford.edu/110/BinaryTrees.html | |
import UIKit | |
var values = [10, 5, 6, 8, 9, 22, 3, 2, 4, 7, 14] | |
class Node { | |
var value:Int = 0 | |
var left:Node? = nil |
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
//: Playground - noun: a place where people can play | |
import UIKit | |
import PlaygroundSupport | |
private final class ProgressLayer: CALayer { | |
@NSManaged var progress: CGFloat | |
private let fillColor = UIColor.blue.cgColor | |
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 | |
func gcd(_ a:Int, _ b:Int) -> Int { | |
let r = a % b | |
if r != 0 { | |
return gcd(b, r) | |
} else { | |
return b | |
} | |
} |
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
//: Playground - noun: a place where people can play | |
import Foundation | |
protocol SendDataDelegate: class {} | |
// Only need to use "weak" if the delegate is of type `class`? structs and enums are value types, not reference types so they don't create retain cycles. | |
class SendingVC { | |
weak var delegate: SendDataDelegate? // Remove "weak" and you create a strong reference between both these *VC objects | |
} |
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
lsof -n -i4TCP:3000 | |
# source: | |
# https://blog.jayway.com/2012/09/08/finding-the-pid-listening-on-a-specific-port-on-mac-os-x/ |
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
/* | |
Write a function that takes an expression and evaluates it. The expression is a different notation of an operand working over two operands. For example: | |
"2 + 5", in this prefix expression language could be written "(+ 2 5)" | |
The grammar for this expression syntax works like so: | |
expression := "( operator operand operand )" | |
operator: "*" | "+" | |
operand: expression | integer |
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 PlaygroundSupport | |
import UIKit | |
/// A line by line walk through of the following Combine example: | |
/// https://useyourloaf.com/blog/getting-started-with-combine/ | |
class TermsOfUseViewController: UIViewController { | |
// Some state: | |
private var acceptedSwitch1: Bool = false { |
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 Combine | |
import PlaygroundSupport | |
import UIKit | |
/// A line by line walk through of the following Combine example: | |
/// https://useyourloaf.com/blog/getting-started-with-combine/ | |
class TermsOfUseViewController: UIViewController { | |
// Some state: |
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
https://www.youtube.com/watch?v=A0VaIKK2ijM | |
SEPARATION OF EFFECTS FROM PURITY | |
Part 1: | |
Isolation of side-effects | |
An expression is said to have a side-effect if its execution makes an observable change to the outside world. | |
The goal is to make side-effects understandable, not make them go away. |
OlderNewer