A Python script for splitting text into parts with controlled (limited) length in tokens. This script utilizes the tiktoken
library for encoding and decoding text.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import CoreData | |
let appTransactionAuthorName = "app" | |
@main | |
struct ZenJournalApp: App { | |
var body: some Scene { | |
WindowGroup { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
extension Calendar { | |
func generateDates( | |
inside interval: DateInterval, | |
matching components: DateComponents | |
) -> [Date] { | |
var dates: [Date] = [] | |
dates.append(interval.start) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol KeyPathUpdatable {} | |
extension KeyPathUpdatable { | |
func updating<LeafType>(_ keyPath: WritableKeyPath<Self, LeafType>, to value: LeafType) -> Self { | |
var copy = self | |
copy[keyPath: keyPath] = value | |
return copy | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
public protocol JSONEncodable: Encodable { | |
static var keyEncodingStrategy: JSONEncoder.KeyEncodingStrategy { get } | |
static var dateEncodingStrategy: JSONEncoder.DateEncodingStrategy { get } | |
static var dataEncodingStrategy: JSONEncoder.DataEncodingStrategy { get } | |
static var nonConformingFloatEncodingStrategy: JSONEncoder.NonConformingFloatEncodingStrategy { get } | |
func toJSON() throws -> Data | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension FileManager { | |
/* | |
Prints out the locations of the simulator and the shared group folder. | |
This is useful for debugging file issues. | |
Example usage: FileManager.default.printFileLocations() | |
*/ | |
func printFileLocations() { | |
let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true) | |
let simulatorFolder = paths.last! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright © 2019 Alexey Naumov. MIT License | |
import Combine | |
typealias CancelBag = Set<AnyCancellable> | |
extension CancelBag { | |
mutating func collect(@Builder _ cancellables: () -> [AnyCancellable]) { | |
formUnion(cancellables()) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Combine | |
public final class CustomPublisher<Output, Failure>: Publisher where Failure: Error { | |
public init(subscribe subscribeClosure: @escaping (AnySubscriber<Output, Failure>) -> Subscription) { | |
self.subscribeClosure = subscribeClosure | |
} | |
public func receive<S>(subscriber: S) where S: Combine.Subscriber, S.Input == Output, S.Failure == Failure { | |
let subscription = subscribeClosure(AnySubscriber(subscriber)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
public struct FormattedTextField<Formatter: TextFieldFormatter>: View { | |
public init(_ title: String, | |
value: Binding<Formatter.Value>, | |
formatter: Formatter) { | |
self.title = title | |
self.value = value | |
self.formatter = formatter | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
public struct NumberField: View { | |
public init(_ title: String, | |
value: Binding<NSNumber?>, | |
decorator: @escaping (String) -> String = { $0 }) { | |
self.title = title | |
self.value = value | |
let formatter = NumberFormatter() |
NewerOlder