Skip to content

Instantly share code, notes, and snippets.

View dmgcodevil's full-sized avatar
👽
coding

Roman Pleshkov dmgcodevil

👽
coding
  • Lost in the static
  • USA, NY
View GitHub Profile
@dmgcodevil
dmgcodevil / affirmation
Created April 14, 2015 13:25
MuleSoft Contributor Agreement Acceptance by Roman_Pleshkov
I, Roman_Pleshkov, have read and do accept the MuleSoft Contributor Agreement
at http://www.mulesoft.org/legal/contributor-agreement.html
Accepted on Tue Apr 14 2015 16:25:47 GMT+0300 (Belarus Standard Time)
package seg;
import java.util.Comparator;
import java.util.Scanner;
import java.util.TreeSet;
public class SegmentAndPoint {
private static int[] fastCountSegments(int[] starts, int[] ends, int[] points) {
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
public class SegmentAndPoint {
public static final OrderY ORDER_Y = new OrderY();
public static final OrderX ORDER_X = new OrderX();
@dmgcodevil
dmgcodevil / Phantom.scala
Created February 28, 2017 05:03
Example of Phantom type in Scala
/**
* Created by dmgcodevil on 2/27/2017.
*/
object Phantom {
object Hacker {
sealed trait State
object State {
@dmgcodevil
dmgcodevil / Existential.scala
Created February 28, 2017 05:05
Example of Existential Type in Scala
/**
* Created by dmgcodevil on 2/27/2017.
*/
object Existential {
// M[T] forSome { type T; } is the type of all things for which there is some T such that they are of type M[T]
// it's possible to use type bounds: T <: Number
type AllArrays = Array[T] forSome {type T} // -> Array[_] ; the type of all arrays
type AnyArray = Array[T forSome {type T}] // -> Array[Any]
public class MinimumWindowSubstring {
public static void main(String[] args) {
assertEquals("ba", minWindow("bba", "ab"));
assertEquals("b", minWindow("ab", "b"));
assertEquals("", minWindow("ab", ""));
assertEquals("bc", minWindow("abc", "bc"));
assertEquals("ab", minWindow("abc", "ab"));
assertEquals("b", minWindow("abc", "b"));
@dmgcodevil
dmgcodevil / LaCarte.scala
Last active May 6, 2019 21:48
modular function eval that interprets expressions that are constructed using the a la carte ` technique
import cats.implicits._
import cats.{Functor, MonadError}
// links:
// [1] http://www.cs.nott.ac.uk/~pszgmh/alacarte.pdf
// [2] http://www.cs.ru.nl/~W.Swierstra/Publications/DataTypesALaCarte.pdf
object LaCarte {
type ErrorOr[A] = Either[String, A]
@dmgcodevil
dmgcodevil / alacarte.scala
Last active March 26, 2021 06:07
alacarte
object alacarte {
sealed trait Interact[A]
case class Ask(prompt: String)
extends Interact[String]
case class Tell(msg: String)
extends Interact[Unit]
@dmgcodevil
dmgcodevil / gist:22e50eb8f415602bb8d128fe28cdb209
Created December 28, 2019 03:48
Using UDP multicast for pods/peers discovery in Kubernetes

Java app: Publisher/Receiver

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.net.UnknownHostException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@dmgcodevil
dmgcodevil / Core.scala
Created September 13, 2020 19:00
Effect wrapper
package io.parapet.v2
import cats.effect.{Concurrent, ContextShift, IO, Timer}
import cats.free.Free
import cats.free.Free.liftF
import cats.{Monad, ~>}
import scala.concurrent.ExecutionContext
object Core {