Skip to content

Instantly share code, notes, and snippets.

View chockenberry's full-sized avatar

Craig Hockenberry chockenberry

View GitHub Profile
@chockenberry
chockenberry / ql.sh
Last active March 4, 2024 23:40
QuickLook for macOS shell
#!/bin/sh
# usage:
# ql /tmp/file.jpg
# cat /tmp/file.jpg | ql
# cal -h | ql
if [ -z "$*" ]; then
cat > /tmp/ql.stdin
mime_type=$(file --brief --mime-type /tmp/ql.stdin)
import Foundation
let okString = "WTF\r\nHELLO"
let wtfString = AttributedString(okString)
if let lineRange = okString.range(of: "\n") {
let lineSubstring = okString[okString.startIndex..<lineRange.lowerBound]
type(of: lineSubstring)
lineSubstring.count
}
@chockenberry
chockenberry / finder_icons.sh
Created March 16, 2023 20:00
Script to toggle Finder icons
#!/bin/sh
defaults read com.apple.finder CreateDesktop > /dev/null 2>&1
enabled=$?
if [ "$1" = "off" ]; then
if [ $enabled -eq 1 ]; then
osascript -e 'tell application "Finder" to quit'
defaults write com.apple.finder CreateDesktop false
open -a Finder
@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 {
@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 / 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 / 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 / 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 / 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 / PrivacyInfo.xcprivacy
Last active April 19, 2024 18:39
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>