Skip to content

Instantly share code, notes, and snippets.

View teigen's full-sized avatar

Jon-Anders Teigen teigen

  • Arktekk
  • Oslo, Norway
View GitHub Profile
import collection.immutable.TreeMap
import collection.mutable.ListBuffer
import reflect.Manifest
import util.matching.Regex
/*
Cucumber API for Scala
Other attempts are
http://gist.github.com/161702
package cuke4duke
/*
static typing to the rescue :-)
scala version of http://wiki.github.com/aslakhellesoy/cucumber/step-argument-transforms
note that this version doesn't need the 'user' hint
since we can provide the same hint using types in the stepdefinition
*/
/*
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"
//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
// scala @ syntax in patternmatching implemented as a library
object `@` {
def unapply[A](a:A) = Some(a, a)
}
// usage
val Nums = """(\d),(\d)""".r
@teigen
teigen / 2.8.0.txt
Created December 26, 2010 13:06
2.8.0 -> 2.8.1 regression
OhNoes.scala:2: error: scala.Symbol.apply("oh") of type Symbol does not take parameters
val bug = 'oh('noes)
^
one error found
@teigen
teigen / gist:783575
Created January 17, 2011 22:01
Do we need Dynamic ?
/* 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]
}
@teigen
teigen / AkkaCometActor
Created February 13, 2011 12:18
Akka Comet Actor Bridge. Akka actor follows comet actor lifecycle
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
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"),
@teigen
teigen / gist:1181563
Created August 30, 2011 18:10
webplugin setup suitable for jrebel (supports loading default.prop outside of directories being packaged)
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,