Skip to content

Instantly share code, notes, and snippets.

View filimo's full-sized avatar

VictorK filimo

View GitHub Profile
@izikeros
izikeros / README.md
Last active March 26, 2024 18:11
[split text fixed tokens] Split text into parts with limited length in tokens #llm #tokens #python

Text Splitter

Code style: black MIT license

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.

Table of Contents

@randomor
randomor / App.swift
Last active February 19, 2021 20:59
SwiftUI 2020 + CloudKit + Core Data ZenJournal prototype: https://thezenjournal.com
import SwiftUI
import CoreData
let appTransactionAuthorName = "app"
@main
struct ZenJournalApp: App {
var body: some Scene {
WindowGroup {
@mecid
mecid / Calendar.swift
Last active October 21, 2024 00:38
SwiftUI Calendar view using LazyVGrid
import SwiftUI
extension Calendar {
func generateDates(
inside interval: DateInterval,
matching components: DateComponents
) -> [Date] {
var dates: [Date] = []
dates.append(interval.start)
protocol KeyPathUpdatable {}
extension KeyPathUpdatable {
func updating<LeafType>(_ keyPath: WritableKeyPath<Self, LeafType>, to value: LeafType) -> Self {
var copy = self
copy[keyPath: keyPath] = value
return copy
}
}
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
}
@AvdLee
AvdLee / FileManagerExtensions.swift
Last active November 19, 2023 23:23
Easily print out useful locations for usage during debugging on the Simulator.
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!
@nalexn
nalexn / CancelBag.swift
Last active November 1, 2023 06:43
Collecting AnyCancellable tokens in declarative SwiftUI fashion
// Copyright © 2019 Alexey Naumov. MIT License
import Combine
typealias CancelBag = Set<AnyCancellable>
extension CancelBag {
mutating func collect(@Builder _ cancellables: () -> [AnyCancellable]) {
formUnion(cancellables())
}
@darrarski
darrarski / CustomPublisher.swift
Last active February 15, 2020 08:08
CustomPublisher - customizable publisher for Combine framework
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))
@darrarski
darrarski / FormattedTextField.swift
Last active September 26, 2024 06:33
SwiftUI FormattedTextField - TextField with custom display/edit formatters
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
}
@darrarski
darrarski / NumberField.swift
Last active October 18, 2023 18:10
SwiftUI NumberField - TextField with custom display/edit number formatters
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()