Skip to content

Instantly share code, notes, and snippets.

View mackoj's full-sized avatar
🤓
Neerding & Parenting

Jeffrey Macko mackoj

🤓
Neerding & Parenting
View GitHub Profile
@mackoj
mackoj / FaceRemover.swift
Last active July 24, 2017 23:46
Simple to test to Pixellate face using CoreImage
//
// ViewController.swift
// localreporter
//
// Created by Jeffrey Macko on 15/07/2017.
// Copyright © 2017 Jeffrey Macko. All rights reserved.
//
import UIKit
import UIKit
import Foundation
struct AllocDeallocTester {
struct AllocationResult : CustomDebugStringConvertible {
let className : String
var pointerNumber : Int = 0
var numberOfMissDealloc : Int = 0
var numberOfValidDealloc : Int = 0
@mackoj
mackoj / diagnose-api-breaking-changes.sh
Created April 28, 2022 08:31
This script test if there is breakage in API
#!/usr/bin/env bash
# Get the last tag and test
swift package diagnose-api-breaking-changes $(git describe --abbrev=0 --tags `git rev-list --tags --skip=1 --max-count=1`)
@mackoj
mackoj / DiffStatePropertyWrapper.swift
Last active May 19, 2022 12:11
This tool help to make diff on a state when using a TCA app
import Foundation
import CustomDump
@propertyWrapper
public struct Diff<Value: Equatable>: Equatable {
public static func == (lhs: Diff<Value>, rhs: Diff<Value>) -> Bool {
lhs.value == rhs.value
}
private var value: Value
@mackoj
mackoj / Bundle+decode.swift
Created May 19, 2022 14:08
Decode file from bundle
import Foundation
extension Bundle {
func decode<Output: Decodable>(
_ type: Output.Type,
filename: String,
withExtension ext: String,
decoder: any TopLevelDecoder = JSONDecoder()
) throw -> Output {
guard let fileURL = url(forResource: filename, withExtension: ext) else {
@mackoj
mackoj / BytesFormatter.swift
Last active May 19, 2022 14:09
Get size of a struct
import Foundation
/*
print("💾 AddCustomParamsState size: \(bytesFormater(bytes: MemoryLayout<AddCustomParamsState>.size))")
*/
public func bytesFormater(bytes: Int) -> String {
let bf = ByteCountFormatter()
bf.allowedUnits = .useBytes
bf.countStyle = .memory
@mackoj
mackoj / RandomAccessCollection+Duplicates.swift
Last active May 19, 2022 14:11
Extract duplicates from a RandomAccessCollection, Array, IndentifiedArray, etc...
import Foundation
extension RandomAccessCollection {
/// Extract duplicates from a RandomAccessCollection
///
/// ```swift
/// let data = [User("jerem", amount: 567), User("jeff", amount: 124), User("jeff", amount: 567)]
/// let duplicateName = data.duplicates(\.name)
/// // duplicateName = [User("jeff", amount: 124), User("jeff", amount: 567)]
/// let duplicateAmount = data.duplicates(\.amount)
@mackoj
mackoj / MockCodable.swift
Created June 3, 2022 20:59
This PropertyWrapper allow you to force a value when decoding a property
import Foundation
/// This allow to force a default value when using codable
/// This will force `isEditMode` to always have `false` when decoding it
/// @MockCodable(defaultValue: false) public var isEditMode: Bool = true
@propertyWrapper
public struct MockCodable<Value> {
private var value: Value
private var defaultValue: Value
@mackoj
mackoj / NotCodable.swift
Created June 3, 2022 21:03
This PropertyWrapper allow a property to not be encoded with Codable without needed to create a custom CodingKeys.
import Foundation
/// This allow a property to no be encoded
@propertyWrapper
public struct NotCodable<Boxed> {
private var value: Boxed?
public init(wrappedValue: Boxed?) {
self.value = wrappedValue
}
@mackoj
mackoj / SerializableCGColor.swift
Created June 8, 2022 17:58
Codable implémentation for Color, CGColor that respect ColorSpace
import CoreFoundation
import CoreGraphics
import Foundation
import SwiftUI
public let defaultBadColor = Color.green
public let defaultGoodColor = Color.red
public struct SerializableCGColorError: Error, LocalizedError {
let error: String