Skip to content

Instantly share code, notes, and snippets.

@ivanopcode
ivanopcode / OrderedStrictidSet
Created January 23, 2024 18:58
Swift OrderedStrictidSet data structure draft
// MIT License
//
// Copyright (c) 2024 Ivan Oparin
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@ivanopcode
ivanopcode / m3u8_primitive_swift_encoder_decoder.swift
Created August 18, 2023 15:55
primitive m3u8 encoder-decoder
// License: MIT
// 2023 Ivan Oparin
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
@ivanopcode
ivanopcode / Transcoder.swift
Created August 18, 2023 13:00
ffmpeg_swift_wrapper_transcode_hls_example
//
// Transcoder.swift
//
// Copyright (c) 2020 Changbeom Ahn, 2023 Ivan Oparin
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
@ivanopcode
ivanopcode / xcgen_perdux_module
Created July 10, 2023 23:26
xcgen_perdux_module script that generates named perdux module stub
#!/bin/zsh
# ---------------------------------------------------------------------------------
# Script Name: xcgen_perdux_module
# Version: 1.0.0+2023-06-10
# Author: Ivan Oparin <amici.waxwing.01@icloud.com>
#
# License:
# MIT License
#
@ivanopcode
ivanopcode / git-branch-cleanup
Created July 10, 2023 23:12
git-branch-cleanup shell script that deletes local branches
#!/bin/zsh
# ---------------------------------------------------------------------------------
# Script Name: git-branch-cleanup
# Version: 1.0.0+2023-06-11
# Author: Ivan Oparin <amici.waxwing.01@icloud.com>
#
# License:
# MIT License
#
@ivanopcode
ivanopcode / measure
Created June 20, 2023 19:50
Convince wrapper for measuring function execution time, relies on Darwin's Foundation
// MIT
// Alexey Grigorev, Ivan Oparin
import Foundation
@discardableResult
public func measure(_ action: () -> ()) -> Double {
let start = Date()
action()
let end = Date()
@ivanopcode
ivanopcode / configureIoC
Created June 20, 2023 19:48
IoC initialization function for SwiftUI-lifecycle based apps
// MIT
// Alexey Grigorev, Ivan Oparin
@MainActor
static private func configureIoC() {
ObjectFactory.initialize(with: DIContainerBuilder.container)
}
@ivanopcode
ivanopcode / DIContainerBuilder.swift
Created June 20, 2023 19:42
Swinject-based DI container builder template
// MIT
// by Alexey Grigorev, Ivan Oparin
import Swinject
class DIContainerBuilder {
public static func build() -> Container {
let container = Container()
return container
@ivanopcode
ivanopcode / NetworkStatusService
Created June 20, 2023 19:35
Thread-Safe Network Status Monitor using Swift Actors and Combine
// MIT
// by Alexey Grigorev, Ivan Oparin
// A thread-safe service for subscribing to network status updates on Apple's platforms. It
// utilizes Apple's Network framework to monitor network conditions. The service
// uses the actor model for thread safety, protecting from data
// races. Updates are emitted via Combine publishers, for easy integration with
// reactive or async code. Updates include network connection status, if the
// connection is expensive, and if the status has changed."