Skip to content

Instantly share code, notes, and snippets.

View KyLeggiero's full-sized avatar
💜
Any Pronouns

Ky KyLeggiero

💜
Any Pronouns
View GitHub Profile
@KyLeggiero
KyLeggiero / FindClosestPointOnBezierPath.swift
Last active September 2, 2018 06:30
Finds the closest point along a Bezier path to a given arbitrary point
// Made to answer http://stackoverflow.com/questions/38512761/how-do-i-find-the-x-y-coordinates-of-the-point-q-on-a-closed-2d-composite-bez
struct BezierPoint {
let q0: CGPoint
let point: CGPoint
let q1: CGPoint
}
struct SimpleBezierCurve {
let left: BezierPoint
@KyLeggiero
KyLeggiero / Swift Enum-Based Datetime Formatter.swift
Last active August 8, 2018 18:55
Create a datetime format with clear and concise Swift enums instead of a cryptic string
// Copyright Ben Leggiero 2017 BH-1-PS
// https://github.com/BlueHuskyStudios/Licenses/blob/master/Licenses/BH-1-PS.txt
import Foundation
@KyLeggiero
KyLeggiero / URL function tests output
Last active September 21, 2018 22:46
Testing ambiguously-named and -documented URL functions
Control:
file:/// => file:///
file:///etc/ => file:///etc/
~/ -- file:/// => ~/ -- file:///
~/Desktop -- file:/// => ~/Desktop -- file:///
~/.bash_profile -- file:/// => ~/.bash_profile -- file:///
./ -- file:/// => ./ -- file:///
../ -- file:/// => ../ -- file:///
file:///etc/../ => file:///etc/../
~/../ -- file:/// => ~/../ -- file:///
/// Example type
public struct Foo {
// Fields...
}
/// Wraps `Foo` so it can be used for that static variable later
private struct FooWrapper {
@KyLeggiero
KyLeggiero / Swift 4 - NSApp Relaunch.swift
Last active April 3, 2021 13:50
Allows you to re-launch a Cocoa app
import Cocoa
public extension NSApplication {
public func relaunch(afterDelay seconds: TimeInterval = 0.5) -> Never {
let task = Process()
task.launchPath = "/bin/sh"
task.arguments = ["-c", "sleep \(seconds); open \"\(Bundle.main.bundlePath)\""]
@KyLeggiero
KyLeggiero / Swift range conformance check.swift
Created November 6, 2017 20:20
A proof-of-concept that attempts to create a syntax like "left < center < right", which ensures that "center" is both greater than "left" and less than "right".
//
// Swift range conformance check.swift
// Requires Swift 4
//
// Created by Ben Leggiero on 2017-11-06.
// Copyright © 2017 Ben Leggiero using BH-1-PS license
//
// This is a proof-of-concept that attempts to create a syntax like "left < center < right", which ensures that
// "center" is both greater than "left" and less than "right".
@KyLeggiero
KyLeggiero / NSWindow+Fade.swift
Last active September 23, 2022 16:00 — forked from indragiek/NSWindow+Fade.h
NSWindow+Fade - Animator proxy based NSWindow fading
//
// NSWindow+Fade.swift
// BH Bezel Notification
//
// Created by Ben Leggiero on 2017-11-09.
// Translated to Swift 4 from the original (ObjC): https://gist.github.com/indragiek/1397050
// Copyright © 2017 Ben Leggiero. All rights reserved.
//
import Foundation
@KyLeggiero
KyLeggiero / What is a Monad?.swift
Created November 27, 2017 22:23
This file is an illustration of the concepts described in the Computerphile video "What is a Monad?", but in Swift rather than the video's Haskell. https://www.youtube.com/watch?v=t1e8gqXLbsU
/// This file is an illustration of the concepts described in the Computerphile video "What is a Monad?", but in Swift rather than the video's Haskell.
/// https://www.youtube.com/watch?v=t1e8gqXLbsU
import Cocoa
// MARK: - Stuff we need in order to make our code look like the code in the video
@KyLeggiero
KyLeggiero / QuickSorter.swift
Last active March 6, 2018 04:27
General-use Quicksort in Swift
/// Uses quicksort with the Lomuto partition scheme.
///
/// By Ben Leggiero, written on 2018-03-05. Copyright BH-0-PD
/// https://github.com/BlueHuskyStudios/Licenses/blob/master/Licenses/BH-0-PD.txt
struct QuickSorter {
/// Performs a quicksort with Lomuto partition using the given array and returns the result
func quicksorting<C: Comparable>(_ unsorted: [C]) -> [C] {
var arrayCopy = unsorted
QuickSorter.quicksort(&arrayCopy)