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 SequenceType { | |
| func find(predicate: Generator.Element -> Bool) -> Generator.Element? { | |
| for x in self { | |
| if predicate(x) { return x } | |
| } | |
| return .None | |
| } | |
| } | |
| infix operator <|> {} |
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 Data.Monoid | |
| import Control.Applicative | |
| import Data.Maybe | |
| main = mapM_ putStrLn $ mapMaybe fizzy [1..315] | |
| fizzy :: Int -> Maybe String | |
| fizzy n = fizz <> buzz <> tizz <> wuzz <|> pure (show n) | |
| where | |
| fizz = modReplace 3 "Fizz" |
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 Array { | |
| /* | |
| 'span' takes a predicate and returns a tuple where first element is longest prefix (possibly empty) | |
| of elements of self that satisfy 'predicate' and second element is the remainder of self: | |
| -- > [1,2,3,4,1,2,3,4].span { $0 < 3 } == ([1,2],[3,4,1,2,3,4]) | |
| -- > [1,2,3].span { $0 < 9 } == ([1,2,3],[]) | |
| -- > [1,2,3].span { $0 < 0 } == ([],[1,2,3]) | |
| */ | |
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
| /* | |
| A silly example demonstrating how object-oriented inhertitance can conflict with protocol oriented Swift | |
| */ | |
| class Animal { | |
| func respire() { print("Yum, oxygen") } | |
| } | |
| class Wolf: Animal { | |
| func growl() { print("Grrrr!") } |
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
| // Create an `Observable` of Optional<Int> | |
| let values: Observable<Int?> = [1, 2, .None, 3, .None, 4, 5].toObservable() | |
| // Method 1: using a free function | |
| // Requires passing the function to `flatMap` | |
| func ignoreNil<A>(x: A?) -> Observable<A> { | |
| return x.map { Observable.just($0) } ?? Observable.empty() | |
| } |
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/env nix-shell | |
| #! nix-shell -i bash -p ffmpeg gifsicle | |
| scale="${3:-320}" | |
| fps="${4:-15}" | |
| palette="/tmp/palette.png" | |
| filters="fps=$fps,scale=$scale:-1:flags=lanczos" | |
| ffmpeg -v warning -i "$1" -vf "$filters,palettegen=stats_mode=diff" -y $palette | |
| ffmpeg -i "$1" -i $palette -lavfi "$filters,paletteuse=dither=bayer:bayer_scale=5:diff_mode=rectangle" -y -f gif - \ |
OlderNewer