This file contains 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
(require 'seq) | |
(require 'dired) | |
(require 'cl-lib) | |
(setq | |
gc-cons-threshold (* 100 1024 1024) ;; 100MB | |
read-process-output-max (* 1 1024 1024)) ;; 1MB | |
(defconst USER-EMACS-DIRECTORY (file-name-directory (or load-file-name (buffer-file-name)))) | |
(defconst USER-INIT-FILE (concat USER-EMACS-DIRECTORY "init.el")) |
This file contains 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 simplity i'm using Ammonite-Repl. | |
* https://lihaoyi.github.io/Ammonite/ | |
*/ | |
// Add Spray repo resolver | |
import ammonite.repl._, Resolvers._ | |
resolvers() = resolvers() :+ Resolver.Http("spray repo", "http://repo.spray.io", IvyPattern, false) | |
// Load toolkit | |
load.ivy("io.spray" %% "spray-routing" % "1.3.3") |
This file contains 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 Distribution { | |
case class DistributionConfig( | |
outputDirectory: File, | |
configResources: Seq[File], // from src/main/resources | |
distJvmOptions: String, | |
distMainClass: String, | |
libFilter: File ⇒ Boolean, | |
additionalLibs: Seq[File]) | |
object DistributionKeys { |
This file contains 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 io.alterstack.build | |
import sbt._ | |
import Keys._ | |
import com.typesafe.config.{Config, ConfigFactory} | |
import com.decodified.scalassh.{ | |
Command => SshCommand, | |
CommandResult => SshCommandResult, | |
_ | |
} |
This file contains 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
/** | |
* Model for our case. | |
* Note that [[Value]] class is not serializable, while | |
* [[Wrapper]] is a case class, which is serializable by default. | |
*/ | |
class Value | |
case class Wrapper(v: Value) | |
// defined class Value | |
// defined class Wrapper |
This file contains 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 DefaultsTo[Type, Default] | |
object DefaultsTo { | |
implicit def defaultDefaultsTo[T]: DefaultsTo[T, T] = null | |
implicit def fallback[T, D]: DefaultsTo[T, D] = null | |
} | |
trait Document | |
trait Reader[A] |
This file contains 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 compute(nums: Int*) = { | |
def h(idx: Int)(num: Int): Int = (((math.pow(num, 2) + math.pow(num, 3)) * idx) % 32).toInt | |
val fs: List[Int => Int] = List(h(1), h(2), h(3)) | |
val result = nums.map { n => | |
val bits = fs.map(_(n)).sorted | |
println(s"$n -> ${bits.mkString(",")}") | |
(n -> bits) | |
} | |
println(s"Result: ${result.map(_._2).flatten.sorted.distinct.mkString(",")}") | |
result |
This file contains 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
/***************************** | |
* Invariant type with Nothing * | |
****************************/ | |
sealed trait Interact[A] | |
case class Ask(value: String) extends Interact[String] | |
case class Tell(value: String) extends Interact[Nothing] // Notice Nothing here | |
val instr = | |
List(Ask("What's your first name?"), |
This file contains 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 Service { | |
def host: String | |
def port: Int | |
} | |
trait GoogleServiceModule extends Service { | |
val host = "google.com" | |
val port = 80 | |
} |
This file contains 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
implicit def streamTMarshaller[M[+_]](implicit mtm: MarshallerM[M], M: Monad[M], arf: ActorRefFactory) = { | |
new MarshallerM[({ type λ[α] = StreamT[M, α] })#λ] { | |
override def marshaller[T](implicit mt: Marshaller[T]): Marshaller[StreamT[M, T]] = { | |
new Marshaller[StreamT[M, T]] { | |
override def apply(value: StreamT[M, T], ctx: MarshallingContext): Unit = { | |
implicitly[MarshallerM[M]].marshaller[Stream[T]].apply(value.toStream, ctx) | |
} | |
} | |
} | |
} |
NewerOlder