Skip to content

Instantly share code, notes, and snippets.

# Election results
It's election night! Exciting! We have a feed of election results from a data supplier. They will supply us a file which will be updated throughout the night as results come in.
## Results format
The fields in the file will be separated by commas but each row will vary in length as described below.
A result will consist of:
@nicl
nicl / gist:776368c22ab21faddc15
Created September 30, 2014 10:51
Scala concurrency questions
val myFuture = someFuture // from a previous async op
val result = myFuture map { f =>
slowOp(f) // either takes ages or doesn't complete at all
}
// then some timeout on result
timeout(result, fallback)
// question is: if fallback is used, what happens to the execution of the slowOp (does it continue and hog resources?!)
@nicl
nicl / gist:5620254
Last active December 17, 2015 13:49
Scala Universal Set
class UniversalSet[A] extends Set[A] {
def contains(key: A) = true
def iterator = throw new UnsupportedOperationException()
def +(elem: A) = this
def -(elem: A) = throw new UnsupportedOperationException()
override def toString: String = "UniversalSet"
}
@nicl
nicl / gist:5541327
Last active December 17, 2015 03:09
Convert data table string into usable form
/**
* Convert a dataTable string representation into a List of Maps. For example:
*
* | x | y |
* | 1 | a is |
* | 2 | b does |
*
* Becomes:
*
* List(Map(x -> 1, y -> "a is"), Map(x -> 2, y -> "b does"))