Skip to content

Instantly share code, notes, and snippets.

View jadlr's full-sized avatar

Jonas Adler jadlr

View GitHub Profile
@jadlr
jadlr / StateTest.scala
Created February 17, 2020 08:13
Experimenting with the state monad to have a context in https4
import cats.data._
import cats.effect.ExitCode
import cats.implicits._
import cats.~>
import org.http4s.dsl.Http4sDsl2
import org.http4s.server.blaze.BlazeServerBuilder
import org.http4s.{ Http, Request, Response }
import zio._
import zio.clock.Clock
import zio.interop.catz._
@jadlr
jadlr / CryptoApp.scala
Created June 26, 2020 13:51
Using AES256GCM to encrypt and decrypt a text
import cats.effect.{ ExitCode, IO, IOApp }
import tsec.cipher.symmetric.{ AAD, AADEncryptor, IvGen }
import tsec.cipher.symmetric.jca.{ AES256GCM, SecretKey }
import tsec.common._
import tsec.cipher.symmetric._
object CryptoApp extends IOApp {
private val aad: AAD = AAD("KnQCxy4rW4KuxMRcvkVvAs9KufF7XR4b".utf8Bytes)
@jadlr
jadlr / FS2TaskInterop.scala
Created October 2, 2020 12:36
Unexpected behaviour when using zio with fs2
import fs2.Stream
import zio.interop.catz._
import zio.{ Runtime, Task }
object FS2TaskInterop extends App {
val runtime = Runtime.default
val nonStream = Task(123).map(_ => BigDecimal("16:19:25.242056065Z"))
val stream = Stream.eval(nonStream)
@jadlr
jadlr / pushbutton.ex
Last active November 14, 2023 14:51
`gen_statem` example rewritten to elixir (http://erlang.org/doc/design_principles/statem.html)
defmodule PushButton do
@behaviour :gen_statem
@name :pushbutton_statem
# Client API
def start do
:gen_statem.start({:local,@name}, __MODULE__, [], [])
end