Skip to content

Instantly share code, notes, and snippets.

View kieranb662's full-sized avatar
🏠
Working from home

Kieran Brown kieranb662

🏠
Working from home
View GitHub Profile
@kieranb662
kieranb662 / NumericalODESolvers.swift
Last active August 28, 2022 19:20
[Numerical ODE Solvers] Numerical Differential Equation Solvers Made In Swift. Euler, Improved Euler, and Runge Kutta 4th Order. #Math
// Kieran Brown
// Kieran's Components "Numerical ODE Solvers"
// https://kieranb662.github.io/blog/2020/04/22/Numerical-ODE-Methods
import Foundations
/// # Eulers Method
/// Uses simple finite difference with no trial steps
/// Each call to this function performs one step. This implies that the `simpleEuler` function is meant to be used as part of a larger solve.
/// - parameters:
@kieranb662
kieranb662 / ReactiveButton.md
Last active June 29, 2020 18:31
[Reactive Button] An example recreation of SwiftUI's built in Button with custom styling features. Plus an example style. #SwiftUI #View

Reactive Button

@kieranb662
kieranb662 / Rainbow.md
Last active May 25, 2023 12:58
[Rainbow ViewModifier] Rainbow animation view modifiers for SwiftUI #SwiftUI #ViewModifier

Rainbow Example

@kieranb662
kieranb662 / SwiftEquationSolvers.md
Last active March 13, 2023 18:01
[Polynomial Solvers] A set of polynomial equation solvers written in Swift. #Math

Swift Equation Solvers

Most equations need to be solved numerically since no close-form expression representing their solutions can be obtained. For polynomial equations of order 1, 2, 3, 4 exact solutions can be obtained. I have created a series of solvers up to a cubic solver, that can be used to obtain most exact solutions. Of course with floating point errors, not everything is going to come out looking clean. To be able to handle complex numbers I made a simplified version of a complex number without all the mathematical operations.

If you call the cubicSolve function with a = 0 then the solver falls back on the quadratic solver, the quadratic solver will fallback on the linear solver and linear solver will return an empty array(Thanks for catching that u\korbonix).

Example Usage

@kieranb662
kieranb662 / SwiftUI-DragGesture-Implementations.md
Last active March 29, 2022 22:37
[Drag Gesture Implementations] #SwiftUI

Drag Gesture Implementations

Simple Example 1

Here I used @State CGSize values to represent both the viewState and the dragState

struct Example1: View {
    @State var viewState: CGSize = .zero
 @State var dragState: CGSize = .zero
@kieranb662
kieranb662 / SwiftUIVarVsFunc.swift
Last active June 29, 2020 17:53
[SwiftUI var vs func] A quick explanation of when I think it Is more useful to return a View from a computed variable or a function and vice versa. #SwiftUI
//
// ContentView.swift
// SwiftUIVarVsFunc
//
// Created by Kieran Brown on 11/1/19.
// Copyright © 2019 Kieran Brown. All rights reserved.
//
@kieranb662
kieranb662 / XcodeKitHelpers.md
Last active April 6, 2023 15:44
[Xcode Editor Notes] Xcodekit Extensions to help make Xcode your own custom text editor.

Xcode Editor Notes

Suggestions

After adding the Extension target to a project

  1. Go to the menu bar -> Product -> Scheme -> Edit Scheme.
  2. Under the info tab change the executable dropdown menu to "Xcode.app".
  3. If you have a testing file add it to the "Arguments Passed On Launch" field under the Arguments tab.