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 AppKit | |
class HoverView: NSView { | |
override var wantsUpdateLayer: Bool { | |
return true | |
} | |
private var isMouseOver = false { | |
didSet { |
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 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 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 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 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
/* | |
<label className="switch"> | |
<input type="checkbox" /> | |
<div className="checkbox"></div> | |
</label> | |
*/ | |
.switch { | |
$active-color: #27c940; | |
$switch-height: 24px; |
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
// Usage: | |
// | |
// const backspace = 8; | |
// | |
// export default withHotkeys({ | |
// [backspace]: props => evt => { | |
// ... | |
// }, | |
// })(YourComponent); |
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
func parent(ofPath path: String, levels: Int) -> String { | |
var parentPath = path | |
for _ in 1...levels { | |
parentPath = (parentPath as NSString).deletingLastPathComponent | |
} | |
return parentPath | |
} |
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 PlaygroundSupport | |
import SpriteKit | |
// Set up scene: | |
let size = CGSize(width: 480, height: 320) | |
let scene = SKScene(size: size) | |
scene.physicsBody = SKPhysicsBody(edgeLoopFrom: scene.frame) | |
scene.physicsWorld.gravity = CGVector.zero // Enabled later |
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
// Adapted from http://stackoverflow.com/a/1248 | |
private let minuteInterval: TimeInterval = 60 | |
private let hourInterval: TimeInterval = 60 * minuteInterval | |
private let dayInterval: TimeInterval = 24 * hourInterval | |
private let monthInterval: TimeInterval = 30 * dayInterval | |
extension Date { | |
var relative: String { |