Skip to content

Instantly share code, notes, and snippets.

View Qata's full-sized avatar

Charles Maria Tor Qata

View GitHub Profile
import Foundation
enum Zone {
indirect case node(component: String, leaves: [Zone])
case leaf(component: String, path: String)
}
func recurseCreateZones(path: [String], separated: [String], root: Zone) -> Zone {
guard case .node(let component, let leaves) = root else { fatalError() }
switch (separated.first, separated.count) {
@Qata
Qata / multiply.hs
Last active January 17, 2017 23:58
(*!) :: (Ord a, Num a) => a -> a -> a
(*!) a b =
let
multiply _ 0 t = t
multiply a b t = multiply a (b - 1) (t + a)
in
if b >= 0
then multiply a b 0
else negate $ multiply a (negate b) 0
#!/usr/bin/env ruby
#Convert a video into chunks of a given size
chunk = ARGV.shift.to_f
file = ARGV.shift
extension = File.extname(file)
basename = File.join(File.dirname(file), File.basename(file, extension))
durations = `ffmpeg -i '#{file}' 2>&1`.match(/Duration: ([\d:.]*)/).captures.first.split(':')
seconds = durations[0].to_f * 3600 + durations[1].to_f * 60 + durations[2].to_f
n_chunks = (seconds / chunk).ceil
@Qata
Qata / Pronounify.hs
Last active February 4, 2017 08:51
import Data.String.Utils
import Data.List
import Data.Char
import Data.Maybe
import System.Environment
main :: IO ()
main = do
strings <- getArgs
mapM_ (putStrLn . pronounify) strings
class ViewController: UIViewController {
@IBOutlet weak var nameTextField: UITextField!
@IBOutlet weak var passwordTextField: UITextField!
func nameValidation(for field: UITextField) -> Signal<Bool, NoError> {
return field
.reactive
.continuousTextValues
.skipNil()
.map { $0.characters.count > 3 }
//
// Monoid.swift
// FPExamples
//
// Created by Charlotte Tortorella on 28/11/16.
// Copyright © 2016 Charlotte Tortorella. All rights reserved.
//
import Foundation
precedencegroup ForwardApplicationPrecedence {
associativity: left
}
/// Applies `f` to `arg`.
infix operator |> : ForwardApplicationPrecedence
func |> <T, U>(arg: T, f: (T) -> U) -> U {
return f(arg)
}
import ReactiveCocoa
import ReSwift
import Result
class ObservableStore<State: StateType>: Store<State> {
internal let observable: MutableProperty<State>
var producer: SignalProducer<State, NoError> {
get {
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 {