Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.
$ python -m SimpleHTTPServer 8000
import spray.routing.{AuthenticationFailedRejection, HttpService} | |
import akka.actor.{Props, ActorSystem, Actor, ActorRefFactory} | |
import spray.routing.authentication._ | |
import scala.concurrent.Promise | |
import spray.routing.AuthenticationFailedRejection.CredentialsMissing | |
import akka.io.IO | |
import spray.can.Http | |
class MinifiedService extends Actor with HttpService { | |
val identity_cookie_name = "session_id" |
import reflect._ | |
class Father[T <: Father[T] : ClassTag]{ | |
def createInstance: T = implicitly[ClassTag[T]].runtimeClass.newInstance.asInstanceOf[T] | |
} | |
class Child1 extends Father[Child1] | |
class Child2 extends Father[Child2] |
import scala.annotation.tailrec | |
@tailrec | |
def common[T: Ordering](l1: List[T], l2: List[T], accu: List[(T, T)]): List[(T, T)] = { | |
(l1, l2) match { | |
case (Nil, _) | (_, Nil) => accu.reverse | |
case (h1 :: t1, h2 :: t2) => | |
val cmp = implicitly[Ordering[T]].compare(h1, h2) | |
if (cmp < 0) common(t1, l2, accu) | |
else if (cmp > 0) common(l1, t2, accu) |
(ns clojure-scripts.template | |
(:import (httl Engine))) | |
(def model {:single_string "Hello, world!" | |
:items [{:name "item1"} | |
{:name "item2"} | |
{:name "item3"}]}) | |
(defn keyword-as-str [model] |
import scala.reflect.runtime.{universe => ru} | |
import ru._ | |
def getProperties[T: TypeTag]: Iterable[String] = { | |
val tpe = ru.typeTag[T].tpe | |
tpe.declarations.collect { | |
case m: MethodSymbol if m.isCaseAccessor => m.name.toString | |
} | |
} |
Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.
$ python -m SimpleHTTPServer 8000
trait TypeClass1[T] | |
trait TypeClass2[V] | |
implicit object StringIsTypeClass1 extends TypeClass1[String] | |
def test[X, M[_]](implicit ev: M[X] = null.asInstanceOf[M[X]]): Boolean = { | |
ev != null | |
} | |
assert(test[String, TypeClass1] == true) |
// You won't be able to compile this with: | |
// scala -language:dynamics NoDynamics.scala | |
// These two ambiguous implicits disable the `dynamics` feature. | |
implicit def ambDynamics1: language.dynamics.type = ??? | |
implicit def ambDynamics2: language.dynamics.type = ??? | |
object Woo extends Dynamic { | |
def selectDynamic(name: String) = s"$name a mess of a language" |
trait CanFromString[T] { | |
def fromString(s: String): T | |
} | |
implicit object intCanFromString extends CanFromString[Int] { | |
override def fromString(s: String): Int = s.toInt | |
} | |
implicit object SymbolCanFromString extends CanFromString[Symbol] { | |
override def fromString(s: String): Symbol = Symbol(s) | |
} |
def pair(s: String, key: Int, value: Int): (String,String) = { | |
val arr = s.split(",") | |
arr(key) -> arr(value) | |
} | |
def pair[V](s: String, key: Int, value: (Int, String => V)): (String,V) = { | |
val arr = s.split(",") | |
arr(key) -> value._2.apply(arr(value._1)) | |
} | |
def pair[K](s: String, key: (Int, String => K), value: Int): (K, String) = { | |
val arr = s.split(",") |