Skip to content

Instantly share code, notes, and snippets.

View ptrdom's full-sized avatar

Domantas Petrauskas ptrdom

View GitHub Profile
@ptrdom
ptrdom / elon-musk-quote.js
Created August 9, 2018 09:30
Elon Musk quote as JavaScript code
/**
* @author Elon Musk
*/
switch(person.choice) {
case 'PARTICIPATE':
it.bePartOf();
default:
it.watchHappen();
}
@ptrdom
ptrdom / elon-musk-quote-inline.js
Created August 9, 2018 09:43
Elon Musk quote as inline JavaScript code
person.choice === 'participate' ? it.bePartOf() : it.watchHappen();
@ptrdom
ptrdom / FindClosest.scala
Last active August 31, 2018 11:46
Finding closest number in sequence to given number
val entryPoint = 0
val points = List(-2, -1, 0, 1, 2, 3, 4)
val closest = points
.reduceLeftOption {
(point1, point2) =>
val distance1 = Math.sqrt(Math.pow(entryPoint - point1, 2))
val distance2 = Math.sqrt(Math.pow(entryPoint - point2, 2))
if (distance1 < distance2) {
@ptrdom
ptrdom / LRUCache.scala
Created August 31, 2018 14:13
LRUCache implementation in Scala
import scala.collection.mutable
class LRUCache(maxSize: Int) {
val map = mutable.LinkedHashMap[Int, String]()
def put(key: Int, value: String) = {
moveToBottom(key, value)
if (map.size > maxSize) {
val (firstKey, _) = map.head
@ptrdom
ptrdom / AutorecoveringDirectReplyClient.java
Created October 18, 2018 12:57
RabbitMQ Java Client AutorecoveringDirectReplyClient example
package utilities.rabbitmq;
import com.rabbitmq.client.*;
import com.rabbitmq.utility.BlockingCell;
import net.jodah.lyra.config.Config;
import net.jodah.lyra.event.DefaultChannelListener;
import java.io.EOFException;
import java.io.IOException;
import java.util.Map;
@ptrdom
ptrdom / PlayTestcontainersIsolatedSlick.scala
Created February 17, 2019 21:33
Example of Play Framework + Testcontainers usage with isolated Slick - not using play-slick
//Test tag
case object DockerDatabaseTest extends Tag("DockerDatabase")
//Test harness
package utilities.database
import com.dimafeng.testcontainers.{ForAllTestContainer, PostgreSQLContainer}
import org.scalatest.mockito.MockitoSugar
import org.scalatest.{Assertion, Suite}
import org.scalatestplus.play.AppProvider
@ptrdom
ptrdom / ScalaSlickEnumSortComplex.scala
Created March 26, 2019 13:32
Scala Slick code that does sorting by Enum while assigning different values to be used for sorting
import scala.language.implicitConversions
object OrderEnum extends Enumeration {
protected case class Val(actualValue: String, orderValue: String) extends super.Val
implicit def valueToVal(x: Value): Val = x.asInstanceOf[Val]
val A = Val("a", "c")
val B = Val("b", "b")
val C = Val("c", "a")
}
@ptrdom
ptrdom / AkkaPersistenceCassandraClient.scala
Created May 31, 2021 06:06
Akka Persistence Cassandra client for interaction with persistence layer with bypass of Lagom's entities
import java.nio.ByteBuffer
import java.time.Instant
import java.time.temporal.ChronoUnit
import java.util.UUID
import akka.Done
import akka.actor.ActorSystem
import akka.serialization.SerializationExtension
import akka.serialization.SerializerWithStringManifest
import com.datastax.driver.core.BatchStatement