Skip to content

Instantly share code, notes, and snippets.

View stsatlantis's full-sized avatar

Barnabás Oláh stsatlantis

View GitHub Profile

Keybase proof

I hereby claim:

  • I am stsatlantis on github.
  • I am stsatlantis (https://keybase.io/stsatlantis) on keybase.
  • I have a public key ASCCQrfKvYjs38lLVT053MrbUhAJCyTsDhr6ahsBiRt6aAo

To claim this, I am signing this object:

@stsatlantis
stsatlantis / AssistEvent.json
Last active June 2, 2021 07:41
Optics at Nicecactus
{
"user":"szeretemacsokit",
"sessionId":"8416525d747a48efa744f0c3ce753d76",
"game":{
"id":5426,
"name": "League of Legends"
},
"event":{
"name":"assist",
"data":{
@stsatlantis
stsatlantis / EncryptionService.scala
Last active May 7, 2019 12:54
Scala-Shapeless POC of tagged type to modify only marked/tagged values
package util
import eu.timepit.refined.api.RefType
import io.circe.Encoder
import io.circe.refined.refinedEncoder
import shapeless._
import shapeless.ops.hlist.Mapper
import shapeless.tag.@@
trait Sensitive
@stsatlantis
stsatlantis / ParentEncoder.scala
Created April 12, 2019 12:03
Circe Parent encoder
import shapeless.HList
trait ParentEncoder[-T] {
type Repr <: HList
def to(t: T): Repr
}
object ParentEncoder {
import io.circe.Encoder
import io.circe.refined.refinedEncoder
import shapeless._
import shapeless.ops.coproduct.{ Mapper => CoproductMapper }
import shapeless.ops.hlist.{ Mapper => HListMapper }
import shapeless.tag.@@
trait Sensitive
object Sensitive {
@stsatlantis
stsatlantis / different field values.scala
Last active June 24, 2018 14:27
Lists the field names where the values are different
object filterPoly extends Poly1 {
implicit def filterNotEqualValues[A <: Symbol, B]: Case.Aux[(A, (B, B)), List[String]] =
at[(A, (B, B))] { case (k, (v1, v2)) => if (v1 == v2) List.empty[String] else List(k.name) }
}
object foldListPoly extends Poly2 {
implicit def foldToList[T](implicit st: filterPoly.Case.Aux[T, List[String]]): Case.Aux[T, List[String], List[String]] =
at[T, List[String]] { (t, acc) => st(t) ::: acc }
}
@stsatlantis
stsatlantis / aoc2017D2.scala
Last active December 2, 2017 22:13
Advent of Code 2017 - Day2
def checkCorruptChecksum(_source: List[List[Int]]) = {
_source.map(
_.map(x => (x, x))
.reduceLeft((x, y) => (x._1 min y._1, x._2 max y._2)
)
).map { case (a, b) => b - a }
.sum
}
def advancedCheckCorruptChecksum(_source: List[List[Int]]) = {
@stsatlantis
stsatlantis / aoc2017D1.scala
Last active December 2, 2017 11:16
Advent of Code 2017 - Day1
def simpleCaptcha(_source: String) = {
(_source + _source.head).map(_.asDigit).sliding(2).collect { case Seq(a, b) if a == b => a }.sum
}
def advancedCaptcha(_source: String) = {
val size = _source.length / 2
val (firstHalf, lastHalf) = _source.map(_.asDigit).splitAt(size)
firstHalf.zip(lastHalf).collect { case (e1, e2) if e1 == e2 => e1 }.sum * 2
}
@stsatlantis
stsatlantis / FizzBuzz.scala
Last active February 2, 2017 09:45
FizzBuzz with extractors and stackable traits
trait Devideable {
def isDevidable(i: Int, d: Int, s: String) = if(i % d == 0) Some(s) else None
}
trait SzogletesDevidable extends Devideable {
abstract override def isDevidable(i: Int, d: Int, s: String): Option[String] = super.isDevidable(i, d, s"[$s]")
}
trait KerekDevidable extends Devideable {
abstract override def isDevidable(i: Int, d: Int, s: String): Option[String] = super.isDevidable(i, d, s"($s)")
@stsatlantis
stsatlantis / countSumOfTwoRepresentations2.scala
Created September 25, 2016 22:54
Given integers n, l and r, find the number of ways to represent n as a sum of two integers A and B such that l ≤ A ≤ B ≤ r.
def countSumOfTwoRepresentations2(n: Int, l: Int, r: Int): Int = {
if(l > n/2) 0 else math.min(n/2 - l, r - n/2) + (if(n%2 == 1) 0 else 1)
}