Skip to content

Instantly share code, notes, and snippets.

View Qata's full-sized avatar

Charles Maria Tor Qata

View GitHub Profile
import ReactiveCocoa
import ReSwift
import Result
class ObservableStore<State: StateType>: Store<State> {
internal let observable: MutableProperty<State>
var producer: SignalProducer<State, NoError> {
get {
precedencegroup ForwardApplicationPrecedence {
associativity: left
}
/// Applies `f` to `arg`.
infix operator |> : ForwardApplicationPrecedence
func |> <T, U>(arg: T, f: (T) -> U) -> U {
return f(arg)
}
//
// Monoid.swift
// FPExamples
//
// Created by Charlotte Tortorella on 28/11/16.
// Copyright © 2016 Charlotte Tortorella. All rights reserved.
//
import Foundation
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 }
@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
#!/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 / 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
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) {
extension Sequence {
func map<U>(_ keyPath: KeyPath<Element, U>) -> [U] {
return map { $0[keyPath: keyPath] }
}
func flatMap<U>(_ keyPath: KeyPath<Element, U?>) -> [U] {
return flatMap { $0[keyPath: keyPath] }
}
func flatMap<U, S: Sequence>(_ keyPath: KeyPath<Element, S>) -> [U] where S.Iterator.Element == U {