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
#!/bin/bash | |
set -e | |
SRC_FILE="$1" | |
DST_PATH="$2" | |
VERSION=1.0.0 | |
info() { |
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
// same as scanl but without initial | |
extension Array { | |
func scanl(combine: (Element, Element) -> Element) -> [Element] { | |
guard let first = self.first else { return [] } | |
return Array(self.dropFirst()).scanl(initial:first, combine:combine) | |
} | |
} |
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 where Element: Hashable { | |
var occurrencesCount :[Element : Int] { | |
var map = [Element : Int]() | |
forEach { element in | |
if let val = map[element]{ | |
map[element] = val+1 | |
} else { | |
map[element] = 1 | |
} |
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 { | |
func partition(predicate: (Element) -> Bool) -> ([Element],[Element]) { | |
var res = (satisfy:[Element](),notSatisfy:[Element]()) | |
self.forEach { element in | |
if predicate(element){ | |
res.satisfy.append(element) | |
} else { | |
res.notSatisfy.append(element) | |
} |
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 { | |
func scanl<T>(initial: T, combine:@noescape (Element, T) -> T) -> [T] { | |
guard let first = self.first else { return [initial] } | |
return [initial] + Array(self.dropFirst()).scanl(initial: combine(first, initial), combine: combine) | |
} | |
} |
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 Lens<A,B> { | |
let get: (A) -> B | |
let set: (B,A) -> A | |
} | |
extension Lens { | |
func compose<C>(other: Lens<B, C>) -> Lens<A, C> { | |
return Lens<A, C>( | |
get: { whole in | |
let part = self.get(whole) |
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 JSONFromFile(file: String) -> AnyObject? { | |
return NSBundle(forClass: self.dynamicType).pathForResource(file, ofType: "json") | |
.flatMap { NSData(contentsOfFile: $0) } | |
.flatMap(JSONObjectWithData) | |
} | |
private func JSONObjectWithData(data: NSData) -> AnyObject? { | |
return try? NSJSONSerialization.JSONObjectWithData(data, options: []) | |
} |
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 NSURL { | |
func getQueryItemValueForKey(key: String) -> String? { | |
guard let components = NSURLComponents(URL: self, resolvingAgainstBaseURL: false) else { | |
return nil | |
} | |
guard let queryItems = components.queryItems else { return nil } | |
return queryItems.filter { | |
$0.name == key | |
}.first?.value |
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 UIColor { | |
convenience init?(hexString userHexString: String, alpha: CGFloat) { | |
var hexString:String = userHexString.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()) | |
if (hexString.hasPrefix("#")) { | |
hexString = hexString.substringFromIndex(hexString.startIndex.advancedBy(1)) | |
} | |
let hexNum = CGFloat(strtoul(hexString, nil, 16)) |
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 CollectionType { | |
@warn_unused_result | |
func toDictionary<K, V> | |
(@noescape transform:(element: Self.Generator.Element) -> (key: K, value: V)?) -> [K : V] { | |
return self.reduce([:]) { (var dictionary, e) in | |
if let (key, value) = transform(element: e){ | |
dictionary[key] = value | |
} | |
return dictionary | |
} |