Skip to content

Instantly share code, notes, and snippets.

View theoknock's full-sized avatar

James Alan Bush theoknock

View GitHub Profile
@theoknock
theoknock / response_streamer.swift
Last active July 17, 2025 23:35
Hosts the function that streams the response from a chat model to the client submitting a prompt
//
// ContentView.swift
// ChatGPTCoreModel_playground
//
// Created by Xcode Developer on 7/15/25.
//
import SwiftUI
import FoundationModels
@theoknock
theoknock / Custom SwiftUI Stepper Control.swift
Last active July 16, 2025 17:08
A compact stepper control featuring accelerating increment/decrement buttons and editable text input. Provides immediate response on touch with progressive speed increase during prolonged presses, plus direct keyboard editing with automatic validation. Clean rounded rectangle design with dual data bindings.
import SwiftUI
struct ContentTestView: View {
@State private var psalmValue: Int = 1
@State private var psalmStringValue: String = "1"
@FocusState private var isTextFieldFocused: Bool
var body: some View {
VStack(spacing: 20) {
Text("PSALM")
@theoknock
theoknock / SwiftSyntaxHighlighting.swift
Created June 15, 2025 13:58
Displays Swift code with syntax highlighting
import SwiftUI
import HighlightSwift
struct SwiftSyntaxHighlighting: View {
@State private var code: String = """
struct Example {
var text = "Hello, world!"
func greet() {
print(text)
}
@theoknock
theoknock / Xcode .git
Created November 26, 2024 20:27
ZSH for deleting the existing local repo for an Xcode project, creating a new repo (locally and remotely), and then performing the setup and initial commit
cd ~/Desktop / PlanetaryHoursSwift
sudo ls -l
sudo rm -rf .git
sudo ls -a
git init
git add .
git commit -m "Initial commit"
git remote add origin https: // github.com/theoknock/PlanetaryHoursSwift.git
git push -u origin main
@theoknock
theoknock / ContentView.swift
Last active November 26, 2024 02:39
Sunrise Sunset Calculator
import SwiftUI
import CoreLocation
struct ContentView: View {
@StateObject private var locationManager = LocationManager()
@State private var sunrise: Date = Date().addingTimeInterval(TimeInterval(TimeZone.current.secondsFromGMT(for: Date())))
@State private var sunset: Date = Date().addingTimeInterval(TimeInterval(TimeZone.current.secondsFromGMT(for: Date())))
@State private var nextDaySunrise: Date = Date().addingTimeInterval(TimeInterval(TimeZone.current.secondsFromGMT(for: Date())))
@State private var hours: [PlanetaryHourSegmenter.PlanetaryHourSegment] = []
@State private var longitudes: [LongitudeSegmenter.Segment] = []
@theoknock
theoknock / ContentView.swift
Created July 5, 2024 18:50
A basic FileDocument template created by ChatGPT
import SwiftUI
import UniformTypeIdentifiers
struct TextFile: FileDocument {
static var readableContentTypes: [UTType] { [.plainText] }
var text = ""
init(initialText: String = "") {
text = initialText
@theoknock
theoknock / ContentView.swift
Last active July 5, 2024 18:05
FileDocument
import SwiftUI
struct ContentView: View {
@Binding var document: TextFile
var body: some View {
HStack {
TextEditor(text: $document.text)
}
}
@theoknock
theoknock / Speech-to-Text-to-Speech.swift
Last active July 3, 2024 16:39
Takes dictation and reads it back.
import SwiftUI
import Speech
import AVFoundation
import Combine
import Observation
@Observable class SpeechRecognizer: NSObject, SFSpeechRecognizerDelegate {
var transcription: String = "Transcription"
var isTranscribing: Bool = false
@theoknock
theoknock / Gemini _Pro_1.5-Bible-Verse-Topical-Search.py
Created June 29, 2024 04:52
Gemini _Pro_1.5-Bible-Verse-Topical-Search.py
"""
Install the Google AI Python SDK
$ pip install google-generativeai
See the getting started guide for more information:
https://ai.google.dev/gemini-api/docs/get-started/python
"""
import os
import SwiftUI
import Speech
import AVFoundation
import Combine
import Observation
@Observable
class SpeechRecognizer {
var transcription: String = ""
var isTranscribing: Bool = false