Skip to content

Instantly share code, notes, and snippets.

View alberussoftware's full-sized avatar
🎯
Focusing

alberussoftware

🎯
Focusing
View GitHub Profile
@OliverLetterer
OliverLetterer / gist:6049349
Created July 21, 2013 18:06
Log all used CAFilter operations
typedef struct CAColorMatrix {
float m11, m12, m13, m14, m15;
float m21, m22, m23, m24, m25;
float m31, m32, m33, m34, m35;
float m41, m42, m43, m44, m45;
} CAColorMatrix;
@interface CAFilter : NSObject
@property(copy) NSString *name;
@airspeedswift
airspeedswift / MyArray.swift
Last active October 8, 2022 19:52
Array using ManagedBuffer
private class MyArrayBuffer<Element>: ManagedBuffer<Int,Element> {
func clone() -> MyArrayBuffer<Element> {
return self.withUnsafeMutablePointerToElements { elements -> MyArrayBuffer<Element> in
return MyArrayBuffer<Element>.create(self.allocatedElementCount) { newBuf in
newBuf.withUnsafeMutablePointerToElements { newElems->Void in
newElems.initializeFrom(elements, count: self.value)
}
return self.value
@an0
an0 / CALayerDrawingAPI.md
Last active April 18, 2022 21:51
CALayer Drawing API

Call Chain:

CALayer.display() --- if delegate implements displayLayer ---> CALayerDelegate.displayLayer(:)
|                                                               /
|                                                              /
else                                                          /
|                                                            /
|                                                           |
v                                                           v
CALayer.drawInContext(:) ---&gt; CALayerDelegate.drawLayer(:, inContext:) ---&gt; UIView.drawRect(:)
@JoaquimLey
JoaquimLey / github_multiple-accounts.md
Last active April 30, 2023 22:17
How to Work with GitHub and Multiple Accounts

Step 1 - Create a New SSH Key

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.

Step 2 - Attach the New Key

@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active July 12, 2024 03:33
Making efficient use of the libdispatch (GCD)

libdispatch efficiency tips

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

@rnapier
rnapier / observable.swift
Created May 16, 2018 18:51
New Observable idea
import Foundation
class Disposable {
let dispose: () -> Void
init(dispose: @escaping () -> Void) { self.dispose = dispose }
deinit {
dispose()
}
}
@PramodJoshi
PramodJoshi / Utils.swift
Last active July 17, 2024 03:16
Check VPN connection on iOS devices - Swift 3/4
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
}
}
@sebsto
sebsto / gist:6af5bf3acaf25c00dd938c3bbe722cc1
Last active July 4, 2024 15:12
Start VNCServer on Mac1 EC2 Instance
# 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
@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