Skip to content

Instantly share code, notes, and snippets.

View rssh's full-sized avatar

Ruslan Shevchenko rssh

View GitHub Profile
@rssh
rssh / gist:a807ce21e030124fd7ed
Created September 16, 2014 04:48
jdv_article10 (stackable trait)
trait LoggedAsyncInput[T]
{
override def onReceive(acceptor: T => ()) =
super.onReceive(x => { println(s“received:${x}”)
acceptor(x) })
}
@rssh
rssh / gist:51448fdd4163721d59c4
Created September 15, 2014 21:36
jdv_article8 (scala trait)
trait AsyncInput[T]
{
def onReceive(acceptor: T=>()): Unit
def read: Future[T] = {
Promise p = Promise[T]()
onReceive(p.complete(_))
p.future
}
@rssh
rssh / gist:2c854f723a34addb07ed
Created September 15, 2014 21:32
jdv_article7 (java default method implementation in interface)
interface AsyncInput<T>
{
void onReceive(Acceptor<T> acceptor)
default void read(): Future<T> {
final CompletableFuture<T> promise = new CompletableFuture<>();
onReceive( x -> promise.complete(x) );
return promise;
}
@rssh
rssh / gist:b7a4c9ec9790295b69f9
Last active August 29, 2015 14:06
jdv_article6 (scala lambda expression with modification of context)
var (maxFirstLen, maxSecondLen) = (0,0)
list.foreach{
x => maxFirstLen = max(maxFirstLen, x.firstName.length)
maxSecondLen = max(maxSecondLen, x.secondName.lenght)
}
@rssh
rssh / gist:8a4375719ca1622a0580
Created September 15, 2014 21:17
jdv_article5 (simple lambda expression in scala)
list.sort((x,y) => {
val cmp = x.lastName.compareTo(y.lastName)
if (cmp!=0) cmp else x.firstName.compareTo(y.lastName)
}
@rssh
rssh / gist:f766e6783af08403ae8a
Created September 15, 2014 21:16
jdv_article_4 (simple lambda-expression in java)
list.sort((x,y)-> {
int cmp = x.lastName.compareTo(y.lastName);
return cmp!=0 ? cmp : x.firstName.compareTo(y.firstName)
}
@rssh
rssh / gist:7baef0ef33054f0daf1d
Created September 15, 2014 04:38
jdv_article3
public class Person extends DTOBase
{
public String firstName;
public String lastName;
}
@rssh
rssh / gist:82fc8a3f6196b616add3
Created September 15, 2014 04:36
jdv_article_2
public class Person
{
private String firstName;
private String lastName;
String getFirstName() { return firstName; }
void setFirstName(String firstName) { this.firstName = firstName; }
String getLastName() { return lastName; }
void setLastName(String lastName) { this.lastName = lastName; }
@rssh
rssh / gist:5511ea89caee72a35861
Created September 15, 2014 04:31
jdlv_article_1
case class Person(firstName:String, lastName:String)
package x
import akka.actor._
import scala.concurrent._
import scala.concurrent.duration._
import ExecutionContext.Implicits.global
object X
{