Skip to content

Instantly share code, notes, and snippets.

View ferhtaydn's full-sized avatar

Ferhat Aydın ferhtaydn

View GitHub Profile
@ferhtaydn
ferhtaydn / nel_serialize.md
Last active July 25, 2022 14:20
How to serialize a model class has NonEmptyList attributes like normal List

How to use NonEmptyList in a model class

Let's say you are implementing an API and decide to return a base error response in common error situations such as BadRequest, NotFound etc.

final case class Error(code: String, description: String)

If you are returning an error response, your assumption would probably be that such responses should contain at least one error.

@ferhtaydn
ferhtaydn / NELJson.scala
Last active October 2, 2017 10:58
How to serialize NonEmptyList in model like normal List
import cats.Applicative
import cats.data.{NonEmptyList => NEL}
import cats.syntax.traverse._
import play.api.libs.json._
final case class Error(code: String, description: String)
object Error {
enum ListEnum[+A] {
case Cons[+A](h: A, t: ListEnum[A]) extends ListEnum[A]
case Empty extends ListEnum[Nothing]
}
val emptyList = ListEnum.Empty
// val res4: ListEnum[Nothing] = Empty
val list = ListEnum.Cons(1, ListEnum.Cons(2, ListEnum.Cons(3, ListEnum.Empty)))
// val res5: ListEnum[Int] = Cons(1,Cons(2,Cons(3,Empty)))
@ferhtaydn
ferhtaydn / forksync.sh
Last active June 5, 2017 08:19
sync a forked repo
git remote -v
git remote add upstream https://github.com/scala/scala.github.com.git
git fetch upstream
git checkout master
git merge (or rebase) upstream/master
@ferhtaydn
ferhtaydn / kafka_cassandra_cluster.md
Created November 18, 2016 14:22
Confluent Kafka Platform and Cassandra Multi Node Deployment Guide

Step by step guide for multi node Confluent Kafka Platform and Cassandra cluster;

It is a multi node deployment of https://github.com/ferhtaydn/sack

Assume that, we have five Ubuntu 14.04 nodes. Their IPs are as follows;

  • 12.0.5.4
  • 12.0.5.5
  • 12.0.5.6
  • 12.0.1.170
@ferhtaydn
ferhtaydn / cakescip.md
Created November 12, 2016 22:53
cake scip exercises

Normal evaluation (lazy evaluation) model would not evaluate the operands until their values were needed. This alternative fully expand and then reduce evaluation method is known as normal-order evaluation, in contrast to the evaluate the arguments and then apply method that the interpreter actually uses, which is called applicative-order evaluation.

Scheme is an applicative-order language, namely, that all the arguments to Scheme procedures are evaluated when the procedure is applied. In contrast, normal-order languages delay evaluation of procedure arguments until the actual argument values are needed. Delaying evaluation of procedure arguments until the last possible moment (e.g., until they are required by a primitive operation) is called lazy evaluation.

####Exercise 1.5: If the interpreter uses applicative-order evaluation, the (test 0 (p)) never terminates since the argument (p) is tried to be evaluated first. However, in normal-order evaluation, the operands are not evaluated until their v

@ferhtaydn
ferhtaydn / StringParser.scala
Created April 21, 2016 07:50
simple string parser with typeclass approach
import scala.util.Try
case class Model(time: Long, value: Double)
trait StringParser[A] {
def apply(s: String): Option[A]
}
object StringParser {
object Solution {
import scala.io.Source
def chain(y: Int, c: Int): Int = {
if (y == 1) c
else if (y % 2 == 0) chain(y / 2, c + 1)
else chain(3 * y + 1, c + 1)