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
+ (void)installWiFiStatusChangedAlertView:(UIViewController *)viewController | |
{ | |
[[[RPCController WiFiStatusChanged] filter:^BOOL(id value) { | |
return ![RPCController isWiFiEnabled] || ![RPCController isWiFiConnected]; | |
}] subscribeNext:^(id _) { | |
NSString *title = nil; | |
NSString *message = nil; | |
if (![RPCController isWiFiEnabled]) | |
{ | |
title = NSLocalizedString(@"WiFi is disabled", 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
struct ControlLineNode: ControlNode { | |
let mac: String | |
let line: UInt8 | |
var groups: [ControlGroupNode] | |
var devices: [ControlDeviceNode] | |
init(withMAC macAddress: String, line lineNumber: UInt8) { | |
mac = macAddress | |
line = lineNumber | |
groups = [] | |
devices = [] |
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
enum RpcCommand { | |
case Echo(ControlNode, AnyObject) | |
case ReadGateway(ControlNode) | |
case RunCommand(ControlNode, RpcRunCommand) | |
case ReadLine(ControlLineNode) | |
case ReadAddress(ControlDeviceNode) | |
case ReadGroup(ControlGroupNode) | |
case ReadGroupData(ControlGroupNode) | |
case ForceReadAddress(ControlDeviceNode) | |
case FindAllUnaddressed(ControlLineNode) |
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 Graphics.Element exposing (Element, leftAligned, flow, down) | |
import List exposing (map, intersperse) | |
import Text exposing (fromString) | |
fizzBuzz : Int -> String | |
fizzBuzz n = | |
case (n % 3, n % 5) of | |
(0, 0) -> "FizzBuzz" | |
(0, _) -> "Fizz" | |
(_, 0) -> "Buzz" |
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 groupByFirstLetter(strings: [String]) -> [String : [String]] { | |
let dictionaries: [[String : [String]]] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".characters.map { (character) -> [String : [String]] in | |
let values = strings.filter { | |
$0.uppercaseString.hasPrefix(String(character)) | |
} | |
return [String(character) : values] | |
}.filter { $0.values.first!.count > 0 } | |
return dictionaries.reduce([:]) { (collector: [String : [String]], dictionary) -> [String : [String]] in | |
var returnCollector = collector |
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 sendCommand(command: RpcCommand, controller: ControlNode) -> SignalProducer<AnyObject, RpcControllerError> { | |
self.mac = controller.mac | |
let (method, params) = command.rpcTuple | |
return self.sendCommand(method, withParams: params).toSignalProducer() | |
.ignoreNil() | |
.map { $0["result"] } | |
.mapError { (error: NSError) -> RpcControllerError in | |
switch error.domain { | |
case NSPOSIXErrorDomain: | |
switch Int32(error.code) { |
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 groupByFirstLetter(strings: [String]) -> [String : [String]] { | |
let A = ("A" as NSString).characterAtIndex(0) | |
let Z = ("Z" as NSString).characterAtIndex(0) | |
let dictionaries: [[String : [String]]] = (A...Z).map { | |
Character(UnicodeScalar($0)) | |
}.map { (character) -> [String : [String]] in | |
let values = strings.filter { | |
$0.uppercaseString.hasPrefix(String(character)) | |
} |
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
infix operator <<< { associativity right } | |
func <<< <A, B, C>(f: B -> C, g: A -> B) -> A -> C { | |
return composeBackward(f, g: g) | |
} | |
infix operator >>> { associativity left } | |
func >>> <A, B, C>(g: A -> B, f: B -> C) -> A -> C { | |
return composeForward(g, f: f) | |
} |
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 Decodable { | |
static func oneOf(json: AnyObject, objects: (Decodable.Type)...) throws -> Decodable { | |
for decodable in objects.dropLast() { | |
if let decoded = try? decodable.decode(json) { | |
return decoded | |
} | |
} | |
return try (objects.last!).decode(json) | |
} | |
} |
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 Device: Decodable { | |
static func decode(json: AnyObject) throws -> Device { | |
guard let resolvedTypes = try json => "devices" as? NSArray else { | |
throw NSArraySucks.ItReallySucks | |
} | |
let types = try (resolvedTypes as [AnyObject]).map { | |
try decodeAsOneOf($0, objectTypes: MSensorType.self, ColourType.self, LEDType.self, GenericType.self) | |
}.flatMap { |