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
// | |
// KitTemplate.swift | |
// AutoFills | |
// | |
// Created by Cem Olcay on 1/20/24. | |
// | |
import Foundation | |
enum KitTemplate: Int, Codable, CustomStringConvertible, CaseIterable { |
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
class WeightedRandom<T> { | |
var elements: [Element] | |
init(elements: [Element] = []) { | |
self.elements = elements | |
} | |
struct Element { | |
let item: T | |
let weight: Double |
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
func convert<T: FloatingPoint>(value: T, inRange: ClosedRange<T>, toRange: ClosedRange<T>) -> T { | |
let oldRange = inRange.upperBound - inRange.lowerBound | |
let newRange = toRange.upperBound - toRange.lowerBound | |
return (((value - inRange.lowerBound) * newRange) / oldRange) + toRange.lowerBound | |
} | |
/// Variety: [0 - 1]. 0 means no randomisation, 1 means a random value between full range. | |
func variety(value: Double, inRange: ClosedRange<Double>, variety: Double) -> Double { | |
let normalised = inRange == 0...1 ? value : convert(value: value, inRange: inRange, toRange: 0 ... 1) | |
let upper = min(normalised + variety, 1.0) |
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
// | |
// TuringMachine.swift | |
// TuringBud | |
// | |
// Created by Cem Olcay on 3/8/22. | |
// | |
import Foundation | |
class TuringMachine { |
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 Collection where Self.Index == Int { | |
subscript(row: Int, col: Int, colCount: Int) -> Element? { | |
let index = row * colCount + col | |
guard index >= 0, index < count else { return nil } | |
return self[index] | |
} | |
} |
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
// | |
// LiveKnobSwiftUI.swift | |
// ControlBud-SwiftUI | |
// | |
// Created by Cem Olcay on 11/3/21. | |
// | |
import UIKit | |
import SwiftUI | |
import LiveKnob |
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
// | |
// LiveFaderSwiftUI.swift | |
// ControlBud-SwiftUI | |
// | |
// Created by Cem Olcay on 11/4/21. | |
// | |
import UIKit | |
import SwiftUI | |
import LiveFader |
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 UIKit | |
import XCPlayground | |
// 500-1000, 1-100 | |
func seq(length: Int, sampleRate: Int) -> [Int] { | |
var s = [Int]() | |
for i in 0..<length { | |
s.append((i * sampleRate).nonzeroBitCount) | |
} | |
return s |
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
func euclid(steps: Int, pulses: Int) -> [Int] { | |
let pulses = min(pulses, steps) | |
let ones = pulses | |
let zeros = steps - pulses | |
if zeros == 0 { | |
return [Int](repeating: 1, count: steps) | |
} | |
var s: [[Int]] = [Int].init(repeating: 1, count: ones).map({ [$0] }) + [Int](repeating: 0, count: zeros).map({ [$0] }) |
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 UIKit | |
var data: [String: Any] = [ | |
"connection": [ | |
"wifi": [ | |
"sx": 1.1, | |
"tx": 11 | |
], | |
"cell": [ | |
"rx": 10, |
NewerOlder