This file contains hidden or 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 struct AttributedString { | |
fileprivate var _handle: NSMutableAttributedString | |
fileprivate init(handle: NSMutableAttributedString) { | |
self._handle = handle | |
} | |
fileprivate init(_ str: NSAttributedString) { | |
self.init(handle: str.mutableCopy() as! NSMutableAttributedString) |
This file contains hidden or 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 | |
import CoreGraphics | |
import Vision | |
struct TargetWindow { | |
let id: CGWindowID | |
let bounds: CGRect | |
init?(appName: String, windowTitle: String) { | |
guard let windows = CGWindowListCopyWindowInfo(.optionAll, kCGNullWindowID) as? [[String: Any]] else { return nil } |
This file contains hidden or 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 UIKit | |
public extension CGSize { | |
func snapped(scale: CGFloat) -> CGSize { | |
var size = self | |
size.width = ceil(size.width * scale) / scale | |
size.height = ceil(size.height * scale) / scale | |
return size | |
} |
This file contains hidden or 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
// Eat/seek/peek | |
extension Collection where SubSequence == Self, Element: Equatable { | |
mutating func eat() -> Element { | |
defer { self = self.dropFirst() } | |
return peek() | |
} | |
mutating func eat(_ n: Int) -> SubSequence { | |
let (pre, rest) = self.seek(n) | |
defer { self = rest } |
This file contains hidden or 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 UIView { | |
/// Convenience API to query iOS 11's `UIView.safeAreaInsets`'s insets (also known as "#NotEmbraceTheNotch") | |
/// in a backwards compatible API. | |
/// It also differs slightly from `UIView.safeAreaInsets` in that it only takes the "Notch" into account | |
/// and not the status bar. This allows you to inset content so that the notch doesn't clip it, but you can still | |
/// lay it out below the status bar. | |
/// Note: This won't be as versitile as the UIKit version because it won't take into account things like navigation bars, | |
/// but it should be correct for views in "full-screen" view controllers, where the UIKit `safeAreaInsets` API falls short. | |
var twSafeAreaInsets: UIEdgeInsets { | |
guard #available(iOS 11.0, *) else { |
This file contains hidden or 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
class RSVerticallyCenteredTextFieldCell: NSTextFieldCell { | |
var mIsEditingOrSelecting:Bool = false | |
override func drawingRect(forBounds theRect: NSRect) -> NSRect { | |
//Get the parent's idea of where we should draw | |
var newRect:NSRect = super.drawingRect(forBounds: theRect) | |
// When the text field is being edited or selected, we have to turn off the magic because it screws up | |
// the configuration of the field editor. We sneak around this by intercepting selectWithFrame and editWithFrame and sneaking a | |
// reduced, centered rect in at the last minute. |
This file contains hidden or 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
/* | |
Erica Sadun, http://ericasadun.com | |
Cross Platform Defines | |
Apple Platforms Only | |
Will update to #if canImport() when available | |
*/ |
This file contains hidden or 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
// Makes the text in an NSTextFieldCell vertically centered. Works with single line, non-editable cells. | |
// Maybe doesn't work with others. | |
// Stolen from this stackoverflow question: | |
// http://stackoverflow.com/questions/1235219/is-there-a-right-way-to-have-nstextfieldcell-draw-vertically-centered-text | |
import Cocoa | |
class VerticallyCenteredTextFieldCell: NSTextFieldCell { | |
override func titleRect(forBounds rect: NSRect) -> NSRect { |
This file contains hidden or 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 UIKit | |
extension UIImage { | |
// colorize image with given tint color | |
// this is similar to Photoshop's "Color" layer blend mode | |
// this is perfect for non-greyscale source images, and images that have both highlights and shadows that should be preserved | |
// white will stay white and black will stay black as the lightness of the image is preserved | |
func tint(tintColor: UIColor) -> UIImage { | |
This file contains hidden or 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 cv2 | |
import json | |
import numpy | |
import re | |
import sys | |
from operator import itemgetter, attrgetter | |
from colormath.color_objects import sRGBColor, LabColor | |
from colormath.color_conversions import convert_color | |
from colormath.color_diff import delta_e_cie2000 |