Skip to content

Instantly share code, notes, and snippets.

View josep2's full-sized avatar
🎯
Focusing

Jowanza Joseph josep2

🎯
Focusing
View GitHub Profile
import org.apache.spark.sql.expressions.MutableAggregationBuffer
import org.apache.spark.sql.expressions.UserDefinedAggregateFunction
import org.apache.spark.sql.Row
import org.apache.spark.sql.types._
class HarmonicMean extends UserDefinedAggregateFunction {
// Defind the schema of the input data
override def inputSchema: org.apache.spark.sql.types.StructType =
StructType(StructField("value", DoubleType) :: Nil)
case class ConnectMessage(deviceId: Long)
case object DisconnectMessage
case object VolumeAdjustmentMessage
case object PauseMessage
class BluetoothHeadphones extends Actor {
def receive = {
case ConnectMessage(message) =>
case DisconnectMessage =>
case VolumeAdjustmentMessage =>
sealed abstract class Action extends Product with Serializable
object Camera {
final case class Picture(iso: Int, aperture: Double) extends Action
final case class Video (duration: Int) extends Action
}
def actionHandler(action: Action): Unit = action match {
case Camera.Picture(iso, app) => print(s"Took photo with iso: $iso and aperture $app")
case Camera.Video(dur) => print(s"Took video for $dur seconds")
case class Watch(mechanism: String)
val swissWatch = Watch("swiss")
println(swissWatch)
// Watch(swiss)
case class Album(title: String, year: Int)
val bitusa = Album("Born in the USA", 1980)
val bitusaRemaster = Album.copy(year = 1991)
case class Player(name: String)
val biggie = Player("Biggie")
biggie.name = "2pac"
// error: reassignment to val
case class Drink(name: String)
val henny = Drink("henny")
val henny2 = henny.copy()
println(henny.equals(henny2))
//true
sealed trait Topping
case object RefriedBeans extends Topping
case object Onions extends Topping
case object Lettuce extends Topping
case object Salsa extends Topping
sealed trait Shell
case object CornTortilla extends Shell
case object TortillaChips extends Shell
case object FlourTortilla extends Shell
// from https://blog.codecentric.de/en/2016/07/spark-2-0-datasets-case-classes/
final case class Body(id: Int,
width: Double,
height: Double,
depth: Double,
material: String,
color: String)
val ds = df.as[Body]
// From https://github.com/spray/spray-json
case class Color(name: String, red: Int, green: Int, blue: Int)
object MyJsonProtocol extends DefaultJsonProtocol {
implicit val colorFormat = jsonFormat4(Color)
}
import MyJsonProtocol._
import spray.json._