// | |
// FreeSpaceViewController.swift | |
// Free Space | |
// | |
// Created by Kyle Howells on 04/05/2022. | |
// | |
import UIKit | |
class FreeSpaceViewController: UIViewController { |
// This gist demonstrates how you can implement versioning for a Codable struct to support loading | |
// old serialized data after changing the structure. Notable features of this solution: | |
// | |
// * No need to make new properties optional, or to perform post-processing on the struct after | |
// loading in ordeer to populate missing values | |
// * No need to change the call site - from the outside this struct behaves just the same | |
// as if we had implemented codable directly in the normal way. | |
// * Versioning can be applied individually to parents or leaves in a larger tree of | |
// structs without affecting the other elements | |
// * This approach will work even if the original struct was not designed with versioning in mind |
@propertyWrapper | |
public final class LayoutInvalidating<Value> where Value: Equatable { | |
public static subscript<EnclosingSelf>( | |
_enclosingInstance observed: EnclosingSelf, | |
wrapped wrappedKeyPath: ReferenceWritableKeyPath<EnclosingSelf, Value>, | |
storage storageKeyPath: ReferenceWritableKeyPath<EnclosingSelf, LayoutInvalidating> | |
) -> Value where EnclosingSelf: UIView { | |
get { | |
return observed[keyPath: storageKeyPath].stored |
# YouTube (english) : https://www.youtube.com/watch?v=FtU2_bBfSgM | |
# YouTube (french) : https://www.youtube.com/watch?v=VjnaVBnERDU | |
# | |
# On your laptop, connect to the Mac instance with SSH (similar to Linux instances) | |
# | |
ssh -i <your private key.pem> ec2-user@<your public ip address> | |
# | |
# On the Mac |
func isVPNConnected() -> Bool { | |
let cfDict = CFNetworkCopySystemProxySettings() | |
let nsDict = cfDict!.takeRetainedValue() as NSDictionary | |
let keys = nsDict["__SCOPED__"] as! NSDictionary | |
for key: String in keys.allKeys as! [String] { | |
if (key == "tap" || key == "tun" || key == "ppp" || key == "ipsec" || key == "ipsec0") { | |
return true | |
} | |
} |
import Foundation | |
class Disposable { | |
let dispose: () -> Void | |
init(dispose: @escaping () -> Void) { self.dispose = dispose } | |
deinit { | |
dispose() | |
} | |
} |
The libdispatch is one of the most misused API due to the way it was presented to us when it was introduced and for many years after that, and due to the confusing documentation and API. This page is a compilation of important things to know if you're going to use this library. Many references are available at the end of this document pointing to comments from Apple's very own libdispatch maintainer (Pierre Habouzit).
My take-aways are:
-
You should create very few, long-lived, well-defined queues. These queues should be seen as execution contexts in your program (gui, background work, ...) that benefit from executing in parallel. An important thing to note is that if these queues are all active at once, you will get as many threads running. In most apps, you probably do not need to create more than 3 or 4 queues.
-
Go serial first, and as you find performance bottle necks, measure why, and if concurrency helps, apply with care, always validating under system pressure. Reuse
We need to generate a unique SSH key for our second GitHub account.
ssh-keygen -t rsa -C "your-email-address"
Be careful that you don't over-write your existing key for your personal account. Instead, when prompted, save the file as id_rsa_COMPANY
. In my case, I've saved the file to ~/.ssh/id_rsa_work
.
Call Chain:
CALayer.display() --- if delegate implements displayLayer ---> CALayerDelegate.displayLayer(:)
| /
| /
else /
| /
| |
v v
CALayer.drawInContext(:) ---> CALayerDelegate.drawLayer(:, inContext:) ---> UIView.drawRect(:)