This file contains 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
@implementation NSArray (GroupBy) | |
- (NSArray *)groupByKeyPath:(NSString *)keyPath { | |
NSArray *distinctValues = [self valueForKeyPath:[@"@distinctUnionOfObjects." stringByAppendingString:keyPath]]; | |
NSMutableArray *result = [NSMutableArray arrayWithCapacity:[distinctValues count]]; | |
for (id groupValue in distinctValues) { | |
NSString *predicateFormat = [NSString stringWithFormat:@"(%@ == %%@)", keyPath]; | |
NSPredicate *predicate = [NSPredicate predicateWithFormat:predicateFormat, groupValue]; | |
NSArray *group = [self filteredArrayUsingPredicate:predicate]; |
This file contains 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 foldl1<A>(list: Array<A>, f: (A, A) -> A) -> A { | |
return foldl(list.head!, list: list.tail!, f: f) | |
} | |
extension Array { | |
var initial: Array<Element>? { | |
get { | |
if self.empty() { return nil } | |
return Array(dropLast(self)) | |
} |
This file contains 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 empty() -> Bool { | |
return self.count == 0 | |
} | |
var head: Element? { | |
get { | |
return self.first | |
} | |
} |
This file contains 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
protocol TreeLike {} | |
enum Tree<T> : TreeLike { | |
case Leaf(@autoclosure () -> T) | |
case Node(TreeLike, TreeLike) | |
} | |
func node<T>(left: Tree<T>, right: Tree<T>) -> Tree<T> { | |
return Tree.Node(left, right) | |
} |
This file contains 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
# Very simple prompt with: | |
# User, Git information, current working directory | |
# Special feature (because I love useless stuff) is a random prompt character for each new session | |
# in the form of a short one line ASCII-Art (Yeah! ASCII-Art) | |
# | |
# Some ASCII-Art might be NSFW, so be aware if you you use this prompt in public ;) | |
# | |
# Source of ASCII-Art: http://1lineart.kulaone.com | |
# | |
# Author: Henning Brandt |
This file contains 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 ruby | |
# Simple script to scrape for one line ASCII-Art and filter them by character-type and length. | |
# It than constructs a shell-script array and ouputs it to the file argument. | |
# | |
# Author: Henning Brandt | |
# Created: 04.01.15 | |
# Licence: MIT | |
# |