Skip to content

Instantly share code, notes, and snippets.

View nathanborror's full-sized avatar

Nathan Borror nathanborror

View GitHub Profile
@nathanborror
nathanborror / build.sh
Last active October 27, 2024 17:24
Command line script that builds to iOS simulator or macOS
#!/bin/bash
# Defaults
PLATFORM="iOS Simulator"
DEVICE="iPhone 16 Pro Max"
OS="latest"
# Required
APP=""
BUNDLE_ID=""
@nathanborror
nathanborror / mkui.sh
Last active September 1, 2024 18:12
UI Maker
#! /bin/bash
# Check if an argument is provided
if [ $# -eq 0 ]; then
echo "Error: Please provide a prompt as an argument."
echo "Usage: $0 <prompt>"
exit 1
fi
echo "Prompt: $1"
struct Message: Codable, Identifiable {
var id: String
var role: Role
var content: String?
var toolCalls: [ToolCall]?
var finishReason: FinishReason?
var created: Date
var modified: Date
enum Role: String, Codable {
import Foundation
import OpenAI
func JSONSchemaEncoder<T>(_ instance: T) -> JSONSchema {
var properties = [String: JSONSchema.Property]()
var required = [String]()
let mirror = Mirror(reflecting: instance)
for child in mirror.children {
if let label = child.label, let schemaInfo = child.value as? any SchemaProtocol {
@nathanborror
nathanborror / defaultScrollView.md
Last active September 18, 2023 06:09
Hack for making defaultScrollView work as expected

Problem

The following code results in a view that does what you expect, always shows the content appearing at the bottom of the scroll view. However, if you start with an empty view and populate it with a few buttons, the tap targets for those buttons will be off until you manually scroll the view.

ScrollView {
  LazyVStack {
    Button(action: {}) { Text("Foo") }
    ...
  }
}

Key repeat

defaults write -g InitialKeyRepeat -int 10 # normal minimum is 15 (225 ms)
defaults write -g KeyRepeat -int 1 # normal minimum is 2 (30 ms)

Requires restart.

Hide desktop

@nathanborror
nathanborror / gcloud-run.md
Last active May 31, 2022 15:50
How to setup a new Go project using Google Cloud Run and Cloud SQL.

Go Google Cloud

How to setup a new Go project using Google Cloud Run and Cloud SQL.

Setup a new project

Update gcloud and authenticate

$ gcloud components update
$ gcloud auth login
struct FlippedUpsideDown: ViewModifier {
func body(content: Content) -> some View {
content
.rotationEffect(.radians(.pi))
.scaleEffect(x: -1, y: 1, anchor: .center)
}
}
extension View {
func flipUpsideDown() -> some View {
@nathanborror
nathanborror / ContentView.swift
Last active October 30, 2022 13:26
SwiftUI wrapper around Slack's PanModal (https://github.com/slackhq/PanModal)
import SwiftUI
import PanModal
struct ExampleView: View {
@State var detail: AnyView? = nil
@State var items: [String] = ["Detail 1", "Detail 2", "Detail 3"]
var body: some View {
NavigationView {

iOS Launch Screen

Steps taken to unofficially localize:

  1. Create a new InfoPlist.strings file
  2. Add the following line to that file:
UILaunchStoryboardName = "LaunchScreen";