Skip to content

Instantly share code, notes, and snippets.

View chuwy's full-sized avatar

Anton Parkhomenko chuwy

View GitHub Profile
@chuwy
chuwy / extract.sh
Created June 13, 2020 11:04
Extract enrich repositories from snowplow/snowplow monorepo
#!/bin/sh
cp -R ../snowplow .
cd snowplow/
git filter-repo \
--path 3-enrich/scala-common-enrich \
--path 3-enrich/spark-enrich \
--path 3-enrich/beam-enrich \
@chuwy
chuwy / Data.hs
Last active March 16, 2020 11:44
data Option a where
Some : a -> Option a
None : Option a
instance Functor
fmap : (a -> b) -> Option a -> Option b
fmap f (Some a) = Some (f a)
fmap _ None = None
deriving instance Show given Show a
trait Mutability[F[_]] {
def init[A](a: A): F[Mutability.Var[F, A]]
}
object Mutability {
trait Var[F[_], A] {
def get: F[A]
def put(a: A): F[Unit]
}
/** Always positive integer, nobody can do `new PositiveInt(-3)` */
class PositiveInt private(value: Int) extends AnyVal
/** Set of constructors for PositiveInt */
object PositiveInt {
/** The only proper constructor. Everything else is workaround */
def fromInt(int: Int): Option[PositiveInt] = if (int > 0) Some(new PositiveInt(int)) else None
/**
* This is a workaround and must be called ONLY when caller is sure the `int` is positive
object WeirdChunks {
import cats.effect.concurrent.Ref
import fs2.concurrent.Queue
import scala.concurrent.duration._
implicit val t = IO.timer(scala.concurrent.ExecutionContext.global)
implicit val cs = IO.contextShift(scala.concurrent.ExecutionContext.global)
def init: IO[(Ref[IO, Int], Queue[IO, String])] =
@chuwy
chuwy / iglu-violation.json
Created March 18, 2019 13:20
Iglu Client error format
{
"anyOf": [
{
"description": "Resolution error - schema could not be found on specified repositories, defined by ResolutionError ADT in Iglu Client",
"properties": {
"repositories": {
"description": "Defined by LookupHistory ADT in Iglu Client",
"properties": {
"name": {
"type": "string",
@chuwy
chuwy / BreakReferentialTransparency.scala
Created March 1, 2018 11:48
Interleaving lazy and eager evaluation to break referential transparency
import cats._
import cats.implicits._
import cats.effect._
import cats.effect.implicits._
object Db {
private val cache = collection.mutable.Map.empty[String, String]
def expensiveIO(input: String): IO[String] =
IO { Thread.sleep(1000); println("Executed expensive action"); input ++ input }
@chuwy
chuwy / diff_hosted_repo.txt
Created February 12, 2018 09:01
diff -r hosted repo
Only in hosted: com.admo-analytics
Only in hosted: com.adxtracking
Only in hosted: com.angelrush
Only in hosted: com.calltracks
Only in hosted: com.certivox
Only in repo: com.convertro
Only in hosted: com.duproprio
Only in hosted: com.duproprio_comfree
Only in hosted: com.findly
Only in hosted: com.finerylondon

Keybase proof

I hereby claim:

  • I am chuwy on github.
  • I am chuwy (https://keybase.io/chuwy) on keybase.
  • I have a public key ASC4yihj3aD9BK2glw6wm-sUNqbq9Qj8uWYJMcb3KhGjrQo

To claim this, I am signing this object:

@chuwy
chuwy / Validator.scala
Created February 23, 2017 12:57
Json Schema Validator
package jsonschemavalidator
import scala.language.implicitConversions
import cats.syntax.either._
import cats.syntax.semigroup._
import cats.syntax.semigroupk._
import cats.syntax.validated._
import cats.data.ValidatedNel
import cats.instances.all._