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
import sbt._ | |
import Keys._ | |
object build extends Build { | |
// usage example | |
lazy val example = Project( | |
"example", | |
file("."), | |
settings = Defaults.defaultSettings ++ Nucleus.settings ++ Seq( |
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
lazy val yodawg = TaskKey[String]("yo-dawg", "I heard you liked settings, so I put a setting in your setting") | |
yodawg <<= Project.app(moduleName :^: version :^: isSnapshot :^: KNil){ | |
case a :+: b :+: c :+: HNil => task(List(a, b, c).mkString("~")) | |
} | |
>show yo-dawg | |
[info] web~2.0-SNAPSHOT~true | |
// source: https://github.com/harrah/xsbt/blob/0.11/main/Structure.scala#L443 |
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
import sbt._ | |
import Keys._ | |
import com.github.siasia.WebPlugin._ | |
lazy val web = Defaults.defaultSettings ++ webSettings ++ Seq( | |
libraryDependencies ++= Seq(jetty, lift, logback), | |
/* add a location for development only resources */ | |
jettyClasspaths <<= (jettyClasspaths, sourceDirectory).map((j, src) => j.copy(classpath = j.classpath +++ src / "development" / "resources")), | |
/* don't scan - use jrebel */ | |
jettyScanDirs := Nil, |
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
scala: | |
case class Node(value:String, children:Node*) | |
def pretty(node:Node, i:String = ""):String = | |
node.children.foldLeft(i + node.value){ _ + "\n" + pretty(_:Node, i + "\t") } | |
println(pretty( | |
Node("parent", | |
Node("child1"), |
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 AkkaCometActor extends CometActor { | |
implicit val optionSelf:Option[ActorRef] = Some(Actor.actorOf(new Actor{ | |
protected def receive = { | |
case a => AkkaCometActor.this ! a | |
} | |
})) | |
override def localSetup { | |
super.localSetup |
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
/* lib */ | |
trait Dynamic { | |
def _select_(name: String):Dynamic | |
def _invoke_(name: String)(args: Any*):Dynamic | |
def ~ (name: Symbol) = _select_(name.name) | |
def ~ (invocation:Invocation) = _invoke_(invocation.name)(invocation.args :_*) | |
def typed[T]:T = asInstanceOf[T] | |
} |
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
OhNoes.scala:2: error: scala.Symbol.apply("oh") of type Symbol does not take parameters | |
val bug = 'oh('noes) | |
^ | |
one error found |
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
// scala @ syntax in patternmatching implemented as a library | |
object `@` { | |
def unapply[A](a:A) = Some(a, a) | |
} | |
// usage | |
val Nums = """(\d),(\d)""".r |
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
//playing around with ideas from http://nilanjan-braincasting.blogspot.com/2010/01/ruby-inject-in-scala.html | |
import collection.TraversableLike | |
implicit def traversableLike2HasInject[A, Repr](t:TraversableLike[A, Repr]) = new { | |
def inject[B >: A](op:(B, A) => B):B = t.reduceLeft(op) | |
} | |
object &:+ extends ((Int, Int) => Int){ | |
override def apply(a:Int, b:Int) = a + b |
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
/* | |
This program is free software. It comes without any warranty, to | |
the extent permitted by applicable law. You can redistribute it | |
and/or modify it under the terms of the Do What The Fuck You Want | |
To Public License, Version 2, as published by Sam Hocevar. See | |
http://sam.zoy.org/wtfpl/COPYING for more details. | |
Uses "http://www.hilite.me/api" |