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 javax.crypto.Mac | |
import javax.crypto.spec.SecretKeySpec | |
def hash_hmac(s: String, secret:String): String = { | |
val sha256_HMAC = Mac.getInstance("HmacSHA256") | |
sha256_HMAC.init(new SecretKeySpec(secret.getBytes("UTF-8"), "HmacSHA256")) | |
sha256_HMAC.doFinal(s.getBytes("UTF-8")).map(char=>f"$char%02x").mkString | |
} |
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
object numberFun { | |
/* Places the numbers 1 to 9 inclusive, once each, in these gaps to make this sum correct | |
() () () () | |
x 3 | |
() () () () () | |
*/ | |
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
case class Thingy(name:String, age:Int){ | |
def +(x:Int)=copy(age=age+x) | |
def unary_- =copy(age = -age) | |
} | |
var dino=Thingy("Dino",49) | |
println(dino) // Thingy(Dino,49) | |
// Note, Thingy is immutable, but we reassign the var |
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 MyTraverable extends Traversable[Int]{ | |
def foreach[U](f: Int => U)={ | |
f(1) | |
f(2) | |
f(3) | |
} | |
} | |
val my=new MyTraverable | |
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 MyIterable extends Iterable[Int]{ | |
def iterator: Iterator[Int]={ | |
Iterator(1,2,3) | |
} | |
} | |
val my=new MyIterable | |
(my ++ my).foreach{println} | |
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
@for((name, actor, status) <- actorsInfo) { | |
@{ | |
val camelCase=actorNameToCamelCase(name) | |
<tr> | |
<td>{name}</td> | |
<td>{status}</td> | |
<td><a href={s"/actors/$camelCase"}>{camelCase}</a></td> | |
</tr> | |
} | |
} |
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 actors.StartActorBrowser | |
import com.google.inject.AbstractModule | |
class Module extends AbstractModule { | |
def configure(): Unit = { | |
bind(classOf[StartActorBrowser]).asEagerSingleton() | |
} | |
} |
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 actors.ActorBrowserActor | |
import com.google.inject.AbstractModule | |
import play.api.libs.concurrent.AkkaGuiceSupport | |
class Module extends AbstractModule with AkkaGuiceSupport{ | |
def configure(): Unit = { | |
bindActor[ActorBrowserActor](ActorBrowserActor.NAME, _=>ActorBrowserActor.props) | |
} | |
} |
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
// https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/_maven_repository.html | |
// Play 2.5 is not compatible with ES 5.x Java TCP, as ES demands Netty 4.1 vs Play's 4.0 | |
// https://github.com/sksamuel/elastic4s/issues/672 | |
import org.apache.http.HttpHost | |
import org.apache.http.entity.ContentType | |
import org.apache.http.nio.entity.NStringEntity | |
import org.apache.http.util.EntityUtils | |
import org.elasticsearch.client.RestClient | |
import play.api.libs.json.{Format, Json, Writes} |
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
/** | |
* Allows you to receive scala.collection.immutable.Stream | |
*/ | |
import org.apache.spark.storage.StorageLevel | |
import org.apache.spark.streaming.receiver.Receiver | |
class InfiniteStreamReceiver[T](stream: Stream[T], delay:Int=0, storageLevel: StorageLevel) extends Receiver[T](storageLevel) { | |
receiver=> |