Skip to content

Instantly share code, notes, and snippets.

View leogdion's full-sized avatar

leogdion leogdion

View GitHub Profile
@leogdion
leogdion / split_swift.sh
Created July 23, 2024 19:43
Split Swift File by Brackets
#!/bin/bash
# Check if a filename was provided
if [ $# -ne 1 ]; then
echo "Usage: $0 <filename>"
exit 1
fi
filename=$1
@leogdion
leogdion / Database.swift
Last active July 22, 2024 12:57
Sample Code for ModelActor
public protocol Database: Sendable {
func delete<T: PersistentModel>(
where predicate: Predicate<T>?
) async throws
func insert(_ closuer: @Sendable @escaping () -> some PersistentModel) async
func fetch<T, U : Sendable>(
_ selectDescriptor: @escaping @Sendable () -> FetchDescriptor<T>,
with closure: @escaping @Sendable ([T]) throws -> U
@leogdion
leogdion / XcodeApplication.swift
Last active July 16, 2024 18:37
Xcode Script Bridging
import AppKit
import ScriptingBridge
@objc public protocol SBObjectProtocol: NSObjectProtocol {
func get() -> Any!
}
@objc public protocol SBApplicationProtocol: SBObjectProtocol {
func activate()
#!/bin/bash
# Define Swift Package Dependencies
dependencies=(
"Vapor:https://github.com/vapor/vapor.git:4.66.0"
"Fluent:https://github.com/vapor/fluent.git:4.0.0"
"FluentPostgresDriver:https://github.com/vapor/fluent-postgres-driver.git:2.0.0"
"JWT:https://github.com/vapor/jwt.git:5.0.0-beta.1"
"AsyncAlgorithms:https://github.com/apple/swift-async-algorithms:1.0.0"
"OpenAPIVapor:https://github.com/swift-server/swift-openapi-vapor:1.0.0"
#!/bin/bash
# Check if input file is provided
if [ $# -ne 1 ]; then
echo "Usage: $0 <input_file.swift>"
exit 1
fi
input_file="$1"
output_file="${input_file%.swift}_cleaned.swift"
#!/bin/bash
SOURCE_DIR="/path/to/your/source/directory"
find "$SOURCE_DIR" -name "*.swift" -type f -print0 | while IFS= read -r -d '' file; do
# Create a temporary file for editing
tmp_file=$(mktemp)
# Use awk to perform the replacement and save to the temporary file
awk '
//
// FileManager+ReduceDirectory.swift
// Copyright (c) 2023 BrightDigit.
//
import Foundation
private extension Error where Self == NSError {
static func fileNotFound(at url: URL) -> NSError {
NSError(
@leogdion
leogdion / PreferredLayoutView.swift
Created September 14, 2023 16:51
Use GeometryReader to Save a Value and Reuse It
//
// PreferredLayoutView.swift
// Copyright (c) 2023 BrightDigit.
//
#if canImport(SwiftUI)
import Foundation
import SwiftUI
public struct Value<Value> {
@leogdion
leogdion / NSWindowDelegateAdaptor.swift
Created August 23, 2023 14:20
How to tap into the NSWindowDelegate
import AppKit
import SwiftUI
// .onCloseButton(self.$object.delegate, { _ in
// self.object.presentConfirmCloseAlert = true
// return false
// })
class NSWindowDelegateAdaptor: NSObject, NSWindowDelegate {
internal init(onWindowShouldClose: ((NSWindow) -> Bool)?) {
@leogdion
leogdion / NSWindowAdaptorModifier.swift
Created August 17, 2023 21:49
Allow SwiftUI to modifier NSWindow
//
// NSWindowAdaptorModifier.swift
// Copyright (c) 2023 BrightDigit.
//
import AppKit
import Foundation
import SwiftUI
// swiftlint:disable strict_fileprivate