Skip to content

Instantly share code, notes, and snippets.

@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"))
@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: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?!)
# 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:
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Top Secret stack",
"Parameters": {
"Name": {
"Description": "Name of the service",
"Type": "String"
},
@nicl
nicl / age.py
Created October 27, 2016 11:17
print 40
@nicl
nicl / HigherOrLower.scala
Created July 5, 2017 16:09
Example higher or lower
import scala.util.Random
trait Guess
case object Higher extends Guess
case object Lower extends Guess
val deck = 1 to 10
def shuffle(decks: Seq[Seq[Int]]): Seq[Int] = {
val shuffled = Random.shuffle(decks.flatten)
@nicl
nicl / scala-good-parts.md
Last active September 17, 2020 08:58
Scala - the good parts
@nicl
nicl / branching.md
Last active July 16, 2018 09:54
Branching thoughts

If you were to draw your code flow as a graph, what would it look like?

It's a useful question I've found in discerning what a good and bad architecture looks like.

Consider, the following two cases:

1)  /\

/ \

select
talk_node.nid as id,
talk_meta.title as title,
node__field_talk_description.field_talk_description_value as description,
speaker_meta.title as author,
talk_meta.created as timestamp,
DATE_FORMAT(FROM_UNIXTIME(talk_meta.created), '%d/%m/%y') as date
from
node as talk_node,
node as speaker_node,