Skip to content

Instantly share code, notes, and snippets.

View sashagavrilov's full-sized avatar

Sasha Gavrilov sashagavrilov

View GitHub Profile
@sashagavrilov
sashagavrilov / ConnectedComponents.java
Created March 19, 2018 20:25
Connected Components in java
class ConnectedComponents {
private int[] components;
private int[] orders;
ConnectedComponents(int size) {
this.components = new int[size];
this.orders = new int[size];
for (int i = 0; i < size; i++) {
components[i] = i;
import java.util.Arrays;
import java.util.stream.IntStream;
import java.util.stream.Stream;
public class Solution {
static class Graph {
private final int[][] adj;
@sashagavrilov
sashagavrilov / ScalaEnum.scala
Created February 7, 2017 01:50 — forked from viktorklang/ScalaEnum.scala
DIY Scala Enums (with optional exhaustiveness checking)
trait Enum { //DIY enum type
import java.util.concurrent.atomic.AtomicReference //Concurrency paranoia
type EnumVal <: Value //This is a type that needs to be found in the implementing class
private val _values = new AtomicReference(Vector[EnumVal]()) //Stores our enum values
//Adds an EnumVal to our storage, uses CCAS to make sure it's thread safe, returns the ordinal
private final def addEnumVal(newVal: EnumVal): Int = { import _values.{get, compareAndSet => CAS}
val oldVec = get
@sashagavrilov
sashagavrilov / ignore-cancel.txt
Last active November 2, 2016 00:08
Akka Tls trace
[akka://TlsSpec/user/StreamSupervisor-0/flow-Client] begin handshake Client
[akka://TlsSpec/user/StreamSupervisor-0/flow-Client] bidirectional
[akka://TlsSpec/user/StreamSupervisor-0/flow-Client] bidirectional continue
[akka://TlsSpec/user/StreamSupervisor-0/flow-Client] wrap: status=OK handshake=NEED_UNWRAP remaining=0 out=149
[akka://TlsSpec/user/StreamSupervisor-0/flow-Client] flushToTransport
[akka://TlsSpec/user/StreamSupervisor-0/flow-Client] sending 149 bytes
[akka://TlsSpec/user/StreamSupervisor-0/flow-Server] begin handshake Server
[akka://TlsSpec/user/StreamSupervisor-0/flow-Server] bidirectional
@sashagavrilov
sashagavrilov / ExtendedCookieState.scala
Last active May 6, 2016 08:42
Extended state to SocialProviders
trait ExtendedOAuth2State extends OAuth2State {
/**
* Returns a uri to send user after authentication
*
* @return A uri to send user after authentication
*/
def returnTo: Option[String]
}
/**