Skip to content

Instantly share code, notes, and snippets.

View debop's full-sized avatar

Sunghyouk Bae debop

View GitHub Profile
@debop
debop / AvroSerializer.kt
Created February 27, 2017 14:31
AvroSerializer
open class AvroSerializer @JvmOverloads constructor(val codecFactory: CodecFactory = CodecFactory.snappyCodec()) {
/**
* Avro instance 를 직렬화하여 byte array 로 변환합니다.
*/
fun <T : SpecificRecordBase> writeAvroObject(graph: T?): ByteArray {
return graph?.let {
val sdw = SpecificDatumWriter<T>(graph.schema)
val dfw = DataFileWriter(sdw).setCodec(codecFactory)
@debop
debop / package.scala
Created February 5, 2017 09:34
Port apply, let method in Kotlin Standard library to Scala
/** 모든 수형에 대해 builder 패턴을 제공하기 위해 사용 : Kotlin 의 apply method 와 같다 */
implicit class AnyRefExtension[T <: AnyRef](underlying: T) {
def build(builder: T => T): T = builder(underlying)
def let(procedure: T => Unit): Unit = procedure(underlying)
}
/** 모든 Option 에 대해 Kotlin 의 let 과 같은 기능을 제공한다 */
implicit class OptionExteions[T](underlying: Option[T]) {
def let(procedure: T => Unit): Unit = underlying foreach { procedure }
}
@debop
debop / Products.kt
Created September 4, 2016 16:18
Product in Kotlin ported from Scala
interface Product {
val productArity: Int
fun elements(index: Int): Any?
fun toList(): List<*> = productIterator().toList()
fun productIterator(): Iterator<*> = object : Iterator<Any?> {
var currIndex = 0
override fun hasNext(): Boolean = currIndex < productArity
override fun next(): Any? = elements(currIndex++)
@debop
debop / Tuples.kt
Created September 4, 2016 16:17
Tuples in Kotlin ported from Scala
data class Tuple1<out T1 : Any>(override val first: T1) : Product1<T1>, Serializable {
override fun toString(): String {
return "($first)"
}
}
data class Tuple2<out T1 : Any, out T2 : Any>(
override val first: T1,
override val second: T2) : Product2<T1, T2>, Serializable {
@debop
debop / ParallelIterates.kt
Created July 26, 2016 09:09
Kotlin 과 EclipseCollection 으로 구현한 병렬 처리 루틴
/*
* Copyright (c) 2016. Sunghyouk Bae <sunghyouk.bae@gmail.com>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@debop
debop / package.scala
Created January 18, 2016 06:32
Scala Implicit methods for Java 8 Functions
package kesti4j
import java.util.function._
/**
* @author sunghyouk.bae@gmail.com
*/
package object core {
object Implicits {
@debop
debop / GsCollectionsFunSuite.scala
Created January 17, 2016 15:26
using gs-collections with scala lambda expression.
class GsCollectionsFunSuite extends AbstractCoreFunSuite {
test("FastList collection") {
val fastlist = FastList.newListWith[Int](1, 2, 3, 4, 5)
val collected: FastList[Int] = fastlist.collect(new Function[Int, Int] {
override def valueOf(obj: Int): Int = obj * obj
})
collected should contain allOf(1, 4, 9, 16, 25)
@debop
debop / GsCollections.scala
Created January 17, 2016 15:19
scala implicit methods for gs-collection interface function
package kesti4s.core.collections
import com.gs.collections.api.block.function._
import com.gs.collections.api.block.function.primitive._
import com.gs.collections.api.block.predicate._
import com.gs.collections.api.block.predicate.primitive._
import com.gs.collections.api.block.procedure._
import com.gs.collections.api.block.procedure.primitive._
/**
package kr.hconnect.data.model;
import com.google.common.base.Objects;
import kr.hconnect.core.tools.HashTool;
import lombok.Getter;
import lombok.Setter;
/**
* Hibernate, JPA 의 모든 엔티티의 기본 클래스입니다.
*
package kr.hconnect.data.model;
import com.google.common.base.Objects;
import kr.hconnect.core.tools.HashTool;
import lombok.Getter;
import lombok.Setter;
/**
* Hibernate, JPA 의 모든 엔티티의 기본 클래스입니다.
*