Skip to content

Instantly share code, notes, and snippets.

View VaslD's full-sized avatar

Yi Ding VaslD

  • Shandong, China
View GitHub Profile
@VaslD
VaslD / OldStylePropertyList.swift
Created October 10, 2022 17:44
Working with old style (ASCII) plists in Swift...
import Foundation
import TabularData
/// OpenStep 格式 Property List 工具集。
///
/// OpenStep 格式 Property List 也称 ASCII Property List 或旧版 Property List。
public enum OldStylePropertyList {
// MARK: Property List
/// 将 `String` (`NSString`) 转为 OpenStep Property List 输出格式。
@VaslD
VaslD / CountingTimer.swift
Created December 14, 2022 18:31
基于 DispatchSource 的正计时器。
import Foundation
/// 递增(正)计时器,基于 `DispatchSource` 和 `CLOCK_MONOTONIC_RAW`,必须在主线程使用。
@MainActor
public class CountingTimer {
/// 计时原点:创建时刻或上次重置时刻。此数值为系统底层时钟周期,只能通过多次获取后计算时长(单位:纳秒)而不能用于确定当前日期时间。
public private(set) var origin: UInt64
/// 回调间隔。修改间隔时间将以当前时刻重新计算间隔,而非顺延上次回调后已经经过的时间。
public var interval: TimeInterval {
import Foundation
import ArgumentParser
public enum Path {
static let path = ProcessInfo.processInfo.environment["PATH"]!.components(separatedBy: ":")
public static func find(_ command: String) throws -> URL {
let files = FileManager.default
for path in Self.path {
let executable = URL(fileURLWithPath: path).appendingPathComponent(command, isDirectory: false)
@VaslD
VaslD / AA.swift
Created March 9, 2023 18:03
Apple Archive
import AppleArchive
import CryptoKit
import Foundation
import System
public enum AA {
public static let version = Int(APPLE_ARCHIVE_API_VERSION)
static let fields = ArchiveHeader.FieldKeySet("TYP,PAT,LNK,DEV,UID,GID,MOD,FLG,MTM,CTM,SH2,DAT,SIZ")!
@VaslD
VaslD / AES-CBC.swift
Last active March 25, 2023 19:20
East-to-use AES-CBC in Swift, UnsafePointer & Data supported.
import CommonCrypto
import CryptoKit
import Foundation
// MARK: - AES.CBC
public extension AES {
enum CBC {}
}
import UIKit
open class UITableViewPlus: UITableView, UITableViewDelegate {
// MARK: Scroll
override public init(frame: CGRect, style: UITableView.Style) {
super.init(frame: frame, style: style)
super.delegate = self
}
import UIKit
open class UICollectionViewPlus: UICollectionView, UICollectionViewDelegate {
// MARK: Scroll
override public init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
super.init(frame: frame, collectionViewLayout: layout)
super.delegate = self
}
import Foundation
import Network
public typealias TCPClient = TCPConnection
/// TCP 节点(客户端)连接
///
/// 由于 TCP 是全双工通讯,服务端也需要作为节点建立连接。
public final class TCPConnection: Sendable {
let queue: DispatchQueue
import Foundation
import Network
/// TCP 监听(服务端)
public final class TCPServer: Sendable {
let queue: DispatchQueue
let listener: NWListener
public init(port: Int) throws {
guard let unsigned = UInt16(exactly: port), let port = NWEndpoint.Port(rawValue: unsigned) else {
#!/usr/bin/swift
import Foundation
import Security
let manager = FileManager.default
// Print usage if called with no arguments.
var inputs = CommandLine.arguments
if let command = inputs.first {