Skip to content

Instantly share code, notes, and snippets.

View semenodm's full-sized avatar

Dmytro Obodowsky semenodm

  • Disney Streaming Services
  • DFW
View GitHub Profile
@semenodm
semenodm / FindNthInTree.java
Created December 8, 2016 03:35
Interview question. Find n-th In-order traversal element with and without recursion
package org.sdo.algorythms;
import java.util.Deque;
import java.util.LinkedList;
/**
* Created by dsemenov
* Date: 12/7/16.
*/
public class FindNthInTree<D> {
package org.sdo.alg.other
import java.util.concurrent.atomic.AtomicReference
/**
* Created by dsemenov
* Date: 1/28/16.
*/
class Throttler(tps: Int) {
val maxInterval = tps / 1000
package org.sdo.alg.other
import org.sdo.alg.other.MaximumSumSubArray.Context
/**
* Created by dsemenov
* Date: 1/21/16.
*/
object MaximumSumSubArray {
package org.sdo.alg.other
/**
* Created by dsemenov
* Date: 1/7/16.
*/
trait WaterCollect {
def collectWater(towers: List[Int]): Int = {
def walkMax(towers: List[Int]): List[Int] = {
var tempMax = 0
@semenodm
semenodm / Assynch Sitributed Transactions
Created January 20, 2016 18:55
My way to cope the asynchronus way of handling distributed transactions
import java.sql._
import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success}
implicit val ec: ExecutionContext = ???
val f1 = Future{
val connection : Connection = ???
@semenodm
semenodm / TopoGraph.scala
Created January 9, 2016 15:39
Topological order by Corman
package org.sdo.alg.graph
case class TopoGraph(adjList: Map[String, List[String]]) {
var visited: Set[String] = Set()
var order: List[String] = Nil
def topologicalOrder(): List[String] = {
adjList foreach {
case (vertex, _) =>
package org.sdo.alg.geeks
/**
* Created by dsemenov
* Date: 1/5/16.
*/
trait PossibleTrees[E] {
def findPossiblePreOrderTreesFor(inOrderTree: List[E]): List[List[E]] = inOrderTree match {
case Nil => Nil
case head :: Nil => List(List(head))
@semenodm
semenodm / MajorityElement.scala
Created December 31, 2015 03:15
Majority element with Moor Voting
package org.sdo.alg.geeks
/**
* Created by dsemenov
* Date: 12/30/15.
*/
trait MajorityElement[E] {
private[this] def findCandidate(elements: List[E]): Option[E] = elements match {
case head :: tail =>
@semenodm
semenodm / AsyncProcessorHelper.java
Created December 7, 2015 21:57
Awaiting downstream processor completion
public static void process(final AsyncProcessor processor, final Exchange exchange) throws Exception {
final AsyncProcessorAwaitManager awaitManager = exchange.getContext().getAsyncProcessorAwaitManager();
final CountDownLatch latch = new CountDownLatch(1);
boolean sync = processor.process(exchange, new AsyncCallback() {
public void done(boolean doneSync) {
if (!doneSync) {
awaitManager.countDown(exchange, latch);
}
}
@semenodm
semenodm / NettyProducer.java
Last active December 7, 2015 21:51
write body
// write body
NettyHelper.writeBodyAsync(LOG, channel, remoteAddress, body, exchange, new ChannelFutureListener() {
public void operationComplete(ChannelFuture channelFuture) throws Exception {
LOG.trace("Operation complete {}", channelFuture);
if (!channelFuture.isSuccess()) {
// no success then exit, (any exception has been handled by ClientChannelHandler#exceptionCaught)
return;
}
// if we do not expect any reply then signal callback to continue routing