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 | |
| /// Given a `String?`, return an `NSNumber` Boolean value that is true if the value is non-nil and not empty. | |
| /// | |
| /// This is useful for binding the `enabled` property of a button to a string value that is bound to a text field. | |
| final class IsNotNilOrEmptyValueTransformer: NSValueTransformer { | |
| override class func transformedValueClass() -> AnyClass { | |
| return NSNumber.self |
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
| \ Blink an LED connected to GPIO pin 18 | |
| \ | |
| \ Must be run with root/sudo. For example: "sudo gforth blink.fs" | |
| require wiringPi.fs | |
| wiringPiSetupGpio drop | |
| 18 constant ledPin | |
| ledPin OUTPUT pinMode |
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
| LDLIBS=-lwiringPi | |
| blink: blink.c | |
| run: blink | |
| sudo ./blink | |
| .PHONY: run | |
| clean: | |
| $(RM) blink |
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 | |
| /// Demonstrate launching an `NSTask` and asynchronously reading its output. | |
| /// | |
| /// Credit: <http://stackoverflow.com/a/23938137/1175> | |
| func testTaskOutputPipe() { | |
| let task = NSTask() | |
| task.launchPath = "/bin/ls" | |
| task.arguments = ["-l", "/Applications"] |
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 | |
| /// Given a positive integer, find its prime factors. | |
| /// | |
| /// - parameter number: The number to be factored. | |
| /// | |
| /// - returns: Array of factors. | |
| /// | |
| /// - TODO: Use a less-naive algorithm. Construct the result lazily. |
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 | |
| extension String { | |
| /// Returns a new string made by appending to the receiver a filesystem path component. | |
| /// | |
| /// - parameter pathComponent: The path component to be appended to the receiver. | |
| /// | |
| /// - returns: A new `String` made by appending `pathComponent` to the receiver, preceded if necessary by a path separator. | |
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 | |
| /// Given a wildcard pattern, return matching paths. | |
| /// | |
| /// - parameter pattern: pathname pattern to be expanded. See docs for `glob(3)`. | |
| /// - returns: array of pathnames that match the pattern | |
| func matchingFilesForPattern(pattern: String) -> [String] { | |
| var result = Array<String>() | |
| var g = glob_t() |
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
| // Implementation of Robert C. Martin's turnstile state-machine example | |
| /// Defines the "events" that can be invoked on a turnstile-like object. | |
| protocol TurnstileEventHandler { | |
| func onCoin() | |
| func onPass() | |
| } | |
| /// Defines the "actions" that a turnstile can take due to an event or state transition. | |
| protocol TurnstileActionDelegate: class { |
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
| #!/usr/bin/swift | |
| // Gets the info.plist data for executables specified on command line | |
| import Foundation | |
| if Process.argc < 2 { | |
| print("usage: get-info-dictionary EXECUTABLE...") | |
| } | |
| 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 Cocoa | |
| class MyInitiallyPositionedWindowController: NSWindowController { | |
| override func windowDidLoad() { | |
| super.windowDidLoad() | |
| if let window = window, screen = window.screen { | |
| let screenRect = screen.visibleFrame | |
| let offsetFromLeft = CGFloat(200) |