Skip to content

Instantly share code, notes, and snippets.

View AlexBaitov's full-sized avatar

AlexBaitov

  • cft
  • Novosibirsk
View GitHub Profile
// https://github.com/scala/bug/issues/5589
implicit class FilterableRight[E, T](x: Either.RightProjection[E, T]) {
def withFilter(p: T => Boolean): Either.RightProjection[E, T] = x
}
implicit class FilterableEither[E, T](x: Either[E, T]) {
def withFilter(p: T => Boolean): Either[E, T] = x
}
implicit class FilterableEitherT[F[_], A, B](x: EitherT[F,A,B]) {
def withFilter(p: B => Boolean): EitherT[F, A, B] = x
package ru.dgis.ams.owl
import com.typesafe.config.{Config, ConfigFactory}
import scala.concurrent.duration.{Duration, NANOSECONDS}
object SimpleFiniteDurationParse extends App{
/**
* A reader for for a scala.concurrent.duration.FiniteDuration. This reader should be able to read any valid duration
* format as defined by the <a href="https://github.com/typesafehub/config/blob/master/HOCON.md">HOCON spec</a>.
@AlexBaitov
AlexBaitov / postgres_queries_and_commands.sql
Created October 2, 2019 08:31 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@AlexBaitov
AlexBaitov / postgresql_timezone.sql
Created March 29, 2019 10:19
Postgresql timezone manipulation
-- https://www.postgresql.org/docs/9.6/view-pg-timezone-names.html
db=> select * from pg_timezone_names;
db=> begin;
BEGIN
db=> select now();
now
------------------------------
2019-03-29 10:16:19.87445+00
(1 row)
@AlexBaitov
AlexBaitov / sealed_trait_match_1.scala
Last active February 25, 2019 10:00
Sealed trait with inherited sealed trait exhaustive check
sealed trait A
sealed trait B extends A
case class Qa(value: String) extends A
case class Wb(value: String) extends B
case class Eb(value: String) extends B
def matc(ob: A) = ob match {
case Qa(v) => "q" + v
case Wb(v) => "w" + v
case Eb(v) => "e" + v
@AlexBaitov
AlexBaitov / 02_encoding_anyval.md
Last active October 20, 2018 16:28
io.circe - Enconding and decoding - Examples

Encoding AnyVal

Initial data

case class RubricId(value: Int) extends AnyVal

Desired result

import io.circe.syntax._

Привет!

Здесь вы найдёте полезные ссылки по докладу Подход к Continuous Deployment в микросервисной архитектуре

Слайды

будет добавлена ссылка на презентацию

будет добавлена ссылка на видео доклада на http://www.highload.ru/siberia/2018/abstracts/3308

Контакты

@AlexBaitov
AlexBaitov / GetResource.scala
Last active March 28, 2023 22:35
Different ways to get file from resource
// 1
Source.fromResource("/public.pem").getLines()
// 2
getClass.getResourceAsStream("/public.pem") match {
case null => throw new FileNotFoundException("/public.pem")
case stream => Source.fromInputStream(stream).getLines().mkString
}
// 3
@AlexBaitov
AlexBaitov / rsa_jwt_encode_decode.scala
Last active October 13, 2022 01:18
RSA JWT encode && decode Example
import org.bouncycastle.jce.provider.BouncyCastleProvider
import java.security.KeyFactory
import java.security.spec.RSAPrivateKeySpec
import java.math.BigInteger
import java.util.Base64
import pdi.jwt.{Jwt, JwtClaim, JwtOptions}
import scala.language.implicitConversions
// https://github.com/cb372/json-web-tokens/blob/master/core/src/main/scala/jwt/Keys.scala