Skip to content

Instantly share code, notes, and snippets.

View TheDIM47's full-sized avatar

Dmitry Koudryavtsev TheDIM47

View GitHub Profile
import scala.math.Ordering.Implicits.infixOrderingOps
/** simple interval [min, max) (or >= min if max is empty) */
final class Interval[A](val min: A, val max: Option[A])(implicit num: Numeric[A]) extends Serializable {
/** if max nonEmpty, then max > min */
require(testRightBound(max, min))
def in(value: A): Boolean =
value >= min && testRightBound(max, value)
@TheDIM47
TheDIM47 / Slf4jLogger.scala
Created March 25, 2022 17:46
scala: slf4j logger for doobie
package util
import doobie.LogHandler
import doobie.util.log.{ExecFailure, ProcessingFailure, Success}
import org.slf4j.LoggerFactory
object Slf4jLogger {
val slf4jLogHandler: LogHandler = {
val logger = LoggerFactory.getLogger(getClass.getName)
// RHO, CompileRoutesSuite
sealed trait Foo extends Product with Serializable
case class Bar(i: Int) extends Foo
case class Baz(v: UUID) extends Foo
test("A CompileService should make routes from a collection of RhoRoutes 2") {
import org.http4s.rho.bits.StringParser.booleanParser
import org.http4s.rho.bits.StringParser.uuidParser
import scala.reflect.runtime.universe.TypeTag
@TheDIM47
TheDIM47 / MySqlCatalog.java
Created October 19, 2021 09:47
MySqlCatalog - Flink MySQL catalog implementation
import org.apache.flink.connector.jdbc.catalog.AbstractJdbcCatalog;
import org.apache.flink.connector.jdbc.table.JdbcConnectorOptions;
import org.apache.flink.connector.jdbc.table.JdbcDynamicTableFactory;
import org.apache.flink.table.api.DataTypes;
import org.apache.flink.table.api.Schema;
import org.apache.flink.table.api.ValidationException;
import org.apache.flink.table.api.constraints.UniqueConstraint;
import org.apache.flink.table.catalog.CatalogBaseTable;
import org.apache.flink.table.catalog.CatalogDatabase;
import org.apache.flink.table.catalog.CatalogDatabaseImpl;
@TheDIM47
TheDIM47 / MySqlTablePath.java
Created October 19, 2021 09:47
MySqlTablePath - Flink MySQL catalog implementation
import org.apache.flink.util.StringUtils;
import java.util.Objects;
import static org.apache.flink.util.Preconditions.checkArgument;
public class MySqlTablePath {
private static final String DEFAULT_SCHEMA_NAME = "public";
private final String schemaName;
private final String tableName;
@TheDIM47
TheDIM47 / flatten.scala
Created August 28, 2021 17:55
flatten benchmarks
package benchmarks
import org.openjdk.jmh.annotations._
import scala.util.Random
import java.util.concurrent.TimeUnit
import scala.annotation.tailrec
/*
[info] Benchmark (size) Mode Cnt Score Error Units
/**
* Flood Fill
* Given a matrix a containing numbers that represents a
* labyrinth with empty space and walls, as follows:
* 0 is empty space, 1 is a wall, and 2 is water.
*
* Write a program that fills the labyrinth with water starting
* from a given position given by coordinates x and y,
* The top-left coordinate of the matrix is 0,0.
* ```
/**
* Join list of lists by order of elements
* val a = List(3, 5, 6)
* val b = List(1, 2, 7, 8)
* val expected = List(3, 1, 2, 5, 6, 7, 8)
*
* @param lists list of lists of elements
* @return list of elements
*/
def join[A](lists: List[List[A]]): List[A] = {
import java.net.InetAddress
import java.nio.ByteBuffer
object InetUtils {
private[this] val Radix = 16
// Fast Hex converters
private[this] val HexChars: Array[Char] = "0123456789ABCDEF".toCharArray
@TheDIM47
TheDIM47 / XmlTvParser.scala
Last active March 18, 2018 16:02
Simple scala-xml parser for XmlTv format
import scala.xml._
import java.util.Date
import java.lang.ThreadLocal
import java.text.SimpleDateFormat
import scala.collection.immutable._
/**
* Simple XmlTv format parser
* http://wiki.xmltv.org/index.php/XMLTVFormat
*/