Skip to content

Instantly share code, notes, and snippets.

View peterkos's full-sized avatar
:octocat:

Peter Kos peterkos

:octocat:
View GitHub Profile
struct LoadingViewModifier: ViewModifier {
@Binding var isLoading: Bool
func body(content: Content) -> some View {
content
.overlay(
// Wrapping this in a `Group` fixes the error
if isLoading {
ProgressView()
.transition(.opacity) // <-- error: Branches have mismatching types
@peterkos
peterkos / FilledBackgroundModifier.swift
Created May 25, 2024 23:33
Apply a background to all cells in a GridRow, with rounded corners.
/// Apply a background to all cells in a GridRow, with rounded corners.
///
/// Example:
/// ```swift
/// Grid(/* ... */) {
/// ForEach(...) { element in
/// GridRow(alignment: .center) {
/// Text(element.title)
/// .modifier(FilledBackgroundModifier(
@peterkos
peterkos / VariadicViewHelpers.swift
Last active May 25, 2024 23:09
Helpers for setting traits when using _VariadicView
// Generic version of https://gist.github.com/chriseidhof/5ff6ef8786f5635c18b20304ab9d9b01
extension View {
/// Convenience for setting a `_ViewTraitKey`
func withTrait<Trait, Value>(_: Trait.Type, value: Value) -> some View
where Trait: _ViewTraitKey, Value == Trait.Value
{
_trait(Trait.self, value)
}
}
@peterkos
peterkos / CLLocation.swift
Created May 24, 2024 19:45
quantom computin'
import CoreLocation
import Foundation
class LocationManager: NSObject, ObservableObject, CLLocationManagerDelegate {
static let shared: LocationManager = .init()
@Published var userCoordinates: UserCoordinates?
private let clLocationManager = CLLocationManager()
@Published var locationPermissions: LocationPermissionStatus = .unknown
@peterkos
peterkos / macos_files.swift
Created May 12, 2024 21:26
macos_files.swift
struct RSFile {
var name: String
}
func importfiles(fileURLs: [URL]) async -> [RSFile] {
var files = [RSFile]()
for fileURL in fileURLs {
let fileData: URLResourceValues
@peterkos
peterkos / trasnferable-swiftdata.swift
Created May 7, 2024 19:56
Until I Write A Blog Post, This Gist Will Do, by Fall Out Boy
//
// TransferablePersistentID.swift
// Cabinette
//
// Created by Peter Kos on 3/1/24.
//
import CoreTransferable
import SwiftData
import UniformTypeIdentifiers
Plugin Description
editor-width-slider Adjust how wide the editor view is
table-editor-obsidian Edit tables!
obsidian-editor-shortcuts Sublime-esque shortcuts, sometimes broke tho.
obsidian-sortable Sort things? I don’t quite remember
obsidian-linter MUST-HAVE. Lint plain text is so so nice. Saves a ton of time formatting extra line breaks.
obsidian-style-settings Extra themeing
obsidian-git Backup the vault using Git
@peterkos
peterkos / DebugPosition.swift
Last active April 16, 2024 01:02
DebugPosition
import SwiftUI
struct DebugPosition: ViewModifier {
var position: CGPoint
func body(content: Content) -> some View {
content
.overlay(alignment: .bottom) {
ZStack {
Text("(\(Int(position.x)), \(Int(position.y)))")
@peterkos
peterkos / zola.yml
Created March 2, 2024 17:03
zola deploy but without docker, runs ~5sec
name: Zola
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
# Allows a manual run from the Actions tab
workflow_dispatch:
struct OptionalComparator<T: Comparable>: SortComparator {
typealias Compared = T?
var order: SortOrder = .forward
func compare(_ lhs: T?, _ rhs: T?) -> ComparisonResult {
return switch (lhs, rhs) {
case (_, nil):
order == .forward ? .orderedDescending : .orderedAscending
default:
order == .forward ? .orderedAscending : .orderedDescending