Skip to content

Instantly share code, notes, and snippets.

@albertbori
albertbori / SwiftUI_willSet_vs_didSet_Publishers.swift
Last active February 23, 2023 18:54
SwiftUI willSet vs didSet onReceive
// Credit: Michael LaRandeau (@mlarandeau)
import SwiftUI
import Combine
import PlaygroundSupport
class ValueProvider: ObservableObject {
private let didSetSubject = CurrentValueSubject<Int, Never>(0)
import Foundation
extension String
{
var length: Int {
get {
return countElements(self)
}
}
@albertbori
albertbori / MyDB.cs
Last active June 13, 2023 18:11
.NET EntityFramework Encryption Example (C#)
public class MyDB : IdentityDbContext<User>
{
//DBSet properties go here
public MyDB()
{
((IObjectContextAdapter)this).ObjectContext.ObjectMaterialized += new ObjectMaterializedEventHandler(ObjectMaterialized);
}
#region Encryption
@albertbori
albertbori / Installation.md
Last active April 19, 2024 00:16
Automatically disable Wifi when an Ethernet connection (cable) is plugged in on a Mac

Overview

This is a bash script that will automatically turn your wifi off if you connect your computer to an ethernet connection and turn wifi back on when you unplug your ethernet cable/adapter. If you decide to turn wifi on for whatever reason, it will remember that choice. This was improvised from this mac hint to work with Yosemite, and without hard-coding the adapter names. It's supposed to support growl, but I didn't check that part. I did, however, add OSX notification center support. Feel free to fork and fix any issues you encounter.

Most the credit for these changes go to Dave Holland.

Requirements

  • Mac OSX 10+
  • Administrator privileges
@albertbori
albertbori / CPDI-docs.md
Last active April 22, 2024 19:30
Composed Protocol Dependency Injection Documentation

Composed Protocol Dependency Injection (CPDI) Pattern

This dependency injection pattern uses native Swift language features to provide a safe, concise, deterministic, and intentional approach to dependency injection.

Overview

The primary Swift language feature that drives CPDI is called "protocol composition". This feature allows you to create a type alias from any combination of protocols. For example:

protocol Car {