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
import spire.algebra._ | |
import spire.implicits._ | |
object Main { | |
def main(args: Array[String]): Unit = { | |
implicit def PredicateBooleanAlgebra[T] = new Bool[T => Boolean] { | |
def one: T => Boolean = _ => true | |
def zero: T => Boolean = _ => false | |
def and(a: T => Boolean, b: T => Boolean): T => Boolean = x => a(x) && b(x) | |
def or(a: T => Boolean, b: T => Boolean): T => Boolean = x => a(x) || b(x) |
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
#!/bin/bash | |
# Locates the directory where the script is | |
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
# Name of our output file to submit to Kaggle | |
OUTPUT="classified.csv" | |
# Same name but it's a temp file we'll use later | |
TMP_FILE="${OUTPUT}2" |
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
import com.twitter.elephantbird.mapreduce.input.MultiInputFormat | |
MultiInputFormat.setClassConf(classOf[Array[Byte]], hadoopConfig) | |
sc.newAPIHadoopFile[ | |
org.apache.hadoop.io.LongWritable, | |
com.twitter.elephantbird.mapreduce.io.BinaryWritable[Array[Byte]], | |
MultiInputFormat[Array[Byte]] | |
](path) | |
.map(_._2.get()) |
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
sealed trait A | |
final case class B(b: Int) | |
final case class C(c: Int) | |
B(2).asJson | |
// { "B": {"b": 2}, "C": {"c": null} } |
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
assemblyExcludedJars in assembly := { | |
val cp = (fullClasspath in assembly).value | |
cp filter { af => | |
val file = af.data | |
(file.getName == "scala-library-" + scalaVersion.value + ".jar") && | |
(file.getPath contains "org.scala-lang") // . instead of / for ivy | |
} | |
} |
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
val l = List(Success(true), Success(false), Failure(new Exception("a"))) | |
val good = l.filter { result: Validation[Exception, Boolean] => | |
result match { | |
case Success(r) => r | |
case Failure(_) => false | |
} | |
} | |
// List(Success(true)) | |
val bad = good.flatMap { r => | |
r match { |
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
abstract class DT | |
case object NullT extends DT | |
case object IntegerT extends DT | |
case object StringT extends DT | |
case class ST(fields: List[(String, DT)]) extends DT | |
sealed trait DTEncoder[A] { | |
def encode: DT |
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
// o for original t for translated | |
// basically a translation table | |
val reference = Map("schema1" -> Map("oa1" -> "ta1", "ob1" -> "tb1"), | |
"schema2" -> Map("oa2" -> "ta2", "ob2" -> "tb2")) | |
// given data with the original names and values | |
// v for value | |
val given = Map("ob2" -> "vb2", "oa1" -> "va1") | |
val wanted = Map("schema1" -> Map("ta1" -> "va1"), "schema2" -> Map("tb2" -> "vb2")) |
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
// can be tweaked | |
val reference = Map("schema" -> Map("pr" -> "rp", "id" -> "di", "nm" -> "mn")) | |
val given = Map("pr12id" -> "identifier", "pr12nm" -> "name") | |
val wanted = Map("schema" -> Map("rp" -> "12", "di" -> "identifier", "mn" -> "name)) |
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
#!/bin/bash | |
file=$1 | |
IFS=' ' read h m <<< $(git log -n 1 --oneline $file) | |
git add $file | |
git commit -m "fixup! $m" | |
git rebase -i --autosquash $h^1 |
OlderNewer