This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Returns [get, set]. Changes to the value can be observed with onChange. | |
function watch(value) { | |
let val = value; | |
function get() { | |
return val; | |
} | |
get.handlers = []; | |
function set(newValue) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// an affine transformation matrix | |
class AffineTransform { | |
// the matrix is represented as a 3x3 matrix | |
// | A C Tx | | |
// | B D Ty | | |
// | 0 0 1 | | |
// A, B, C, D are the coefficients of the linear transformation | |
// Tx, Ty are the translation components | |
constructor(A, C, Tx, B, D, Ty) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Transferable+Extensions.swift | |
// ImageWriter | |
// | |
// Created by David Albert on 8/5/24. | |
// | |
import CoreTransferable | |
import os | |
import SwiftUI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ContentView.swift | |
// UnicodeExplorer | |
// | |
// Created by David Albert on 5/1/24. | |
// | |
import SwiftUI | |
struct ContentView: View { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Cocoa | |
class MyAutoscrollingView: NSView { | |
override func mouseDown(with event: NSEvent) { | |
// mouseDown-specific logic here | |
var mouseEvent = event | |
var done = false | |
NSEvent.startPeriodicEvents(afterDelay: 0.1, withPeriod: 0.05) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UniformTypeIdentifiers | |
// As of macOS 14.3 | |
extension UTType { | |
static var allTypes: [UTType] { | |
[ | |
.item, | |
.content, | |
.compositeContent, | |
.diskImage, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Cursed! Do not use! | |
// Supports most, but not all Text initializers. | |
import SwiftUI | |
extension FormatStyle { | |
func format(any value: Any) -> FormatOutput? { | |
if let v = value as? FormatInput { | |
return format(v) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// OnWindowClose.swift | |
// | |
// Created by David Albert on 12/16/23. | |
// | |
import SwiftUI | |
import AppKit | |
struct WindowReader: NSViewRepresentable { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Range where Bound == Int { | |
init<Summary>(_ range: Range<BTreeNode<Summary>.Index>, in root: BTreeNode<Summary>) where Summary: BTreeSummary { | |
range.lowerBound.validate(for: root) | |
range.upperBound.validate(for: root) | |
self = range.lowerBound.position..<range.upperBound.position | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Chunk { | |
mutating func fixup(withPrevious prev: Chunk) -> Bool { | |
var i = string.startIndex | |
var first: String.Index? | |
var old = startBreakState | |
var new = prev.endBreakState | |
startBreakState = new |
NewerOlder