Skip to content

Instantly share code, notes, and snippets.

View t3hnar's full-sized avatar
🎯
Focusing

Yaroslav Klymko t3hnar

🎯
Focusing
View GitHub Profile
@t3hnar
t3hnar / revert-to.sh
Last active October 31, 2019 15:36
revert-to.sh
REVISION=$1 &&
BRANCH=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,') &&
git reset --hard $REVISION &&
MSG="revert $BRANCH to ${REVISION}" &&
git merge -s ours @{1} -m "${MSG}" &&
echo $MSG
import cats.effect.Concurrent
import cats.effect.concurrent.{Deferred, Ref}
import cats.implicits._
trait Cache[F[_], K, V] {
def getOrUpdate(k: K)(v: F[V]): F[V]
def values: F[Map[K, Deferred[F, V]]]
}
@t3hnar
t3hnar / SerialRef.scala
Created January 9, 2019 16:37
SerialRef.scala
import cats.effect._
import cats.effect.concurrent.{Ref, Semaphore}
import cats.implicits._
trait SerialRef[F[_], A] {
def get: F[A]
def modify[B](f: A => F[(A, B)]): F[B]
package akka_streams_test
import akka.actor.ActorSystem
import akka.stream._
import akka.stream.scaladsl.{Flow, Keep, Sink, Source}
import scala.concurrent.Future
object ConsistentHashingParallelism extends App {
implicit val system = ActorSystem("ConsistentHashingParallelism")
package com.evolutiongaming.serialization
import java.nio.charset.Charset
import akka.serialization.SerializerWithStringManifest
import scala.util.control.NoStackTrace
class BrokenSerializer extends SerializerWithStringManifest {
# Maven
target
# Idea
.idea/
*.iml
*.ipr
#JRebel
rebel.xml
lazy val dbCache: Option[Cache] = ???
lazy val realCache: scala.concurrent.Future[Cache] = ???
def cache: Option[Cache] = {
realCache.value match {
case Some(Success(x)) => Some(x)
case None => dbCache
case Some(Failure(error)) =>
log.error(error)
dbCache
case class Coordinates(x: Double, y: Double)
object HaversineDistance {
def apply(a: Coordinates, b: Coordinates): Double = {
val deltaLat = math.toRadians(b.x - a.x)
val deltaLong = math.toRadians(b.y - a.y)
val x = math.pow(math.sin(deltaLat / 2), 2) + math.cos(math.toRadians(a.x)) * math.cos(math.toRadians(b.x)) * math.pow(math.sin(deltaLong / 2), 2)
val greatCircleDistance = 2 * math.atan2(math.sqrt(x), math.sqrt(1 - x))
3958.761 * greatCircleDistance
}
lazy val flyway = new Flyway {
setDataSource(dataSource)
}
def migrateToLatestDbVersion() {
try flyway.migrate() catch {
case e: FlywayException if e.getMessage.startsWith("Unable to check whether schema") =>
flyway.init()
flyway.migrate()
}
@t3hnar
t3hnar / codeStyleSettings.xml
Last active August 29, 2015 13:56
Intellij Idea codeStyleSettings.xml for Scala
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectCodeStyleSettingsManager">
<option name="PER_PROJECT_SETTINGS">
<value>
<option name="USE_SAME_INDENTS" value="true" />
<option name="IGNORE_SAME_INDENTS_FOR_LANGUAGES" value="true" />
<option name="OTHER_INDENT_OPTIONS">
<value>
<option name="INDENT_SIZE" value="2" />