Skip to content

Instantly share code, notes, and snippets.

View domdorn's full-sized avatar

Dominik Dorn domdorn

View GitHub Profile
@domdorn
domdorn / VavrToScalaConverters.scala
Created September 15, 2020 16:24
Vavr To Scala Converters
import cats.data.EitherT
import io.vavr.concurrent.{Future => VavrFuture}
import scala.concurrent.{ExecutionContext, Future, Promise}
object VavrToScalaConverters {
implicit class VavrFutureToScala[T](future: VavrFuture[T]) {
def asScala: Future[T] = {
@domdorn
domdorn / Animal.scala
Created September 18, 2020 12:54
Play Json Inheritance
import play.api.libs.json._
sealed trait Animal {
val `type`: String
}
case class Cat(name: String) extends Animal {
override val `type`: String = "cat"
}
@domdorn
domdorn / HMacSha256.scala
Created November 21, 2020 16:43
Create a HMac Sha256 hash from a given string
object HMAC {
def generateHMAC(sharedSecret: String, input: String): String = {
val secret = new SecretKeySpec(sharedSecret.getBytes, "HmacSHA256") //Crypto Funs : 'SHA256' , 'HmacSHA1'
val mac = Mac.getInstance("HmacSHA256")
mac.init(secret)
val hashString: Array[Byte] = mac.doFinal(input.getBytes)
// this makes sure that the string is 64chars long and gets padded with 0 if its shorter
String.format("%064x", new BigInteger(1, hashString))
}
@domdorn
domdorn / sample.json
Created August 30, 2021 20:09
JQ flatten / flatMap nested structure
{
"correlationId": "83937bab-e23c-465f-9708-5c0a0030cc6e",
"items": [
{
"jobId": "7601ebfa-fb17-41ad-815e-a7b6339952df",
"status": "Waiting",
"variants": [
{
"variantId": 1,
"status": "Waiting",
Interface Settings
{
"locale": "en-US"
}
Graphics Settings
{
"qualitySettings": [
{
"enabled": true,
"isAdaptive": true,