Skip to content

Instantly share code, notes, and snippets.

View chuwy's full-sized avatar

Anton Parkhomenko chuwy

View GitHub Profile
@chuwy
chuwy / AllSubtypesOf.scala
Created April 1, 2024 06:59
A Scala 3 match type that checks that all elements of a tuple match a certain (sub)type
import scala.compiletime.ops.boolean.&&
type AllSubtypesOfMatch[T <: Tuple, Super] <: Boolean = T match
case EmptyTuple =>
true
case h *: t =>
h match
case Super => AllSubtypesOfMatch[t, Super]
type AllSubtypesOf[T <: Tuple, Super] = AllSubtypesOfMatch[T, Super] =:= true
@chuwy
chuwy / README.md
Created August 12, 2023 11:36 — forked from runiq/README.md
Neovim throttle & debounce

What are these?

Functions that allow you to call a function not more than once in a given timeframe.

Throttling on the leading edge

This can be illustrated with timing diagrams. In the following diagrams, f designates call to the throttled function, t is the period where the timer is running, and x shows you the actual execution point of the throttled function.

f 1  2  3  4  5  6
@chuwy
chuwy / ConfigWithComments.scala
Created August 11, 2023 10:06 — forked from DiggesT/Api.scala
Scala code research
def loadFromPath[F[_]: Sync](path: JPath): F[Config] =
val source = ConfigSource.default(ConfigSource.file(path)).withFallback(ConfigSource.default)
loadF[F, Config](source)
def load(args: List[String]): IO[Either[Help, (SubCommand, Option[Config])]] = //input array: List[String], output: why IO
command.parse(args) match // how it matching string with help/commands?
case Left(help) => IO.pure(help.asLeft) //help command
case Right(cli) => //other commands
cli match //match with SubCommand
case SubCommand.Run(configPath, _) => //Run command
type SpanF[A, C] <: Tuple = (A, C) match
case ((as, bs), (a, b)) => (as *: a, bs *: b)
type Span[A <: Tuple] = Fold[A, (EmptyTuple, EmptyTuple), SpanF]
def span[T <: Tuple](t: Tuple): Option[Span[T]] =
def go[TT <: Tuple, A <: Tuple, B <: Tuple](remaining: TT, as: A, bs: B): Option[(A, B)] =
remaining match
case EmptyTuple => Some((as, bs))
case (a, b) *: tt => go(tt, a *: as, b *: bs).asInstanceOf[Option[(A, B)]]
@chuwy
chuwy / Table.scala
Last active August 22, 2023 19:54
Scala macro for building type-safe SQL Fragments
import java.time.LocalDateTime
import scala.quoted.*
import scala.deriving.Mirror
import quotidian.*
import quotidian.syntax.*
import io.github.iltotore.iron.*
@chuwy
chuwy / run_shredder.py
Created January 10, 2022 15:26
No Dataflow Runner
import boto3
connection = boto3.client(
'emr',
region_name='eu-central-1',
aws_access_key_id=ACCESS_KEY,
aws_secret_access_key=SECRET_KEY,
)
cluster_id = connection.run_job_flow(
def input[F[_]: Timer] =
(Stream(1, 2, -3, 4, -5) ++
Stream.sleep_(1.second) ++
Stream(4, 3, -1, -2, 1) ++
Stream.sleep_(1.second) ++
Stream(0, 2, -5) ++
Stream.sleep_(1.second) ++
Stream(-6, 1, 2, 0, -1, -4, 2, 9)
).covary[F].map(i => if (i % 2 == 0) i.asRight else (i.toString + "b").asLeft)
#!/bin/sh
set -e
if [ -z ${TRAVIS_BUILD_DIR+x} ]; then
echo "TRAVIS_BUILD_DIR is unset";
exit 1
fi
IGLUCTL_ZIP="igluctl_0.6.0.zip"
@chuwy
chuwy / README.md
Last active June 17, 2020 15:28
Second version of Iglu root metaschema

Files

  • metaschema.json - new root metaschema to put in $schema properties
  • example-meta.json - example registry metaschema, i.e. one hosted on Acme Ltd. (Mixpanel, Iteratively, Snowplow) Iglu registry and thus specific to all its schemas. Can have 2-0-0 or 1-0-0 root metaschema
  • example-schema.json - plain (non-meta, usual) schema hosting on Acme Ltd. registry and containing metadata described by above metaschema

Changes

Compared to 1-0-0

@chuwy
chuwy / 0001-Unify.patch
Created June 13, 2020 11:06
Combine enrich submodules into a single SBT project
From fe136f1c24a2d3510f654348fa4522f48cdc6efb Mon Sep 17 00:00:00 2001
From: Anton Parkhomenko <mailbox@chuwy.me>
Date: Sat, 13 Jun 2020 14:52:47 +0700
Subject: [PATCH] Unify
---
beam.sbt | 88 ---------
build.sbt | 172 ++++++++++++++++++
common.sbt | 68 -------
...mmonSettings.scala => BuildSettings.scala} | 68 ++++++-