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 |
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
#!/bin/sh | |
# For Ubiquiti EdgeOS | |
# | |
# This script creates a directory /config/scripts/post-commit.d. Any script you put | |
# in that directory will get run every time you commit a new configuration. | |
# | |
# Installation: | |
# - Put this script in /config/scripts/post-config.d. Note that this is a different | |
# directory from the directory this creates. |
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
#!/bin/sh | |
set -e | |
# NOTE: This is no longer necessary! When the IPv6 rollout started, the issue went away. | |
# I'm just keeping the script here for posterity. | |
# Verizon Fios's router on the other end of the ONT (one hop upstream of this router) responds to | |
# any ICMP echo request with an ICMP echo reply, no matter who the intended host is. This breaks | |
# any traceroute that uses ICMP, including mtr, making it look like the destination host is one |
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 | |
struct EmptyContainer<T> { | |
} | |
typealias IntContainer = EmptyContainer<Int> | |
extension IntContainer: Sequence { | |
struct Iterator: IteratorProtocol { | |
func next() -> Int? { |
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
// Lightly modified from the slides for "Rethinking Classical Concurrency Patterns" | |
package sync | |
import "context" | |
type state struct { | |
seq int64 | |
changed chan struct{} // closed upon notify | |
} |
NewerOlder