Skip to content

Instantly share code, notes, and snippets.

@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
@adam-zethraeus
adam-zethraeus / Bash.swift
Created December 25, 2023 09:57 — forked from andreacipriani/Bash.swift
Execute shell/bash commands from Swift
import UIKit
protocol CommandExecuting {
func run(commandName: String, arguments: [String]) throws -> String
}
enum BashError: Error {
case commandNotFound(name: String)
}
@_spi(Internals) import ComposableArchitecture
struct Bound<R: Reducer, S, V:View> {
init(store: StoreOf<R>, _ s: KeyPath<R.State, S>, _ a: @escaping (S) -> R.Action, @ViewBuilder _ vb: @escaping (Binding<S>) -> V) {
_state = Binding<S>{store.state.value[keyPath: s] } set:{ store.send(a($0)) }
self.vb = vb
}
@Binding var state: S
@ViewBuilder var vb: (Binding<S>) -> V
@adam-zethraeus
adam-zethraeus / JSON.swift
Last active December 2, 2023 20:37
JSON.swift
/*
This source file is part of the Swift.org open source project
Copyright (c) 2021 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception
See https://swift.org/LICENSE.txt for license information
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
*/
// Source: https://github.com/apple/swift-docc/blob/ddf8f0a64f4f477259ae166b84d5f064ab2887c5/bin/output-diff.swift
public struct Locked<T>: LockedValue {
public init(_ value: T) {
let lock = Self.make(for: value)
withLock = { act in
lock.lock()
defer { lock.unlock() }
return act(&lock.unsafe_wrapped)
}
}
@adam-zethraeus
adam-zethraeus / WithState.swift
Created September 22, 2023 10:58
WithState — easy state in Xcode previews
import SwiftUI
extension View {
public func withState<Value, V: View>(_ state: Value, @ViewBuilder content: @escaping (_ state: Binding<Value>) -> V) -> some View {
modifier(WithStateModifier(state, content: content))
}
}
public struct WithState<Value, V: View>: View {
public init(_ value: Value, @ViewBuilder content builder: @escaping (_ state: Binding<Value>) -> V) {
@adam-zethraeus
adam-zethraeus / transaction.swift
Created September 15, 2023 06:33
Transaction Wrapper
public enum Condition {
case new
case safe
}
public enum Transacting<T> {
case known(T)
case changing(known: T, tentative: T)
public mutating func stage(_ value: T) {
switch self {
@adam-zethraeus
adam-zethraeus / Tuple.swift
Created September 15, 2023 06:29
Codable/Hashable Tuple
public enum Tup {
public struct A<A> {
var a: A
}
public struct B<A, B> {
var a: A
var b: B
}
public struct C<A, B, C> {
var a: A
@adam-zethraeus
adam-zethraeus / ConditionallyModify.swift
Last active August 31, 2023 07:45
Conditional tweaks to SwiftUI views without using AnyView
import SwiftUI
extension View {
/// Conditionally make a change to a view in a modifier chain
///
/// - Parameter if: the condition required to make the change
/// - Parameter modify: the change to make
public func conditionally(if condition: Bool, @ViewBuilder _ modify: @escaping (_ content: Self) -> some View) -> some View {
EitherView(condition: condition, input: self, modify: modify)
@adam-zethraeus
adam-zethraeus / warp-pwd.sh
Created August 22, 2023 05:12
Print the current working directory of the most recent Warp terminal window from the command line
#!/usr/bin/env bash
sqlite3 "${HOME}/Library/Application Support/dev.warp.Warp-Stable/warp.sqlite" -readonly -cmd 'select cwd from terminal_panes order by id desc limit 1' '.exit'