Skip to content

Instantly share code, notes, and snippets.

View darionyaphet's full-sized avatar
🫐
On vacation

yaphet darionyaphet

🫐
On vacation
View GitHub Profile
package org.darion.yaphet.gearpump
import org.apache.gearpump.cluster.UserConfig
import org.apache.gearpump.cluster.client.ClientContext
import org.apache.gearpump.streaming.{Processor, StreamApplication}
import org.apache.gearpump.streaming.partitioner.HashPartitioner
import org.apache.gearpump.streaming.source.DataSourceProcessor
import org.apache.gearpump.util.{AkkaApp, Graph}
import org.apache.gearpump.util.Graph.Node
@darionyaphet
darionyaphet / Case2Tuple
Last active May 10, 2017 09:45
Case Class --> Tuple
case class People(name: String, age: Int)
val me = People("darion.yaphet", 26)
val (name, age) = People.unapply(me).get
************************************************************
val (name_, age_) = me match {
case People(name, age) => (name, age)
}
@darionyaphet
darionyaphet / ScalaCollection
Created April 27, 2017 10:12
ScalaCollection
scala> Array(1,2,3,4,5,6,7).partition(_%2 == 0)
res1: (Array[Int], Array[Int]) = (Array(2, 4, 6),Array(1, 3, 5, 7)
package org.darion.yaphet.scala.examples.other
import scala.util.control.TailCalls._
import scala.annotation._
object Sum extends App {
def evenLength(xs: Seq[Int]): TailRec[Boolean] =
if (xs.isEmpty) done(true) else tailcall(oddLength(xs.tail))
def oddLength(xs: Seq[Int]): TailRec[Boolean] =
file
.map(line => (line.split(",")(0), 1))
.reduceByKey(_ + _)
.map(item => item.swap)
.sortByKey(false)
.map(item => item.swap)
.take(20)
.foreach(println)
@darionyaphet
darionyaphet / WordCountExample.scala
Created March 3, 2017 05:42
Simple WordCount SparkJobServer Example
package org.darion.yaphet.jobs
import com.typesafe.config.Config
import org.apache.spark.SparkContext
import spark.jobserver.{SparkJob, SparkJobInvalid, SparkJobValid, SparkJobValidation}
import scala.util.Try
/**
* Created by darionwang on 2017/3/3.
object MatchExample {
def main(args: Array[String]): Unit = {
val key = "3"
key match {
case "1" => println("1")
case "2" => println("2")
case _ => println("default")
}
}
val m = Map("k0"->"v0","k1"->"v1","k2"->"v2")
val n = m.map{case (k,v) => (v,k)}.toMap
println(n)
@darionyaphet
darionyaphet / Examples
Last active July 2, 2016 03:57
KryoExample
package org.darion.yaphet.kryo;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.Serializer;
import com.esotericsoftware.kryo.io.Input;
@darionyaphet
darionyaphet / Parquet ReadFileExample
Last active May 15, 2017 03:07
Parquet Example
package org.darion.yaphet.parquet;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.parquet.example.data.Group;
import org.apache.parquet.hadoop.ParquetReader;
import org.apache.parquet.hadoop.example.GroupReadSupport;
import java.io.IOException;