Skip to content

Instantly share code, notes, and snippets.

View rssh's full-sized avatar

Ruslan Shevchenko rssh

View GitHub Profile
@rssh
rssh / X.scala
Created December 31, 2015 21:45
package x
object X
{
def main(arr:Array[String]): Unit = {
System.err.println(s"build with ${BuildInfo.millis}");
}
@rssh
rssh / gist:cc0ff1fda7891e9d8ec9
Last active August 29, 2015 14:06
jdv_article19 (macros example)
object Log
{
def apply(msg: String): Unit = macro applyImpl
def applyImpl(c: Context)(msg: c.Expr[String]):c.Expr[Unit] =
{
import c.universe._
val tree = q"""if (Log.enabled) {
@rssh
rssh / gist:15dd5f8004020ddb938b
Created September 16, 2014 08:43
jdv_article18 (Do usage)
Do {
x += 1
} until ( x != 10 )
@rssh
rssh / gist:40dabb8bc2ad9945dfdc
Created September 16, 2014 07:48
jdv_article17 (own Do loop)
object Do
{
def apply(body: => Unit) = new DoDody(body)
}
class DoBody(body: => Unit)
{
def until(cond: =>Unit): Unit =
{ body
while(!cond)
@rssh
rssh / gist:b39fa949af92f18e8b87
Created September 16, 2014 07:44
jdv_article16
p match {
case Person(“Jon”,”Galt” ) => “Hi, who are you ?”
case Person(firstName, lastName) => s”Hi, ${firstName}, ${lastName}”
case _ => “You are not person”
}
@rssh
rssh / gist:a559710f485fa6fab465
Created September 16, 2014 07:36
jdv_article15 (SAM illustrations, scala)
trait AsyncInputOutput[T]
{
def onReceive(f: T => Unit): Unit
def onSend(f: Unit => T): Unit
}
@rssh
rssh / gist:c07d16cc2e9344c881f4
Created September 16, 2014 06:12
jdv_article14 (SAM illustration)
interface AsyncInputOutput<T>
{
void onReceive(Acceptor<T> acceptor)
void onSend(Generator<T> generator)
}
@rssh
rssh / gist:23bb4add871c21de16c1
Created September 16, 2014 04:57
jdv_article13 (scala collection operation)
peoples.filter(_.firstName == “Jon”)
@rssh
rssh / gist:1f10c1aad5c7814ebf71
Created September 16, 2014 04:56
jdv_article12 (java collections)
peoples.stream().filter( x -> x.firstName.equals(”Jon”)).collect(Collectors.toList())
@rssh
rssh / gist:fadc2e2a8fc35745c571
Created September 16, 2014 04:52
jdv_article11 (overriding toString in trait)
trait MyToString
{
override def toString = s”[${super.toString}]”
}