Skip to content

Instantly share code, notes, and snippets.

Avatar

Keith Irwin zentrope

  • Portland, Oregon
View GitHub Profile
@zentrope
zentrope / Login.swift
Last active Dec 3, 2021
Use enum to indicate state in SwiftUI
View Login.swift
//
// ContentView.swift
// Test5
//
//import SwiftUI
//
//struct ContentView: View {
// var body: some View {
// Text("Hello, world!")
@zentrope
zentrope / locale.swift
Last active Dec 3, 2021
Pseudo example for locale picker
View locale.swift
import SwiftUI
// Can be in another file
struct DataManager {
static let shared = DataManager()
static let defaultRegionCode = "US"
@zentrope
zentrope / ContentView.swift
Created Nov 26, 2021
Picker (like Mac's Contacts App) -- But there's no way to hide the background button style in SwiftUI
View ContentView.swift
import SwiftUI
struct ContentView: View {
var body: some View {
ContactEditor()
.frame(width: 500)
}
}
struct ContactEditor: View {
@zentrope
zentrope / ContentView.swift
Created Oct 21, 2021
Scroll Text in Content View
View ContentView.swift
//
// ContentView.swift
// TestApp2
//
import SwiftUI
struct ContentView: View {
let author = "Moderator"
let title = "Daily Tech Support Thread"
View FetchController.swift
func usersFetchController() -> NSFetchedResultsController<FKUser> {
let fetcher: NSFetchRequest = FKUser.fetchRequest()
fetcher.sortDescriptors = [ NSSortDescriptor(key: "id", ascending: false) ]
return NSFetchedResultsController(fetchRequest: fetcher, managedObjectContext: viewContext, sectionNameKeyPath: nil, cacheName: nil)
}
View UserData.swift
//
// UserData.swift
//
import Cocoa
import Combine
import ForumsKit
class UserData: NSObject, ObservableObject, NSFetchedResultsControllerDelegate {
@zentrope
zentrope / register.rkt
Created Nov 26, 2020
Incomplete token registry service in Racket Lang
View register.rkt
#lang racket
(require db)
(require web-server/servlet)
(require web-server/servlet-env)
(require web-server/managers/none)
(define auth-token "3d99fd86-f62b-4583-a14c-e1151b093569")
(define db-name "register.sqlite")
View post.ss
(def (do-post)
(http-post "http://localhost:9515/session"
headers: '(("Content-Type" . "application/json; charset=utf-8")
("Accept-Encoding" . "identity")
("Accept" . "*/*"))
data: (json-object->string capabilities)))
(def (get-session)
(let (req (do-post))
(for-each (lambda (h) (printf "~s~%" h)) (request-headers req))
View gambit-static-link.sh
View resolve.scm
(define (http:resolve url)
(define resolved-url
(make-parameter (uri-reference url)))
(define (update-resolved-url r)
(resolved-url (request-uri r))
(default-prepare-request r))
(parameterize ((prepare-request update-resolved-url))