Skip to content

Instantly share code, notes, and snippets.

View damuellen's full-sized avatar

Daniel Müllenborn damuellen

View GitHub Profile
@damuellen
damuellen / install_swift.sh
Created May 17, 2022 09:50
install swift colab
#!/bin/bash
# Process command-line arguments
old_IFS=$IFS
IFS='.'
read -a strarr <<< "$1"
component_count=${#strarr[*]}
if [[ $component_count -ge 2 ]]; then
# First argument is two components separated by a period like "5.6" or three
@damuellen
damuellen / ExcelFormula.swift
Created April 20, 2022 16:18
Excel Formula Parsing
import Foundation
public struct ExcelFormula {
public var formula: String
public init(_ formula: String) { self.formula = formula }
public var indented: String {
var indentCount = 0
@damuellen
damuellen / Polynomial.swift
Last active April 10, 2022 21:19
Polynomial regression
/// Represents a polynomial function, e.g. `2 + 3x + 4x²`.
public struct Polynomial: Codable, Equatable {
/// Represents the coefficients of the polynomial
public let coefficients: [Double]
public init(coeffs: Double...) {
self.coefficients = coeffs
}
public init(_ array: [Double]) {
@damuellen
damuellen / Gnuplot.swift
Created June 30, 2021 21:13
Gnuplot.swift
import Foundation
/// Create graphs using gnuplot.
public final class Gnuplot {
let datablock: String
let plot: String
public init(data: String) {
self.datablock = data
self.plot = "plot $data"
@damuellen
damuellen / PerformanceDataPlot.swift
Created September 3, 2020 13:30
PerformanceDataPlot
import Foundation
public class PerformanceDataPlot {
let xy1s: [[(x: TimeInterval, y: Double)]]
let xy2s: [[(x: TimeInterval, y: Double)]]
public var y1Titles: [String]
public var y2Titles: [String]
@damuellen
damuellen / deDE.lua
Created October 24, 2019 11:50
deDE LFG addon
LocalizedTagTemplates["deDE"] = {
    lfg = {
        {
            title = "Looking For Group",
            keywords = {
                "lf",
                "lfg","lfd",
                "lfm","lf1m","lf2m","lf3m","lf4m",
                "lftank","lfheal","lfheals","lfhealer","lfdps",
                "tank","heal","heals","healer","dps","dd","heiler",
@damuellen
damuellen / CommandLineOptions.swift
Created July 17, 2019 00:39
CommandLineOptions with DynamicMemberLookup
extension CommandLine {
@dynamicMemberLookup
public struct Options {
private let dict: [String : String]
public init?(_ arguments: [String]) {
let keysWithValues = arguments.dropFirst().compactMap(parse)
if keysWithValues.isEmpty { return nil }
self.dict = Dictionary(keysWithValues) { $1 }
}
import Foundation
let base62Alphabet: [Character] = [
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
]
@damuellen
damuellen / StrideOperator.swift
Created April 21, 2018 21:06
StrideOperator
infix operator .. : StrideFormationPrecedence
precedencegroup StrideFormationPrecedence {
lowerThan: RangeFormationPrecedence
}
func .. <T: Strideable>(left: Range<T>, right: T.Stride) -> StrideTo<T> {
return stride(from: left.lowerBound, to: left.upperBound, by: right)
}
@damuellen
damuellen / LTTBD.swift
Created May 13, 2016 09:51
Largest-Triangle-Three Bucket Downsampling
func downsample(values: [(x:Double, y: Double)], threshold: Int) -> [(x:Double,y: Double)] {
guard values.count > threshold && values.count > 2 else { return values }
let bucketSize = (values.count - 2) / (threshold - 2)
var A = 0, nextA = 0
var out = [(x:Double, y: Double)]()
var maxAreaPoint: (x:Double, y: Double) = (x:0, y: 0)
out.append(values.first!)