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
// ©2012 Viktor Klang | |
// ©2012 Hiram Chirino | |
object Actor { | |
import org.fusesource.hawtdispatch._ | |
type Behavior = Any => Effect | |
sealed trait Effect extends (Behavior => Behavior) | |
case object Stay extends Effect { def apply(old: Behavior): Behavior = old } | |
case class Become(like: Behavior) extends Effect { def apply(old: Behavior): Behavior = like } | |
final val Die = Become(msg => { println("Dropping msg [" + msg + "] due to severe case of death."); Stay }) // Stay Dead plz |
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
Tuple3 { | |
inline def forEach(fn: Function<Any?,Unit>):Unit = { | |
fn.invoke(this._1) | |
fn.invoke(this._2) | |
fn.invoke(this._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
kotlin code: | |
val builder = HtmlBuilder(usersLocale).useLongDates() | |
"foo $a bar $b".build(builder) | |
Creates an anonymous class | |
class AnonymousTemplate(a: String, b: Foo) : (String, Foo) { | |
fun toString() = "foo " + a + " bar " + b | |
inline fun build(out: Appender): Unit { |
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
kotlin code: "foo $a bar $b" | |
by default is turned into... | |
StringTemplate(array("foo ", " bar"), array(a, b)) | |
if a custom compiler plugin knew you wanted a Html template, say, it could change that code to | |
MyHtmlTemplate(a, b) |
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
/** | |
* helper method to return all create features available for the palette | |
* | |
* @param fp the feature provider | |
* @return an array of create features for the palette | |
*/ | |
public static ICreateFeature[] getCreateFeatures(IFeatureProvider fp) { | |
return new ICreateFeature[] { | |
new CreateFigureFeature<Endpoint>(fp, Messages.paletteEndpointTitle, Messages.paletteEndpointDescription, Endpoint.class) | |
#for (n <- nodeDefinitions) |
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 org.scalatra._ | |
import scalate.ScalateSupport | |
object Web extends App { | |
import org.mortbay.jetty.Server | |
import org.mortbay.jetty.webapp.WebAppContext | |
val webapp = new WebAppContext | |
webapp.setDescriptor("src/main/webapp/WEB-INF/web.xml") | |
webapp.setResourceBase("src/main/webapp/") | |
val server = new Server(8080) |
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
---- index.jade ---- | |
- attributes("layout") = "/WEB-INF/nested.jade" | |
- attributes("left") = capture | |
h1 Hello | |
- attributes("right") = capture | |
p This is the content | |
---- /WEB-INF/nested.jade ---- |
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
# | |
val name = "Foo" | |
val blah = "Something" | |
class #{name} extends #{interfaces.mkString(" with ")} | |
# for( method <- methods ) | |
def #{method.name}() = | |
println | |
:string | |
Here | |
Doc style |
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 Elvis { | |
private class ElvisNull extends RuntimeException | |
final class ElvisAny[T](val value: T) extends Proxy { | |
def self: Any = value | |
def ? : T = if( value==null ) throw new ElvisNull else value | |
def :| (func: =>T): T = { | |
try { |
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 transformer extends Transformer { | |
$(".people") { node => | |
// extract a template fragment from the html.. removes it | |
val odd = node.$template("tr.odd") | |
val even = node.$template("tr.even") | |
var c=0 | |
people.flatMap { p => | |
c += 1 | |
node << transform(if (c%2 == 0) even else odd) { t => | |
$(".name").contents = p.name |
NewerOlder