Skip to content

Instantly share code, notes, and snippets.

View leogdion's full-sized avatar

leogdion leogdion

View GitHub Profile
#!/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
@leogdion
leogdion / PackageUI.swift
Created July 21, 2023 20:30
Swift DSL for Package.swift
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.
// add this to beginning of your Package.swift
import PackageDescription
// MARK: SupportedPlatform
protocol SupportedPlatformable {
#!/bin/bash
tmpfile=$(mktemp)
branch=${1:-main}
logfileslst=$(mktemp)
echo -n "Compiling list of changes..."
git diff --name-only $1 HEAD | while read -r file; do
logfile=$(mktemp)
@leogdion
leogdion / brew_detect.sh
Last active February 10, 2023 19:02
Detect Brew Prefix If Needed
#!/bin/bash
BREW_PATH="$(which brew)"
BREW_PATH_RESULT=$?
if [[ $BREW_PATH_RESULT -ne 0 ]] || [[ -z "$BREW_PATH" ]]; then
echo "It looks like Homebrew is not already installed."
echo "Finding path where it will be..."
arch="$(arch)" # -i is only linux, -m is linux and apple
if [[ "$arch" = i386 ]]; then