Skip to content

Instantly share code, notes, and snippets.

View KyNorthstar's full-sized avatar
💜
Any Pronouns

Ky KyNorthstar

💜
Any Pronouns
View GitHub Profile
@KyNorthstar
KyNorthstar / main.swift
Created October 16, 2023 23:12
COW Example
//
// main.swift
// COW Example
//
// Created by The Northstar✨ System on 2023-10-16.
//
import Foundation
struct Person {
import Foundation
public extension Array where Element == UInt8 {
// MARK: - Constants
/// This is used by the `toHexString()` method
private static let uppercaseHexCharacters : [Character] =
@KyNorthstar
KyNorthstar / LICENSE.txt
Last active April 14, 2022 19:49
Make UIColor Codable
BLUE HUSKY LICENSE 0 - PUBLIC DOMAIN - OPUS 7
0: LAYMAN'S TERMS
This section is meant to explain the purpose of this License in Layman's
terms, and should thusly never be seen as legally binding. This disclaimer does
not apply to further sections of this License.
1. This is no one's product and is in the public domain
2. You're not responsible for any bad things that might happen because someone
used this product
@KyNorthstar
KyNorthstar / runAnimationGroup shim.swift
Created May 7, 2019 18:22
NSAnimationContext.runAnimationGroup in OS X 10.11 and older
// By Ben Leggiero on 2019-05-07
// License is BH-1-PS: https://github.com/BlueHuskyStudios/Licenses/blob/master/Licenses/BH-1-PS.txt
import AppKit
public extension NSAnimationContext {
@KyNorthstar
KyNorthstar / CompilationException
Last active December 24, 2018 07:29
Kotlin Compiler Crashes
<Exception from standalone Kotlin compiler>
Kotlin: [Internal Error] org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: wrong code generated
org.jetbrains.kotlin.codegen.CompilationException Back-end (JVM) Internal error: Couldn't transform method node:
reposition (Lorg/bh/tools/base/math/geometry/FractionRect;Lorg/bh/tools/base/math/geometry/FractionRect;)Lorg/bh/tools/base/math/geometry/FractionRect;:
@Lorg/jetbrains/annotations/NotNull;() // invisible
@Lorg/jetbrains/annotations/NotNull;() // invisible, parameter 0
@Lorg/jetbrains/annotations/NotNull;() // invisible, parameter 1
L0
ALOAD 1
LDC "rect"
@KyNorthstar
KyNorthstar / Array.joinedWithComma.swift
Last active September 11, 2018 19:29
Slight tweaks to Cortis Clark's joinedWithComma function
extension Array where Iterator.Element == String {
/// Originally by Cortis Clark on StackOverflow, modified by Ben Leggiero for an example
/// - SeeAlso: https://stackoverflow.com/a/52266604/3939277
func joinedWithComma(useOxfordComma: Bool = true, maxItemCount: UInt8? = nil) -> String {
let result: String
if let maxItemCount = maxItemCount, count > maxItemCount {
result = self[0 ..< maxItemCount].joined(separator: ", ") + ", etc."
} else if count >= 2 {
let lastIndex = count - 1
let extraComma = (useOxfordComma && count > 2) ? "," : ""
@KyNorthstar
KyNorthstar / Elevate Permissions.swift
Created August 8, 2018 21:51
Elevates permissions in non-sandboxed Swift apps
import Foundation
private func gainPermissions() {
var authorizationRef: AuthorizationRef? = nil
var authItem = AuthorizationItem(name: kSMRightBlessPrivilegedHelper, valueLength: 0, value: nil, flags: 0)
var authRights = AuthorizationRights(count: 1, items: &authItem)
let flags: AuthorizationFlags = [.interactionAllowed, .preAuthorize, .extendRights]
var environment = AuthorizationEnvironment()
@KyNorthstar
KyNorthstar / 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)
@KyNorthstar
KyNorthstar / 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