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
// You've gotta start somewhere | |
import akka.dispatch.Future | |
implicit val system = akka.actor.ActorSystem("MySystem") | |
// lame | |
val WHY_YOU_TAKE_SO_LONG: Seq[Kitten] = | |
grep(theWorld, kittens) | |
// awesome | |
val allKittens: Future[Seq[Kitten]] = |
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
/** tap implementation for C++11 */ | |
template<typename T, typename F> | |
T tap(T &&obj, F const &fn) { | |
fn(obj); | |
return obj; | |
} | |
// usage | |
tap(new User(params), [](User *u) { | |
if (u->isValid()) { |
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
val fib: Stream[BigInt] = { | |
def nextFib(a: BigInt, b: BigInt): Stream[BigInt] = { | |
Stream.cons(a + b, nextFib(b, a + b)) | |
} | |
Stream.cons(0, Stream.cons(1, nextFib(0, 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
object ZzubZzif { | |
val fizzbuzz: PartialFunction[Int, String] = { | |
case x if x % 15 == 0 => "fizzbuzz" | |
case x if x % 5 == 0 => "buzz" | |
case x if x % 3 == 0 => "fizz" | |
} | |
// I'm actually embarrassed that this is the best I can do | |
def zzubzzif(seq: Seq[String]): Seq[Int] = { | |
val fizzbuzzIndexed = new PartialFunction[(Int, Int), (String, Int)] { |
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 | |
# | |
# Runs a program, stripping ANSI color codes from stdout and stderr | |
# | |
# detect which sed to use | |
if test -z ${SED}; then | |
if cat /dev/null | sed -r '' 2> /dev/null ; then | |
SED=sed |
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 a map | |
val cars = Map("james" -> "BMW", "ike" -> "Infiniti", "stephen" -> "Buick") | |
//create a map from an Array | |
//Scala does not provide a convenience method to do this... :( | |
val carArray = Array("james", "BMW", "ike", "Infiniti", "stephen", "Buick") | |
val cars = carArray.grouped(2).toList.map(c => (c.head,c.last)).toMap | |
//mapping over a map | |
//transform all string keys to symbols (interned strings) |
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
trait Searchable { | |
def search(query: SearchQuery): Seq[SearchResults] | |
} | |
trait PaginationWithNominalType { | |
this: Searchable => | |
def page(query: SearchQuery, pageSize: Int, pageNum: Int) = { | |
search(query).grouped(pageSize).toList(pageNum) | |
} | |
} |
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
#include <stdio.h> | |
int main() { | |
printf("Goodbye, dmr.\n"); | |
return 0; | |
} |
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
// FizzBuzz in Scala | |
// http://www.codinghorror.com/blog/2007/02/why-cant-programmers-program.html | |
1 to 100 map { | |
case x if x % 15 == 0 => "FizzBuzz" | |
case x if x % 3 == 0 => "Fizz" | |
case x if x % 5 == 0 => "Buzz" | |
case x => x | |
} foreach (println _) |