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 | |
| import IOKit | |
| func getMACAddress() -> String { | |
| let matching = IOServiceMatching("IOEthernetInterface") as NSMutableDictionary | |
| matching[kIOPropertyMatchKey] = ["IOPrimaryInterface": true] | |
| var servicesIterator: io_iterator_t = 0 | |
| defer { IOObjectRelease(servicesIterator) } | |
| guard IOServiceGetMatchingServices(kIOMasterPortDefault, matching, &servicesIterator) == KERN_SUCCESS 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
| import Alamofire | |
| import RxSwift | |
| extension Request: ReactiveCompatible {} | |
| extension Reactive where Base: DataRequest { | |
| func responseJSON() -> Observable<Any> { | |
| return Observable.create { observer in | |
| let request = self.base.responseJSON { response in |
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 progress = Progress(parent: nil, userInfo: [ | |
| .fileOperationKindKey: Progress.FileOperationKind.downloading, | |
| .fileURLKey: URL(fileURLWithPath: "/Users/mminer/Downloads/somefile.zip"), | |
| ]) | |
| progress.isCancellable = true | |
| progress.isPausable = false | |
| progress.kind = .file |
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 RxSwift | |
| extension ObservableType { | |
| /// A map that unwraps an optional value, only continuing if the result is not nil. | |
| func ignoreNilMap<R>(transform: @escaping (E) -> R?) -> Observable<R> { | |
| return Observable.create { observer in | |
| return self.subscribe { element in | |
| switch element { | |
| case .next(let value): |
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 RxSwift | |
| import SocketIO | |
| extension Reactive where Base: SocketIOClient { | |
| public func on(_ event: String) -> Observable<[Any]> { | |
| return Observable.create { observer in | |
| let id = self.base.on(event) { items, _ in | |
| observer.onNext(items) | |
| } |
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
| // 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 { |
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 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 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
| 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 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
| // Usage: | |
| // | |
| // const backspace = 8; | |
| // | |
| // export default withHotkeys({ | |
| // [backspace]: props => evt => { | |
| // ... | |
| // }, | |
| // })(YourComponent); |
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
| /* | |
| <label className="switch"> | |
| <input type="checkbox" /> | |
| <div className="checkbox"></div> | |
| </label> | |
| */ | |
| .switch { | |
| $active-color: #27c940; | |
| $switch-height: 24px; |