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 Parser { | |
def main(args: Array[String]): Unit = { | |
val shit = new JsonParser1() | |
println{ | |
shit.parseAll(shit.something, """{"nagger": 3, "dicklen": 3.14e2, "slask": null, "arne": "sket", "gammelarray": ["arne", 3, true], "nested": {"apa": true}}""") | |
} | |
} | |
} | |
class JsonParser1 extends RegexParsers { |
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 java.io.{OutputStream, InputStream} | |
import Skandal._ | |
import scala.annotation.tailrec | |
import scala.collection.mutable.LazyBuilder | |
import scala.collection.generic.CanBuildFrom | |
import scala.collection.mutable.Builder | |
import scala.collection.SeqLike | |
import scala.collection.generic.GenericTraversableTemplate | |
import scala.collection.generic.GenericCompanion | |
object Mustivar { |
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
<target name="init" depends="-set-release-mode, -build-setup"> | |
<property | |
name="scala-library.jar" | |
value="${scala.dir}/lib/scala-library.jar" | |
/> | |
<path id="build.classpath"> | |
<pathelement location="${scala-library.jar}" /> | |
<!--<pathelement location="${your.path}" />--> | |
<pathelement location="${build.dir}" /> | |
</path> |
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
/** For every collection that is a sequence, pimp the method groupedSeq */ | |
implicit class GroupedSeq[SEQ[X]<:Seq[X], T](val seq: SEQ[T]) extends AnyVal { | |
/** Takes a function that maps elems of type T to the grouping kind U | |
* All sequential elements that has the same group U will be grouped in a SEQ | |
* Example {{{ | |
* class Person(name: String) | |
* val people = List(Person("ADAM"), Person("adam"), Person("pelle")) | |
* people.groupeSeq{ _.name.toUpperCase } => List(List(Person(ADAM), Person(adam)), List(pelle)) | |
* }}} |
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 scala.collection.generic.CanBuildFrom | |
object Batik extends App { | |
val fun: Int => Option[Int] = { | |
case 3 => Some(1337) | |
case 5 => None | |
case n => Some(n * 3) | |
} | |
val mustare = List(1,2,3,4,5).filterMap(fun) |
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 java.util.concurrent.LinkedBlockingDeque | |
import scala.annotation.tailrec | |
object `MyOwnFsm;)` extends App{ | |
// val musta = new Musta | |
// musta ! "to5" | |
// musta ! "to6" | |
// musta ! "should crash" | |
// println | |
val pc = new PorcheCounter | |
1 to 3 foreach { _ => pc ! Car("porsche") } |
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
sealed trait JsValue { | |
override final def toString = mkString | |
def mkString: String | |
} | |
case class JsArray(value: JsValue*) extends JsValue { | |
def mkString = value.map{ _.mkString }.mkString("[", ", ", "]") | |
} | |
case class JsObj(value: (String, JsValue)*) extends JsValue { | |
def mkString = value.map{ | |
case (k, v) => s""""$k": ${v.mkString}""" |
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
case class PackedArray[T](elems: Array[AnyRef]) | |
object Packer { | |
def unapply[T](pa: PackedArray[T]): Seq[T] = macro unpack_impl[T] | |
def unpack_impl[T : c.WeakTypeTag](c: Context)(pa: c.Expr[PackedArray[T]]): c.Expr[Seq[T]] = { | |
import c.universe._ | |
val tTyp = weakTypeOf[T] | |
val Some(fields) = tTyp.declarations.collectFirst { | |
case cons: MethodSymbol if cons.isPrimaryConstructor && !cons.isPublic => | |
c.error(c.enclosingPosition, "No public primary constructor found") | |
Nil |
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
/** | |
* Created by arneball on 2014-05-08. | |
*/ | |
import java.util.{List => JList} | |
import retrofit.client.Response | |
import retrofit.http.{Path, GET} | |
import retrofit.{RetrofitError, Callback, RestAdapter} | |
import collection.JavaConversions._ | |
object RetroFit extends App { |
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
class ext extends StaticAnnotation { | |
def macroTransform(annottees: Any*) = macro extension.impl | |
} | |
object extension { | |
def impl(c: Context)(annottees: c.Expr[Any]*): c.Expr[Any] = { | |
import c.universe._ | |
annottees.map{ _.tree }.head match { | |
case q"def $name[..$tp](...$params): $ret = $b" => | |
val Seq(Seq(thiz, rest @ _*), rest2 @ _*) = params |
OlderNewer