Skip to content

Instantly share code, notes, and snippets.

View adam-zethraeus's full-sized avatar
🏔️

adamz adam-zethraeus

🏔️
View GitHub Profile
@adam-zethraeus
adam-zethraeus / onShake-iOS+macCatalyst.swift
Created October 12, 2025 09:18
SwiftUI onShake operator for iOS (devices) and macCatalyst (windows).
import SwiftUI
extension View {
/// A view modifier which triggers `action` when the iOS device is shaken or the mac catalyst window is shaken.
public func onShake(perform action: @escaping () -> Void) -> some View {
#if targetEnvironment(macCatalyst)
self.modifier(WindowShakeModifier(action: action))
#else
self.modifier(OnShakeModifier(action: action))
#endif
@adam-zethraeus
adam-zethraeus / MarchingCubesParams.h
Created August 8, 2025 22:05 — forked from Matt54/MarchingCubesParams.h
Marching Cubes Metaballs in RealityKit (Metal + LowLevelMesh)
#ifndef MarchingCubesParams_h
#define MarchingCubesParams_h
#include <simd/simd.h>
struct MarchingCubesParams {
simd_uint3 cells;
simd_float3 origin;
simd_float3 cellSize;
float isoLevel;
simd_float3 centerA;
@adam-zethraeus
adam-zethraeus / VisualHash.swift
Last active July 15, 2025 08:54
VisualHash.swift (Value -> Emoji / Pastel / Neon)
import CryptoKit
import SwiftUI
#if canImport(UIKit)
import UIKit
#elseif canImport(AppKit)
import AppKit
#endif
public enum VisualHash {
@adam-zethraeus
adam-zethraeus / DirectoryChangesAsyncSequence.swift
Created June 19, 2025 12:49
DirectoryChangesAsyncSequence
import Foundation
import Dispatch
import CoreServices
import Foundation
import os
/// An AsyncSequence which emits when a file or folder is changed.
public final class DirectoryChanges: AsyncSequence {
public enum Failure: Error {
case InvalidFileURL
@adam-zethraeus
adam-zethraeus / LogUtil.swift
Last active September 2, 2025 20:54
OSLog visualizer
import UniformTypeIdentifiers
import SwiftUI
import OSLog
import Foundation
import Observation
extension Logger {
public static func make(file: StaticString = #file, category: StaticString? = nil) -> Logger {
Logger(
subsystem: Bundle.main.bundleIdentifier ?? "some.recorder",
@adam-zethraeus
adam-zethraeus / CatchingView.swift
Created November 12, 2024 16:42
A SwiftUI view which catches and display subview errors. Similar to an error boundary in React.
public import SwiftUI
public struct CatchingView<Content: View, ErrorMessage: View>: View {
public init(
@ViewBuilder content: @escaping () throws -> Content
) where ErrorMessage == Text {
self.init {
Text("Any error occurred while attempting to load the content.")
} content: {
@adam-zethraeus
adam-zethraeus / github-folder-dl.sh
Created September 5, 2024 11:30
download a folder on github given its URL
#!/usr/bin/env bash
set -e
URL="$*"
START=$(echo "$URL" | sed 's%/tree/main/%\n%g' | head -n1)
END=$(echo "$URL" | sed 's%/tree/main/%\n%g' | tail -n1)
FOLDER=$(echo "$END" | rev | cut -d'/' -f1 | rev)
REPO=$(echo "$START" | cut -d'/' -f5)
CHECKOUT="${REPO}_$(uuidgen)"
@adam-zethraeus
adam-zethraeus / swift-operator-characters.md
Last active October 9, 2025 18:23 — forked from natecook1000/operatorCharacters.swift
Allowed characters for Swift operators

Allowed First Characters for Operators

Char Unicode Unicode Name
= 003D =
- 002D -
+ 002B +
! 0021 !
* 002A *
% 0025 %
import SwiftUI
import Vision
@available(iOS 17, *)
public struct SFEdgeShape: InsettableShape {
public init(systemName: String) {
self.systemName = systemName
}
var systemName: String
@adam-zethraeus
adam-zethraeus / whisper.sh
Created February 26, 2024 12:21
command link whisper
#!/usr/bin/env bash
# https://github.com/ggerganov/whisper.cpp
CLONEDIR="${HOME}"/Developer/
stty -echoctl
function ctrl_c() {
2>/dev/null "${CLONEDIR}"/whisper.cpp/main -m "${CLONEDIR}"/whisper.cpp/models/ggml-large-v3-q5_0.bin -f /tmp/rec.wav --print-colors | pbcopy