Skip to content

Instantly share code, notes, and snippets.

View chockenberry's full-sized avatar

Craig Hockenberry chockenberry

View GitHub Profile
@chockenberry
chockenberry / ContentView.swift
Created April 17, 2024 17:43
NavigationPath Experiments
//
// ContentView.swift
// NavigationTest
//
// Created by Craig Hockenberry on 4/16/24.
//
import SwiftUI
struct OddView: View {
@chockenberry
chockenberry / ContentView.swift
Created April 12, 2024 17:58
Optional Bindable
//
// ContentView.swift
// BindableOptional
//
// Created by Craig Hockenberry on 4/12/24.
//
import SwiftUI
@Observable
@chockenberry
chockenberry / ContentView.swift
Created April 10, 2024 18:29
SwiftUI Protocol Bindings
//
// ContentView.swift
// ProtocolBinding
//
// Created by Craig Hockenberry on 4/10/24.
//
import SwiftUI
protocol ShapeProtocol {
@chockenberry
chockenberry / PrivacyInfo.xcprivacy
Last active March 30, 2024 16:58
PrivacyInfo.xcprivacy sample
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPrivacyAccessedAPITypes</key>
<array>
<dict>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>CA92.1</string>
@chockenberry
chockenberry / df.sh
Created March 4, 2024 18:51
df Replacement
#!/bin/sh
if [ ! -z "$*" ]; then
echo "this is ~/bin/df, use /bin/df"
exit 1
fi
protect=`mount | grep -v "read-only" | grep "protect" | cut -f 3 -w`
nosuid=`mount | grep -v "read-only" | grep "nosuid" | cut -f 3 -w`
@chockenberry
chockenberry / url.swift
Created November 27, 2023 23:35
Get URL for a published NetService instance
extension NetService {
var url: URL? {
get {
if self.port != -1 {
var urlComponents = URLComponents()
urlComponents.scheme = "http"
if let hostName = self.hostName {
urlComponents.host = hostName.lowercased()
}
@chockenberry
chockenberry / FB.txt
Created August 15, 2023 23:23
THE BEST ENHANCEMENT: Extend #if targetEnvironment() for Previews, Widgets, and More.
We have this in SwiftUI:
#if targetEnvironment(simulator)
Yet it’s rarely useful, because SwiftUI code that’s being used in a preview is being run in a simulator.
The distinction that developers need is whether the code is being used in a preview or in the Simulator app.
The root of the problem is that View data is kept in two separate locations:
@chockenberry
chockenberry / ContentView.swift
Created August 11, 2023 21:43
A struggle to resize an Image in an HStack
//
// ContentView.swift
// PanelTest
//
// Created by Craig Hockenberry on 8/11/23.
//
import SwiftUI
struct ContentView: View {
@chockenberry
chockenberry / simkill.sh
Last active December 9, 2023 14:04
A simple shell script to reset CoreSimulator
#!/bin/sh
pids=`ps axo pid,command | grep CoreSimulator | grep -v "grep CoreSimulator" | cut -c 1-5`
if [ "$1" = "go" ]; then
kill -9 $pids
elif [ "$1" = "echo" ]; then
echo $pids
else
pid_param=`echo $pids | tr -s ' ' ','`
@chockenberry
chockenberry / wtf.swift
Created May 23, 2023 22:12
URLSession with SSH and HTTP
import Foundation
Task<Void,Never> {
do {
if let url = URL(string: "http://localhost:22") {
let (_, response) = try await URLSession.shared.data(from: url)
if let response = response as? HTTPURLResponse {
print(response.statusCode)
}
else {