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
/// Merges right hand side dictionary into left hand side dictionary. Works on nested dictionaries as well. | |
/// | |
/// - Parameters: | |
/// - lhs: Dictionary you want to merge someting. | |
/// - rhs: Merging dictionary. | |
/// - Returns: Returns merged dictionary. | |
internal func +<Key, Value> (lhs: [Key: Value], rhs: [Key: Value]) -> [Key: Value] { | |
var result = lhs | |
rhs.forEach { | |
if let dict = $1 as? [Key: Value] { |
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 DictionaryStore { | |
static var storeFileName: String { get } | |
var store: [[String: Any]] { get set } | |
} | |
extension DictionaryStore { | |
func write() throws { | |
let data = try JSONSerialization.data(withJSONObject: store, options: []) | |
let document = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false) | |
let path = document.appendingPathComponent(Self.storeFileName) |
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
find . -name '.DS_Store' -type f -delete |
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, |
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 | |
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
// | |
// 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
// | |
// 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
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
// | |
// TuringMachine.swift | |
// TuringBud | |
// | |
// Created by Cem Olcay on 3/8/22. | |
// | |
import Foundation | |
class TuringMachine { |