Skip to content

Instantly share code, notes, and snippets.

View loicdescotte's full-sized avatar

Loïc Descotte loicdescotte

View GitHub Profile
@loicdescotte
loicdescotte / zquery-caching.scala
Last active January 19, 2024 09:03
#ZIO Query #ZQuery caching
import zio._
import zio.query._
case class DbDepartment(id: Int, name: String)
case class DbEmployee(id: Int, name: String, departmentId: Int)
case class Employee(name: String, departmentName: String)
case class GetDepartement(id: Int) extends Request[Nothing, DbDepartment]
object ZqueryDemo extends ZIOAppDefault {
@loicdescotte
loicdescotte / ResultUsage.kt
Last active August 30, 2023 09:25
Kittinunf Result usage example
import com.github.kittinunf.result.*
open class AppError(message: String) : Throwable(message)
class ReadError(message: String) : AppError("Read error " + message)
class WriteError(message: String) : AppError("Write error " + message)
fun main(args: Array<String>) {
val result: Result<Unit, AppError> = readArgs(args).flatMap { writeToConsole(it) }
@loicdescotte
loicdescotte / genericws.scala
Last active January 19, 2024 09:00
Process web services and transform data with type classes #ZIO #Generic #Scala
object TestApp extends App :
import zio.json._
case class Input[A](hits: List[A])
trait Transformer[A,B] :
extension(a: A) def transform: B
object Input :
implicit def decoder[A: JsonDecoder]: JsonDecoder[Input[A]] = DeriveJsonDecoder.gen[Input[A]]
@loicdescotte
loicdescotte / extract_mbox_attachments.py
Created August 5, 2021 15:16 — forked from georgy7/extract_mbox_attachments.py
Extract attachments from mbox file.
# Modified.
# Original script source:
# http://blog.marcbelmont.com/2012/10/script-to-extract-email-attachments.html
# Usage:
# Run the script from a folder with file "all.mbox"
# Attachments will be extracted into subfolder "attachments"
# with prefix "n " where "n" is an order of attachment in mbox file.
# ---------------
@loicdescotte
loicdescotte / HelloZioHttp.scala
Last active March 18, 2021 21:28
ZIO HTTP basic example
import zio._
import zhttp.http._
import zhttp.http.HttpError.InternalServerError
import zhttp.service.Server
import zio.clock.Clock
import java.time.DateTimeException
object HelloWorld extends App {
@loicdescotte
loicdescotte / ZIOPreludeValidation.scala
Last active December 20, 2020 19:00
ZIO Prelude validation
case class Name(value: String)
case class Age(value: Int)
case class Person(name: Name, age: Age)
trait Error
case object ParsingError extends Error
case class DataValidationError(message:String) extends Error
import zio._
import zio.prelude._
@loicdescotte
loicdescotte / node_redis.md
Last active September 8, 2020 09:45 — forked from leommoore/node_redis.md
Node - Redis

Node - Redis

Redis is a simple key, value pair database. The common commands include:

Data StructureCommands
StringsSET, GET, DEL, APPEND, DECR, INCR...
HashsHSET, HGET, HDEL, HGETALL...
ListsLPUSH, LREM, LTRIM, RPOP, LINSERT...
SetsSADD, SREM, SMOVE, SMEMBERS...
const config = {
typeDirs: [
{ type: "pdf", directory: "documents" },
{ type: "png", directory: "images" },
{ type: "mp3", directory: "music" },
],
};
type Config = typeof config;
type TypeDirs = Config["typeDirs"];
@loicdescotte
loicdescotte / ZioQueuePullPush.scala
Last active February 20, 2020 10:20
ZIO queue example
import zio._
import zio.console._
import zio.stream._
import zio.duration._
object ZioQueuePullPush extends zio.App {
// c.f. ZIO type aliases https://zio.dev/docs/overview/overview_index#type-aliases
val result: URIO[Clock with Console, Unit] = for {
queue <- Queue.bounded[Int](100)
@loicdescotte
loicdescotte / RT.scala
Last active November 20, 2019 12:54
Referential Transparency example with Try and IO
import scala.util._
import cats.effect._
//See https://impurepics.com/posts/2018-04-01-referential-transparency.html for RT definition
println("-----------Try--------------")
println("-----------This will print only 1 line : --------------")
val t = Try(println(1+1))
for {