Skip to content

Instantly share code, notes, and snippets.

View guersam's full-sized avatar

Jisoo Park guersam

  • Seoul, South Korea
View GitHub Profile
@guersam
guersam / check-domain.sc
Created June 20, 2018 04:54
Check domain name availability with whois and notify via slack
#!/usr/bin/env amm
import $ivy.`com.github.gilbertw1::slack-scala-client:0.2.3`
import slack.api.BlockingSlackApiClient
import akka.actor.ActorSystem
import scala.util.Try
def sendSlackNotification(msg: String)(implicit sys: ActorSystem): Unit = {
val token = "<token>" // TODO parameterize
@guersam
guersam / App.scala
Created March 18, 2018 08:44 — forked from notxcain/App.scala
Onion Architecture using Finally Tagless and Liberator
import cats.data.{ EitherT, State }
import cats.implicits._
import cats.{ Monad, ~> }
import io.aecor.liberator.macros.free
import io.aecor.liberator.syntax._
import io.aecor.liberator.{ ProductKK, Term }
@free
trait Api[F[_]] {
def doThing(aThing: String, params: Map[String, String]): F[Either[String, String]]
@guersam
guersam / fs2Cp949Decoder.scala
Last active August 9, 2017 12:06
fs2 cp949 decoder
import java.nio.charset.Charset
import fs2.{Chunk, Pipe, Pull, Pure, Stream}
object Fs2Util {
val cp949Charset: Charset = Charset.forName("cp949")
def cp949Decode[F[_]]: Pipe[F, Byte, String] =
_.chunks.through(cp949DecodeC)
@guersam
guersam / _Main.scala
Created April 27, 2017 08:46
cross-libraries optimization in Scala 2.12
object Main {
val xs = (1 to 10).toList
def simple(): List[Int] =
xs.map { i =>
i + 1
}
}
@guersam
guersam / desciption.md
Last active July 22, 2016 06:16
Monix Task.gatherUnordered benchmark (quick)

Quick benchmark for monix/monix#188

Environment

  • Intel® Core™ i5-4670 CPU @ 3.40GHz × 4
  • 32GB memory
  • Ubuntu 16.04.1 LTS 64-bit
  • Oracle JDK 1.8.0_91, VM 25.91-b14
  • Very small iteration size (-f1 -t4 -i 5 -wi 5) due to a error in default settings (not caused by gatherUnordered though)
@guersam
guersam / LogFileReader.scala
Last active June 15, 2016 15:02
Java nio live file reader in akka stream
import akka.streams.scaladsl._
import akka.util.ByteString
import java.nio.ByteBuffer
import java.nio.file.Path
import java.nio.channels.FileChannel
def logFileReader(path: Path, bufferSize: Int = 4096)
Source.unfoldResource[ByteString, (ByteBuffer, FileChannel)](
() => (ByteBuffer.allocateDirect(bufferSize), FileChannel.open(path, StandardOpenOption.READ)),
{
@guersam
guersam / syb.scala
Created April 28, 2016 08:21
스칼라 우왕
import shapeless._
// Shapeless를 이용한 Generic Programming
// https://github.com/milessabin/shapeless/blob/shapeless-2.3.0/examples/src/main/scala/shapeless/examples/sybclass.scala
// 재귀적으로 정의된 이진 트리
sealed trait Tree[T]
case class Leaf[T](t: T) extends Tree[T]
case class Node[T](left: Tree[T], right: Tree[T]) extends Tree[T]
@guersam
guersam / ColumnReader.scala
Created March 14, 2016 04:06
Naive, generic CSV reader
import cats.data.Xor
import cats.syntax.xor._
import elsresearch.common.util.Read
import scala.annotation.implicitNotFound
@implicitNotFound("Cannot find implicit ColumnReader for ${A}")
trait ColumnReader[A] {
def read(s: String): Throwable Xor A
}
@guersam
guersam / Tablifier.scala
Last active July 2, 2016 10:49
Generate a bidimensional table from a sequence of arbitrary case class
import cats.Show
import shapeless._
import shapeless.ops.record._
import shapeless.ops.hlist._
import scala.collection.immutable
trait Tablifier[A] {
def head: List[String]
@guersam
guersam / foldLeft.scala
Created January 16, 2016 09:16
foldLeft
def flatMap[A](list: List[A], f: A => List[A]) =
list.foldLeft(List.empty[A]) { (acc, x) => acc ++ f(x) }
assert(
flatMap(1 :: 2 :: 3 :: Nil, (x: Int) => x :: x :: Nil) ==
List(1, 1, 2, 2, 3, 3)
)
def max[A: Ordering](list: List[A]): Option[A] =
list match {