Skip to content

Instantly share code, notes, and snippets.

View nathanborror's full-sized avatar

Nathan Borror nathanborror

View GitHub Profile
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 /
Last active September 18, 2023 06:09
Hack for making defaultScrollView work as expected


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 /
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 {
.scaleEffect(x: -1, y: 1, anchor: .center)
extension View {
func flipUpsideDown() -> some View {
nathanborror / ContentView.swift
Last active October 30, 2022 13:26
SwiftUI wrapper around Slack's 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";
import SwiftUI
import Combine
struct AdaptToKeyboard: ViewModifier {
@State var currentHeight: CGFloat = 0
func body(content: Content) -> some View {
nathanborror / playground.swift
Last active January 3, 2023 22:16
Custom UIKit view with child SwiftUI views
import UIKit
import SwiftUI
import PlaygroundSupport
// CustomParentView is a custom UIKit view. Its Coordinator can be used
// to manage delegates if needed (e.g. UIContextMenuInteractionDelegate).
struct CustomParentView<Content: View>: UIViewRepresentable {
let content: UIView