This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
organization := "net.seratch" | |
name := "sandbox" | |
version := "0.1" | |
scalaVersion := "2.9.1" | |
libraryDependencies ++= Seq( | |
"junit" % "junit" % "4.9" withSources(), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def retry(noTimes: Int)(block: ⇒Future[T]): Future[T] = { | |
val ns: Iterator[Int] = (1 to noTimes).iterator | |
val attempts: Iterator[Future[T]] = ns.map(_⇒ ()⇒block) | |
val failed = Future.failed(new Exception) | |
attempts.foldLeft(failed) | |
((a,block) ⇒ a recoverWith { block() }) | |
} | |
retry(3) { block } | |
= unfolds to |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.typesafe.config.{ConfigValueFactory, Config} | |
import shapeless._ | |
import shapeless.ops.hlist.LeftFolder | |
import shapeless.ops.record._ | |
/* | |
* case class Book(author: String, title: String, age: Option[Int] = None) | |
* | |
* val caseClass = Book("Little John","Shapeless in depth") | |
* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.collection.mutable.{ListBuffer, ArrayBuffer} | |
import MatrixTraveller._ | |
object MatrixTraveller { | |
type Point = (Int,Int) | |
type MaxScore = Int | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.util.{Try, Success, Failure} | |
import Ordering.Implicits._ | |
object HelloWorld extends App{ | |
def find2MaxElem[T : Ordering ](items : Seq[T]) : T = { | |
if(items.size<2) | |
throw new RuntimeException("not enough elems in collection") | |
var max = items(0); | |
var pmax = items(0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait MyIterator[T]{ | |
def hasNext : Boolean | |
def next: T | |
} | |
class Node[T]( | |
value1 : T, | |
var parent:Option[Node[T]], | |
var left1:Option[Node[T]], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class Integer | |
{ | |
private: | |
int value; | |
public: | |
Integer(int i): value(i) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.FilterInputStream; | |
import java.io.IOException; | |
import java.io.InputStream; | |
/** | |
* CustomImplementation of BuffereInputStream which does not use available() of nested stream at all. | |
* It might be reasonable and helpful for those InputStreams that does not impement or implement available with errors [yes, it is truth, one very famous IT company privodes API with error inside available(). ]. | |
* this implementation uses O(1) RAM consuming. | |
*/ | |
public class BufferedInputStream extends FilterInputStream { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DIScope extends Enumeration{ | |
type Value = DIScope | |
val PROTOTYPE,SINGLETON = Value | |
} | |
import DIScope._ | |
object Container{ | |
def inject[A,B](self : B, clazz: Class[A],id: Symbol) : A {} | |
def inject[A,B](self : B, clazz: Class[A])(implicit manifest: Manifest[A]) : A{} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.vast.example | |
import java.net.InetSocketAddress | |
import java.util.UUID | |
import java.util.concurrent.{Executors, TimeUnit} | |
import com.google.common.base.Splitter | |
import com.twitter.finagle.http.Http | |
import com.twitter.finagle.builder.{Server, ServerBuilder} | |
import com.twitter.finagle.service.TimeoutFilter | |
import com.twitter.finagle.{Service, SimpleFilter, GlobalRequestTimeoutException} |
NewerOlder