Skip to content

Instantly share code, notes, and snippets.

View maximkrouk's full-sized avatar
🇺🇦

Maxim Krouk maximkrouk

🇺🇦
View GitHub Profile
@MihaelIsaev
MihaelIsaev / Postgres+Transaction.swift
Last active January 16, 2020 01:34
Postgres transaction extension for Vapor4 and Fluent4
//
// Postgres+Transaction.swift
//
// Created by Mihael Isaev on 14.01.2020.
//
import Vapor
import FluentKit
import PostgresKit
@IanKeen
IanKeen / EntryPoint.swift
Last active March 13, 2025 00:22
Example main.swift
import Foundation
import SwiftUI
let isUITesting = /* your UI test detection here */
@main
struct EntryPoint {
static func main() {
if isUITesting {
UITestApp.main()
@IanKeen
IanKeen / LosslessCodable.swift
Last active May 22, 2024 20:06
PropertyWrapper: LosslessCodable attempts to brute force convert the incoming value to the required type - the underlying type is maintained and used when encoding the value back
public typealias LosslessStringCodable = LosslessStringConvertible & Codable
@propertyWrapper
public struct LosslessCodable<Value: LosslessStringCodable>: Codable {
private let type: LosslessStringCodable.Type
public var wrappedValue: Value
public init(wrappedValue: Value) {
self.wrappedValue = wrappedValue
@PimCoumans
PimCoumans / CustomButton.swift
Last active July 8, 2022 09:16
UIButton subclass with per-state custom values like background and image colors, extendable with whatever value you want to update
class Button: UIButton {
private class Subview: UIView {
// Never allow isUserInteractionEnabled in any button subview
override var isUserInteractionEnabled: Bool {
get { false }
set { super.isUserInteractionEnabled = false }
}
}
import Foundation
public extension Dictionary where Key == String, Value == Any {
fileprivate func _get<T>(path: [String]) -> T? {
var root = self
for idx in 0 ..< path.count - 1 {
guard let _root = root[path[idx]] as? [String: Any] else {
return nil
}
@dduan
dduan / cube.swift
Last active November 26, 2020 08:55
A rotating 3-D cube in terminal. Written in Swift
/// A rotating 3-D cube in terminal
/// Only works on macOS
/// Run `swift cube.swift` in a terminal application to run it.
/// For controlling the cube, see comments for `Key` in code.
import Darwin
enum RawModeError: Error {
case notATerminal
case failedToGetTerminalSetting
// THIS IS A UNIVERSAL SWIFT FUNCTION BIULDER
// FOR ARRAYS OF ANY TYPE
// tested on Swift 5.3.1
@_functionBuilder
public enum ArrayBuilder<Element> {
public typealias Expression = Element
public typealias Component = [Element]