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
// | |
// HyperlinkTextField.swift | |
// Cleepp | |
// | |
// Created by Pierre Houston on 2024-03-28. | |
// Copyright © 2024 Bananameter Labs. All rights reserved. | |
// | |
// Based on snippits and tips from | |
// https://stackoverflow.com/a/56854375/592739 | |
// https://gist.github.com/mminer/597c1b2c40adcf3c319f7feeade62ed4 |
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
// | |
// BareTextView.swift | |
// Cleepp | |
// | |
// Created by Pierre Houston on 2024-03-27. | |
// Copyright © 2024 Bananameter Labs. All rights reserved. | |
// | |
// Based on snippits from https://stackoverflow.com/a/56854375/592739 | |
// and https://stackoverflow.com/a/14469815/592739 | |
// and https://gist.github.com/mminer/597c1b2c40adcf3c319f7feeade62ed4 |
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
// Insired by https://forums.swift.org/t/iscontained-in-array-extension-of-equatable/20223/28 | |
// Exercise for the reader: define operators ∈ and ∉ | |
// | |
// Created primarily for excluded, which I wanted to use in an | |
// expression like: | |
// `let foos = things.compactMap({ $0.foo?.excluded(from: [a,b,c]) })` | |
// I then went on to generalize to included(in:) and all the | |
// variations below, and found an even better way to write similar | |
// expressions: `let x = y.excluding([u,v,w])` | |
// |
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
# Useful to refer to finder selections from the fish shell command line, like: | |
# $ file (selection) | |
# /Users/me/Documents/Files/Throwback.dvtcolortheme: XML 1.0 document text, ASCII text | |
# /Users/me/Documents/Files/Test.sparsebundle/: directory | |
# | |
function selection | |
osascript -e "tell application \"Finder\" to set s to the selection as alias list" -e "repeat with f in s" -e "set contents of f to POSIX path of f" -e "end repeat" -e "set AppleScript's text item delimiters to linefeed" -e "s as string" | |
end |
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 Result { | |
func failed(else handleSuccess: ((Success) -> Void)? = nil) -> Failure? { | |
switch self { | |
case .success(let value): | |
handleSuccess?(value) | |
return nil | |
case .failure(let error): | |
return error | |
} | |
} |
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 Data { | |
struct HexEncodingOptions: OptionSet { | |
let rawValue: Int | |
static let uppercase = HexEncodingOptions(rawValue: 0) | |
static let lowercase = HexEncodingOptions(rawValue: 1 << 0) | |
} | |
func hexEncodedString(options: HexEncodingOptions = []) -> String { | |
let hexDigits = Array((options.contains(.lowercase) ? "0123456789abcdef" : "0123456789ABCDEF").utf16) | |
var dump: [unichar] = [] | |
var ascii: [unichar] = [] |
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
public extension TimeInterval { | |
public var dispatchInterval: DispatchTimeInterval { | |
let microseconds = Int64(self * TimeInterval(USEC_PER_SECS)) // perhaps use nanoseconds, though would more often be > Int.max | |
return microseconds < Int.max ? DispatchTimeInterval.microseconds(Int(microseconds)) : DispatchTimeInterval.seconds(Int(self)) | |
} | |
} |
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
// TODO: link here to SO post that inspired this | |
// ^ that source worked fine when setting placeholderColor sometime after | |
// placeholder or attributedPlaceholder, but not the other way around. | |
// this is an attempt to fix this, it might work. | |
class ColorPHTextField : UITextField { | |
@IBInspectable var placeholderColor: UIColor? { | |
didSet { | |
applyPlaceholderColor() |
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 Array { | |
func element(at index: Int) -> Element? { | |
return index >= 0 && index < count ? self[index] : nil | |
} | |
} |
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
// | |
// NSManagedObject+Clone.h | |
// TResActivityLog | |
// | |
// Created by Pierre Houston on 2016-05-30. | |
// Copyright © 2016 Resilience software. All rights reserved. | |
// | |
// When no context provided, uses [NSManagedObjectContext MR_defaultContext]. | |
// Note, I was going to add unique prefix "jph_" to these category method names, | |
// but currently I've left those out. |
NewerOlder