Skip to content

Instantly share code, notes, and snippets.

View amine2233's full-sized avatar

Amine Bensalah amine2233

View GitHub Profile
@fxm90
fxm90 / swiftui.stencil
Last active May 2, 2022 04:00
A stencil template for generating SwiftUI assets with SwiftGen. Currently only `Image` and `Color` are supported.
//
// Do not edit! File generated using SwiftGen — https://github.com/SwiftGen/SwiftGen
//
// SwiftUI Template by Felix Mau – https://felix.hamburg
//
// Latest version available at https://gist.github.com/fxm90/d1eb5439ad0f45d727bdb98132e933a6
//
import SwiftUI
@gdavis
gdavis / assignNoRetain.swift
Created February 10, 2021 18:03
Combine assign method without the memory leak
extension Publisher where Self.Failure == Never {
public func assignNoRetain<Root>(to keyPath: ReferenceWritableKeyPath<Root, Self.Output>, on object: Root) -> AnyCancellable where Root: AnyObject {
sink { [weak object] (value) in
object?[keyPath: keyPath] = value
}
}
}
extension Result {
func tryMap<T>(_ transform:(Success) throws -> T) -> Result<T, Swift.Error> {
switch self {
case let .success(success):
do {
return .success(try transform(success))
} catch {
return .failure(error)
}
case let .failure(failure):
@steipete
steipete / with.swift
Created January 28, 2021 10:37
with and then for UIKit and SwiftUI
/// Perform an immediate mutation of `subject`. The `transform` function may
/// just mutate the given `subject` or replace it entirely.
///
/// - Parameters:
/// - subject: A value to be transformed.
/// - transform: A closure that mutates or replaces the `subject`.
@inlinable func with<T>(_ subject: T, _ transform: (_ subject: inout T) throws -> Void) rethrows -> T {
var subject = subject
try transform(&subject)
return subject
@ytyubox
ytyubox / MustInjected.swift
Created December 19, 2020 11:43
@MustInjected replace var:!
@propertyWrapper struct MustInjected<Value> {
private var _value: Value! = nil
#if DEBUG
let line: UInt
let file: StaticString
#endif
@available(*, unavailable)
init(wrappedValue: @autoclosure @escaping () -> Value) {
self._value = nil
line = #line
@niw
niw / README.en.md
Last active March 30, 2025 06:00
How to run Windows 10 on ARM or Ubuntu for ARM64 in QEMU on Apple Silicon Mac

How to run Windows 10 on ARM or Ubuntu for ARM64 in QEMU on Apple Silicon Mac

Here is easy steps to try Windows 10 on ARM or Ubuntu for ARM64 on your Apple Silicon Mac. Enjoy!

NOTE: that this is current, 10/1/2021 state.

Running Windows 10 on ARM

  1. Install Xcode from App Store or install Command Line Tools on your Mac
//Orginal code from: https://gist.github.com/mecid/f8859ea4bdbd02cf5d440d58e936faec
//I just made some modification in appearnce, show monthly navigator and weekdays.
import SwiftUI
struct ContentView: View {
@Environment(\.calendar) var calendar
private var year: DateInterval {
calendar.dateInterval(of: .month, for: Date())!
@tonyarnold
tonyarnold / NSObject+BidirectionalAssign.swift
Created September 11, 2020 05:52
Experiment to implement bidirectional assignment of values using Combine/KVO publishers
import Combine
import Foundation
extension NSObjectProtocol where Self: NSObject {
/// Assigns each unique element assigned to the key paths specified to the inverse object.
func bidirectionallyAssign<Value: Equatable, B: NSObject>(
from firstKeyPath: ReferenceWritableKeyPath<Self, Value>,
to secondKeyPath: ReferenceWritableKeyPath<B, Value>,
on otherObject: B
) -> [AnyCancellable] {
@frankschlegel
frankschlegel / Combine+SelfBindings.swift
Last active February 17, 2024 02:14
Convenience extensions for Combine adding memory-save bindings and Cancellable management
import Combine
/// Classes implementing this protocol can be target of convenience Publisher
/// bindings and assignments without causing accidental retain cycles.
/// Those bindings and assignments are also released together with the target.
///
/// For example:
///
/// aPublisher.bind(to: self) { me, object in
@avaidyam
avaidyam / BackdropView.swift
Created July 2, 2020 17:23
DIY NSVisualEffectView using Private API for macOS
// TODO: setting window transforms (or mission control) flattens layers...
// TODO: Mask image vs path (layer)?
/// `NSVisualEffectView`:
///
/// A view that adds translucency and vibrancy effects to the views in your interface.
/// When you want views to be more prominent in your interface, place them in a
/// backdrop view. The backdrop view is partially transparent, allowing some of
/// the underlying content to show through. Typically, you use a backdrop view
/// to blur background content, instead of obscuring it completely. It can also