Skip to content

Instantly share code, notes, and snippets.

View krzysztofzablocki's full-sized avatar

Krzysztof Zabłocki krzysztofzablocki

View GitHub Profile
krzysztofzablocki /
Created January 18, 2021 11:29
3rd party tooling processing script
cd "$(dirname "$0")/.."
if [[ -n "$CI" ]] || [[ $1 == "--fail-on-errors" ]] ; then
echo "Running in --fail-on-errors mode"
krzysztofzablocki / Minimum.swift
Last active December 11, 2023 17:08
Breaking isolation context bug
import SwiftUI
@Observable @MainActor
final class ViewModel {
var name: String { "Foo" }
class ObservableFoo: ObservableObject {}
struct ContentView: View {
krzysztofzablocki / debugDiffing.swift
Created August 18, 2021 18:28
Higher order reducer for TCA that enables better debugging
import ComposableArchitecture
import Difference
import Foundation
/// A container for storing action filters.
/// The logic behind having this rather than a normal closure is that it allows us to namespace and gather action filters together in a consistent manner.
/// - Note: You should be adding extensions in your modules and exposing common filters you might want to use to focus your debugging work, e.g.
/// ```swift
/// extension ActionFilter where Action == AppAction {
import CloudKit
import Combine
/// Fetches the user's CloudKit Account status.
/// - Parameter container: The container to check the status in.
/// - Returns: A deferred future that resolves to the user's CloudKit Account status.
func getAccountStatus(for container: CKContainer) -> AnyPublisher<CKAccountStatus, Error> {
Deferred {
krzysztofzablocki / Snippet.swift
Last active March 23, 2023 13:15
TCA NOOP Action round trip
/// Add a noop action into your main reducer, don't do anything in that action, just return .none
/// __run the app in RELEASE to get all optimizations enabled __
/// Add this code at the end of your app finish launching delegate call (or onAppear on main view if not using delegate)
// The Interquartile Range (IQR) method is a robust technique used in statistics to measure the spread of data and identify outliers. It is less sensitive to extreme values compared to other methods like standard deviation
func removeOutliers(from array: [Double]) -> [Double] {
func quartiles(of array: [Double]) -> (Double, Double) {
let sortedArray = array.sorted()
let count = sortedArray.count
krzysztofzablocki / gist:338eddf527a351de825bd62cf2a1de28
Last active September 23, 2022 04:57
Use Sourcery to Generate bash script that will rewrite your source code to add final to all classes that have no inheritance
#!/usr/bin/env bash
<% for type in types.classes { -%>
<%_ if{ $ }.contains("final") ||{ $ }.contains("open") || types.based[].isEmpty == false { continue } -%>
<%_ _%>git grep -lz 'class <%= %>' | xargs -0 perl -i'' -pE "s/class <%= %>(?=\s|:)/final class <%= %>/g"
<% } %>
// Run with Sourcery on your codebase and then execute generated code via bash :)
krzysztofzablocki / gist:4396302
Last active November 24, 2021 19:17
Set symbol breakpoint on objc_msgSend then setup this debug command to log all methods called in iOS Simulator. If you want to do device debugging change esp+4 register to r0, esp+8 to r1 Found long ago somewhere on stackoverflow.
expr -- (void)printf("[%s, %s]\n",(char *) object_getClassName(*(long*)($esp+4)), (char *) *(long *)($esp+8) )
krzysztofzablocki / FindFinalClasses.swift
Last active August 22, 2021 12:12
Swift makes classes final if possible
#!/usr/bin/env bash
<% for type in types.classes { -%>
<%_ if type.attributes["final"] != nil || type.attributes["open"] != nil || types.based[]?.isEmpty == false { continue } -%>
<%_ _%>git grep -lz 'class <%= %>' | xargs -0 perl -i'' -pE "s/class <%= %>(?=\s|:)/final class <%= %>/g"
<% } %>
krzysztofzablocki / NetworkResponseConvertible.swift
Last active August 22, 2021 12:09
A good way to deal with mapping network data to your local models in a consistent way, This is how @noremac standardised it in Times codebase
import Combine
import Foundation
/// This protocols allows you to declare your type as having a distinct network
/// representation.
/// Rather than writing and maintaining a custom `Decodable` implementation for
/// your type, declare a brand new struct that exactly matches the expected
/// network response, and then write an initializer for your actual type that
/// accepts a `NetworkResponse`.
krzysztofzablocki / Versionable.swift
Created May 26, 2021 09:16
Extension of that supports a situation when you shipped app without versioning and want to add it now
import Foundation
public protocol VersionType: CaseIterable, Codable, Comparable, RawRepresentable {}
public extension VersionType where RawValue: Comparable {
static func < (a: Self, b: Self) -> Bool {
return a.rawValue < b.rawValue