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
@dynamicMemberLookup | |
final class UnsafeSendableBox<T>: @unchecked Sendable { | |
let value: T | |
init(_ value: T) { | |
self.value = value | |
} | |
subscript<Value>(dynamicMember keyPath: KeyPath<T, Value>) -> Value { | |
value[keyPath: keyPath] | |
} |
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
@discardableResult | |
func logMemoryPressure() -> DispatchSourceProtocol { | |
// Wrapper class to make DispatchSourceMemoryPressure sendable | |
final class SendableDispatchMemoryPressureSource: @unchecked Sendable { | |
let source: any DispatchSourceMemoryPressure | |
init(_ source: any DispatchSourceMemoryPressure) { | |
self.source = source | |
} | |
func activate() { |
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
@discardableResult | |
@preconcurrency func logMemoryPressure() -> DispatchSourceProtocol { | |
let source = DispatchSource.makeMemoryPressureSource(eventMask: .all, queue: nil) | |
let queue = DispatchQueue( | |
label: "com.example.memoryPressure") | |
queue.async { | |
source.setEventHandler { | |
guard !source.isCancelled else { return } | |
let event = source.data |
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
// Source: https://www.douggregor.net/posts/swift-for-cxx-practitioners-extensions/ | |
extension UInt32 { | |
subscript(index: Int) -> Bool { | |
get { | |
(self & UInt32(1) << index) != 0 | |
} | |
set { | |
let mask = UInt32(1) << index | |
self = (self & ~mask) | (newValue ? mask : 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
# Source: https://www.reddit.com/r/MicrosoftEdge/comments/16u0nuf/i_know_how_to_launch_edge_into_a_specific_profile/ | |
cat "$HOME/Library/Application Support/Microsoft Edge/Default/Workspaces/WorkspacesCache" | |
open -a '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge' --args --profile-directory="ProfileName" --launch-workspace=<workspace-id> |
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
{ | |
"workbench.colorCustomizations": { | |
"activityBar.activeBackground": "#dc0000", | |
"activityBar.activeBorder": "#03A9F4", | |
"activityBar.background": "#860009", | |
"activityBar.foreground": "#e7e7e7", | |
"activityBar.inactiveForeground": "#e7e7e799", | |
"activityBarBadge.background": "#03A9F4", | |
"activityBarBadge.foreground": "#e7e7e7", | |
"statusBar.background": "#03A9F4", |
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
extension Publisher where Failure == Never { | |
func weakAssign<T: AnyObject>( | |
to keyPath: ReferenceWritableKeyPath<T, Output>, on object: T | |
) -> AnyCancellable { | |
sink { [weak object] value in | |
object?[keyPath: keyPath] = value | |
} | |
} | |
func weakSink<T: AnyObject>( |
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
extension Publisher { | |
@available(macOS 12.0, iOS 15.0, tvOS 15.0, watchOS 8.0, *) | |
func asyncFirst() async throws -> Output? { | |
return try await self | |
.first() | |
.values | |
.first { _ in true } | |
} | |
// https://medium.com/geekculture/from-combine-to-async-await-c08bf1d15b77 |
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
// Source: https://www.hackingwithswift.com/plus/high-performance-apps/using-memoization-to-speed-up-slow-functions | |
// Source: https://medium.com/@mvxlr/swift-memoize-walk-through-c5224a558194 | |
typealias MemFn<Input, Output> = (Input) -> Output | |
// work with any sort of input and output as long as the input is hashable | |
// accept a function that takes Input and returns Output, and return a function with the same signature | |
func memoize<Input: Hashable, Output>( | |
_ work: @escaping MemFn<Input, Output> | |
) -> MemFn<Input, Output> { |
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
defaults write com.apple.dt.Xcode IDEModelAccessHasUserConsentForOnDeviceInteractions -bool FALSE |
NewerOlder