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 Foundation | |
| func format(bytes: Double) -> String { | |
| guard bytes > 0 else { | |
| return "0 bytes" | |
| } | |
| // Adapted from http://stackoverflow.com/a/18650828 | |
| let suffixes = ["bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"] | |
| let k: Double = 1000 |
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 AppKit | |
| extension NSImage { | |
| convenience init?(base64EncodedString: String) { | |
| guard | |
| let url = URL(string: base64EncodedString), | |
| let data = try? Data(contentsOf: url) | |
| 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
| extension String { | |
| func insert(_ string: String, at index: Int) -> String { | |
| let prefix = String(characters.prefix(index)) | |
| let suffix = String(characters.suffix(characters.count - index)) | |
| return prefix + string + suffix | |
| } | |
| } |
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 AppKit | |
| class HoverView: NSView { | |
| override var wantsUpdateLayer: Bool { | |
| return true | |
| } | |
| private var isMouseOver = false { | |
| didSet { |
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 AppKit | |
| class VerticallyCenteredTextFieldCell: NSTextFieldCell { | |
| // Adapted from http://stackoverflow.com/a/8626071 | |
| override func drawInterior(withFrame cellFrame: NSRect, in controlView: NSView) { | |
| let adjustedFrame = adjusted(frame: cellFrame) | |
| super.drawInterior(withFrame: adjustedFrame, in: controlView) | |
| } |
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 AppKit | |
| protocol OutlineViewDelegate { | |
| func outlineView(outlineView: NSOutlineView, menuForItem item: Any) -> NSMenu? | |
| } | |
| extension OutlineViewDelegate { | |
| func outlineView(outlineView: NSOutlineView, menuForItem item: Any) -> NSMenu? { |
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 Foundation | |
| let iso8601Formatter: DateFormatter = { | |
| let formatter = DateFormatter() | |
| formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ" | |
| return formatter | |
| }() |
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 Foundation | |
| func isPortInUse(_ port: Int) -> Bool { | |
| // Use netstat to find ports in use then grep for one we're interested in. | |
| // See this solution for piping shell commands: http://stackoverflow.com/a/16650638 | |
| let process = Process() | |
| process.launchPath = "/bin/sh" | |
| process.arguments = ["-c", "netstat -an | grep '\\b\(port)\\b' | grep LISTEN"] | |
| process.standardOutput = Pipe() | |
| process.launch() |