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 opcodeLookup = Map( | |
0 -> "nop", | |
1 -> "aconst_null", | |
2 -> "iconst_m1", | |
3 -> "iconst_0", | |
4 -> "iconst_1", | |
5 -> "iconst_2", | |
6 -> "iconst_3", | |
7 -> "iconst_4", | |
8 -> "iconst_5", |
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 JVMParamParser { | |
def parse(sig: String) = { | |
def parseRec(acc: Seq[String], sig: List[Char]): Seq[String] = { | |
val drop = sig.dropWhile(_ == '[') | |
val fill = Seq.fill(sig.length - drop.length)('[').mkString | |
drop match { | |
case head :: tail if jvmTypeLookup.contains(head) => | |
parseRec(acc :+ s"$fill${head.toString}", tail) | |
case head :: tail if head == 'L' => |
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 SpellCheck { | |
val alpha = "abcdefghijklmnopqrstuvwxyz" | |
val model = scala.io.Source.fromFile("big.txt") | |
.getLines() | |
.flatMap(_.toLowerCase.split("\\W+")) | |
.foldLeft(Map.empty[String, Int].withDefaultValue(1)) { (acc, word) => | |
acc + (word -> (acc.getOrElse(word, 0) + 1)) | |
} |
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 FlickrBase58Coder { | |
val alpha = "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ" | |
val base = alpha.length | |
def apply(encodedInput: String) = decode(encodedInput) | |
def apply(decodedInput: Long) = encode(decodedInput) | |
def encode(input: String): String = encode(input.toLong) | |
def encode(input: Long) = { | |
def enc(in: Long, acc: String): String = if (in < 1) acc else enc(in / base, alpha((in % base).toInt) + acc) |