Skip to content

Instantly share code, notes, and snippets.

Avatar

Gavin Bisesi Daenyth

View GitHub Profile
View resetTimeout.scala
/** Execute `onTimeout` every time the stream goes `timeout` duration with no
* elements
*/
def resetTimeout[F[_]: Temporal, A](
timeout: FiniteDuration,
onTimeout: F[Unit]
): fs2.Pipe[F, A, A] = {
def go(timedPull: Pull.Timed[F, A]): Pull[F, A, Unit] =
timedPull.timeout(timeout) >>
timedPull.uncons.flatMap {
@Daenyth
Daenyth / doobie.scala
Created Jun 9, 2022
Doobie code structure example
View doobie.scala
package myapp.users
// This is the shape of code I've found to work best for doobie in a cats-effect application using capability traits
trait UserOnboarding[F[_]] {
// The api expresses the business-level workflow, not the implementation of inserting to a database
// Keep the interface expressing the high level concern; database is only *one* implementation and it can change later
def registerUser(userInfo: UserInfo): F[UserId]
}
View RawSqlInstances.scala
import cats.{Contravariant, Functor, Semigroupal}
import slick.jdbc.{
GetResult,
PositionedParameters,
PositionedResult,
SetParameter
}
trait RawSqlInstances {
@Daenyth
Daenyth / ssh-config
Last active Apr 21, 2022
Use a different ssh key for a specific github organization
View ssh-config
# ~/.ssh/config
Match host github.com exec "[[ $(git remote get-url origin | sed 's/^.*://' | sed 's/\/.*//') = TheGithubOrganization ]]"
# Don't forget to ssh-add this in addition to other keys, or git will pick one that's already in the agent first
IdentityFile ~/.ssh/specific_rsa
@Daenyth
Daenyth / munit-cats-laws.scala
Created Mar 1, 2022
munit-discipline cats law testing example
View munit-cats-laws.scala
import cats.kernel.laws.discipline.SemigroupTests
import cats.syntax.all._
import munit.DisciplineSuite
import org.scalacheck.Arbitrary
case class MyInt(value: Int)
object MyInt {
implicit val semigroupMyInt: Semigroup[MyInt] = Semigroup.instance((x1, x2) => MyInt(x1.value + x2.value))
}
@Daenyth
Daenyth / toki-pona-words.txt
Last active Jan 15, 2022
lines in /usr/share/dict/words that match toki pona phonotactics
View toki-pona-words.txt
a
ajaja
ajowan
aka
akala
akali
akan
akasa
ake
akeki
@Daenyth
Daenyth / Prelude.scala
Created Jan 14, 2022
cats-effect prelude
View Prelude.scala
package com.myproject.prelude
import cats.syntax.{AllSyntaxBinCompat => CatsSyntax}
import cats.effect.syntax.{AllSyntax => CESyntax}
import cats.effect.instances.{AllInstances => CEInstances}
/** Custom prelude for importing with -Yimport
*
* This means we never need to import cats syntax or stream explicitly
*/
@Daenyth
Daenyth / VulcanHelper.scala
Created Nov 22, 2021
fs2-kafka vulcan => avro Serde helper
View VulcanHelper.scala
import cats.effect.Sync
import cats.syntax.all._
import cats.effect.std.Dispatcher
import fs2.kafka.vulcan.{AvroSettings, avroDeserializer, avroSerializer}
import fs2.kafka.{Deserializer, Headers, Serializer}
import org.apache.kafka.common.serialization.{Serde, Serdes}
import vulcan.Codec
// Credit to Fede Fernández for the original CE2 version
// Note: this isn't under an open source license; it's for educational purposes only
@Daenyth
Daenyth / keybase.md
Last active Aug 25, 2021
keybase.md
View keybase.md

Keybase proof

I hereby claim:

  • I am daenyth on github.
  • I am daenyth (https://keybase.io/daenyth) on keybase.
  • I have a public key ASCSw0W8Kr-JKKaGIAxIIOqY3h1MuLZzNqx2epHUbiLD4Qo

To claim this, I am signing this object:

View monad-li-seme.md

"Monad" is a word that describes a set of behaviors

In scala, we use the Monad[Foo] typeclass from cats to define instances of this behavior.

The essence of its behavior is the ability to describe a series of computations, where one computation depends on the result of the computation that came before it.

For example, Monad[Option] shows that the Option[A] data type can be used to describe computations of A which may result in no value.