Skip to content

Instantly share code, notes, and snippets.

View davidakoontz's full-sized avatar
💭
Working with Bubble.io a NO-CODE platform and building sites.

David Koontz davidakoontz

💭
Working with Bubble.io a NO-CODE platform and building sites.
View GitHub Profile
@davidakoontz
davidakoontz / Fraction.swift
Created August 29, 2023 02:41
Fraction class for Swift - provides support for rational number arithmetic.
//
// Fraction.swift
//
// Created by David Koontz on 8/28/23.
//
import Foundation
// Wonder if a Rational Fraction class would be valuable in Swift.
// - Use Int to model the numerator & denominator
@aChase55
aChase55 / SwiftUI+HexColors.swift
Last active December 5, 2020 21:43
SwiftUI Hex Colors
//Trying out a prefix operator
//I thought vertical elipses made sense, representative of rbg
prefix operator ⋮
prefix func ⋮(hex:UInt32) -> Color {
return Color(hex)
}
extension Color {
init(_ hex: UInt32, opacity:Double = 1.0) {
let red = Double((hex & 0xff0000) >> 16) / 255.0
import Foundation
// Inspired by https://gist.github.com/mbuchetics/c9bc6c22033014aa0c550d3b4324411a
struct JSONCodingKeys: CodingKey {
var stringValue: String
init?(stringValue: String) {
self.stringValue = stringValue
}
@JadenGeller
JadenGeller / Arbitrary Precision and Arbitrary Base Integers Example.swift
Last active September 30, 2023 00:48
Swift Arbitrary Precision, Arbitrary Base Integers
// Use an integer literal to instantiate
let a: BigInt = 23559821412349283
// Or use a string literal if you want to start with a number that is greater than IntMax
let b: BigInt = "123456789876543234567876543234567876543"
// Perform arithmetic operations
let c: BigInt = 123456 + 321 // -> 12777
let d = c / 100 // -> 127
let e = d << d // -> 12700000000......(127 zeros)