Skip to content

Instantly share code, notes, and snippets.

View cemolcay's full-sized avatar
🎼
🎶

Cem Olcay cemolcay

🎼
🎶
View GitHub Profile
@cemolcay
cemolcay / DictionaryMergeExtension.swift
Created January 23, 2019 12:36
Adds + and += operators to dictionary
/// 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] {
@cemolcay
cemolcay / CodableStore.swift
Last active January 24, 2019 11:25
A protocol where can read/write Codable items on disk.
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)
@cemolcay
cemolcay / gist:7d54d62f0e94ef09f44ec57622a3b12d
Created May 7, 2019 12:23
Delete .DS_Store recursively in a folder
find . -name '.DS_Store' -type f -delete
@cemolcay
cemolcay / DictValidation.swift
Created June 25, 2020 15:57
Validates swift dictionary with rules
import UIKit
var data: [String: Any] = [
"connection": [
"wifi": [
"sx": 1.1,
"tx": 11
],
"cell": [
"rx": 10,
@cemolcay
cemolcay / EuclidianSequencer.swift
Created April 17, 2021 17:21
Creates euclidian sequences
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] })
@cemolcay
cemolcay / ones.xcplayground
Created October 18, 2021 14:19
creates fractal sequence
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
@cemolcay
cemolcay / LiveFader-SwiftUI.swift
Created December 16, 2021 21:24
LiveFader SwiftUI Bridge
//
// LiveFaderSwiftUI.swift
// ControlBud-SwiftUI
//
// Created by Cem Olcay on 11/4/21.
//
import UIKit
import SwiftUI
import LiveFader
@cemolcay
cemolcay / LiveKnob-SwiftUI.swift
Created December 16, 2021 21:24
LiveKnob SwiftUI Bridge
//
// LiveKnobSwiftUI.swift
// ControlBud-SwiftUI
//
// Created by Cem Olcay on 11/3/21.
//
import UIKit
import SwiftUI
import LiveKnob
@cemolcay
cemolcay / 1dArrayWithColRow.swift
Created December 31, 2021 11:50
Get item with row and col from 1d array
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]
}
}
@cemolcay
cemolcay / TuringMachine.swift
Created April 12, 2022 10:32
ShiftBud bit shift algorithm.
//
// TuringMachine.swift
// TuringBud
//
// Created by Cem Olcay on 3/8/22.
//
import Foundation
class TuringMachine {