Skip to content

Instantly share code, notes, and snippets.

View MaximBazarov's full-sized avatar
💤
ZEN

Maxim Bazarov MaximBazarov

💤
ZEN
View GitHub Profile
import AppKit
import SwiftUI
import Combine
import OSLog
/// Full screen window that hosts the SwiftUI view.
/// - Can not become active nor main so user stays in the app they were in.
/// - Ignores all mouse events allowing user to interact with content behind it.
/// - Enables mouse events, only when mouse is over its content view.
@MainActor
@MaximBazarov
MaximBazarov / UDStorage.swift
Created October 10, 2024 07:43
Storage for an array of Coddle items on disk
import UIKit
enum StoredItem<V: Codable> {
case item(key: String, value: V)
case delete(key: String)
init(key: String, value: V?) {
self = .delete(key: key)
}
@MaximBazarov
MaximBazarov / AwaitAuth.swift
Last active April 9, 2024 17:40
Swift Concurrency: Await of one task from multiple tasks
import Foundation
actor Auth {
private var tokenRefresh: Task<String, Error>?
private var _token: String?
private var counter: Int = 0
func token() async throws -> String {
if var tokenRefresh {
@MaximBazarov
MaximBazarov / OSLogStore+AssertContains.swift
Created October 30, 2023 07:59
OSLogStorage contains a log message
import OSLog
import XCTest
extension OSLogStore {
static func entities(
subsystem: String? = nil,
category: String? = nil
) throws -> [OSLogEntryLog] {
let logStore = try OSLogStore(scope: .currentProcessIdentifier)
let enumerator = try logStore.__entriesEnumerator(position: nil, predicate: nil)
@MaximBazarov
MaximBazarov / xed_xcode_invocation_tool.md
Created July 27, 2023 15:23 — forked from dive/xed_xcode_invocation_tool.md
Xcode invocation tool - xed

Xcode invocation tool - xed

xed is a command-line tool that launches the Xcode application and opens the given documents (xcodeproj, xcworkspace, etc.), or opens a new document, optionally with the contents of standard input.

If you work from the command line, this tool is a better option than open (which can open Xcode projects as well). Why?

  • xed knows about the current selected Xcode version (open behaves unpredictably if you have multiple Xcode installed)
  • You can use it open all files from a specific commit (with a little help explained below). It is useful on code-reviews or when you want to explore significant changes in the repository
  • You can use it as a "quick open" helper. Helps with monorepo phenomena, when you have hundreds of projects in the repository (I will show you an example below)
Xcode Test Coverage
@MaximBazarov
MaximBazarov / bouncywin.swift
Created December 7, 2019 15:22 — forked from ihnorton/bouncywin.swift
Bouncy window manager "solution"
import Cocoa
import Foundation
import AppKit
import CoreFoundation
import ApplicationServices
/// https://jvns.ca/blog/2019/11/25/challenge--make-a-bouncy-window-manager/
/*
This code runs the following sequence:
// Safely Modifying The View State (SwiftUI)
// https://swiftui-lab.com
// https://swiftui-lab.com/state-changes
import SwiftUI
struct CustomView: View {
var body: some View {
NavigationView {