Skip to content

Instantly share code, notes, and snippets.

View MaximBazarov's full-sized avatar
💤
ZEN

Maxim Bazarov MaximBazarov

💤
ZEN
View GitHub Profile
@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 {
@MaximBazarov
MaximBazarov / PGNParsing.swift
Last active October 6, 2019 11:44
Draft for PGN parsing task
import Foundation
// MARK: - Portable Game Notation (PGN).
/// Portable Game Notation (PGN).
/// https://en.wikipedia.org/wiki/Portable_Game_Notation
struct PGN {
typealias TurnNumber = UInt
let counterparts: [Counterpart]
@MaximBazarov
MaximBazarov / Networking.swift
Last active September 2, 2019 17:35
Trying to make a Networking layer more clean
/// USAGE ///
// Declarative endpoint description
// MARK: - Endpoints
struct LoginRequest: Request {
let endpoint = "api/v3/auth"
let method = HTTPMethod.get
let headers: [String : String] = [:]