Skip to content

Instantly share code, notes, and snippets.

View Qata's full-sized avatar

Charles Maria Tor Qata

View GitHub Profile
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)
}
}
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)
}
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))
}
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) {
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
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"
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)
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 = []
+ (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);
//
// CTMaybe.c
// Firestarter
//
// Created by Charlotte Tortorella on 17/03/2016.
// Copyright © 2016 DALI Lighting. All rights reserved.
//
#include "CTMaybe.h"