Skip to content

Instantly share code, notes, and snippets.

View guersam's full-sized avatar

Jisoo Park guersam

  • Seoul, South Korea
View GitHub Profile
@dacr
dacr / index.md
Last active April 20, 2024 13:35
David's programming examples knowledge base / published by https://github.com/dacr/code-examples-manager #fecafeca-feca-feca-feca-fecafecafeca/211658a4b67b6bf297ce7b4351a7080d22b50ad3

David's programming examples knowledge base

akka-pekko

@seoh
seoh / EitherT example.ipynb
Created March 4, 2019 13:32
EitherT example
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import cats.data.Kleisli
import cats.effect.{ Concurrent, Sync }
import cats.effect.concurrent.MVar
import cats.implicits._
import cats.{ Applicative, Functor, Monad }
// Let's start with our dsl
// First we need to interact with a console
trait Console[F[_]] {
@seratch
seratch / H2SampleSpec.scala
Last active December 25, 2018 12:01
r2dbc sample in Scala
import org.scalatest._
class H2Spec extends FlatSpec with Matchers {
case class Sample(id: Long, name: Option[String])
"H2 connections" should "work" in {
import io.r2dbc.h2.{ H2ConnectionConfiguration, H2ConnectionFactory }
import io.r2dbc.client.R2dbc
@e8kor
e8kor / AkkaStructuredLogging.scala
Last active February 22, 2018 05:15
Structured logging using akka, slf4j, Logstash Logback Json Encoder
// Snippet
import akka.event.LogMarker
import akka.event.slf4j.Slf4jLogMarker
import net.logstash.logback.marker.RawJsonAppendingMarker
import io.circe._
import io.circe.generic.extras._
import io.circe.syntax._
implicit private val config: Configuration = Configuration.default.withSnakeCaseMemberNames // ELK has good support for snake case json convention
@kryptt
kryptt / blocks.scala
Last active November 28, 2018 03:09
Model/View/Update using FS2
package br
package blocks
import scala.concurrent.{ExecutionContext, Future}
import fs2.{Strategy, Stream, Task}
import fs2.async.mutable.Topic
abstract class Piece[Model, View]
(events: Stream[Task, Any])(implicit ec: ExecutionContext) {
@notxcain
notxcain / App.scala
Last active September 21, 2018 13:54
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]]

Revisiting Tagless Final Interpreters

Tageless Final interpreters are an alternative to the traditional Algebraic Data Type (and generalized ADT) based implementation of the interpreter pattern. This document presents the Tageless Final approach with Scala, and shows how Dotty with it's recently added implicits functions makes the approach even more appealing. All examples are direct translations of their Haskell version presented in the Typed Tagless Final Interpreters: Lecture Notes (section 2).

The interpreter pattern has recently received a lot of attention in the Scala community. A lot of efforts have been invested in trying to address the biggest shortcomings of ADT/GADT based solutions: extensibility. One can first look at cats' Inject typeclass for an implementation of [Data Type à la Carte](http://www.cs.ru.nl/~W.Swierstra/Publications/DataTypesA

@bmc
bmc / StaticFile.scala
Last active September 3, 2021 20:08
I needed code to serve static files from an Akka HTTP server. I wanted to use fs2 to read the static file. Michael Pilquist recommended using streamz to convert from an fs2 Task to an Akka Source. This is what I came up with. (It does actually work.)
object StaticFile {
// Various necessary imports. Notes:
//
// 1. fs2 is necessary. See https://github.com/functional-streams-for-scala/fs2
// 2. streamz is necessary. See https://github.com/krasserm/streamz
// 3. Apache Tika is used to infer MIME types from file names, because it's more reliable and
// fully-featured than using java.nio.file.Files.probeContentType().
//
// If using SBT, you'll want these library dependencies and resolvers:

Getting Started in Scala

This is my attempt to give Scala newcomers a quick-and-easy rundown to the prerequisite steps they need to a) try Scala, and b) get a standard project up and running on their machine. I'm not going to talk about the language at all; there are plenty of better resources a google search away. This is just focused on the prerequisite tooling and machine setup. I will not be assuming you have any background in JVM languages. So if you're coming from Python, Ruby, JavaScript, Haskell, or anywhere…  I hope to present the information you need without assuming anything.

Disclaimer It has been over a decade since I was new to Scala, and when I was new to Scala, I was coming from a Java and Ruby background. This has probably caused me to unknowingly make some assumptions. Please feel free to call me out in comments/tweets!

One assumption I'm knowingly making is that you're on a Unix-like platform. Sorry, Windows users.

Getting the JVM