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
/*------------------------------------------------------------------------------ | |
* MIT License | |
* | |
* Copyright (c) 2017 Doug Kirk | |
* | |
* Permission is hereby granted, free of charge, to any person obtaining a copy | |
* of this software and associated documentation files (the "Software"), to deal | |
* in the Software without restriction, including without limitation the rights | |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
* copies of the Software, and to permit persons to whom the Software is |
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
/*------------------------------------------------------------------------------ | |
* MIT License | |
* | |
* Copyright (c) 2017 Doug Kirk | |
* | |
* Permission is hereby granted, free of charge, to any person obtaining a copy | |
* of this software and associated documentation files (the "Software"), to deal | |
* in the Software without restriction, including without limitation the rights | |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
* copies of the Software, and to permit persons to whom the Software is |
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
(defn classes-of | |
"Get the classes of an element as a Clojure keyword vector." | |
[e] | |
(let [words (-> e (.getAttribute "class") (string/split " "))] | |
(mapv keyword words))) | |
(defn classes->str | |
"Change a Clojure keyword seq into an HTML class string." | |
[classes] | |
(->> classes (mapv name) (string/join " "))) |
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
def dump(s: java.io.InputStream): Unit = { | |
val buf = new StringBuilder(64) | |
val chars = new StringBuilder(32) | |
var offset = 0 | |
def dumpLine = { | |
println("%08x %48s |%16s|".format(offset, buf, chars)) | |
buf.setLength(0) | |
chars.setLength(0) | |
offset += 0x10 |
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
/*------------------------------------------------------------------------------ | |
* MIT License | |
* | |
* Copyright (c) 2016 Doug Kirk | |
* | |
* Permission is hereby granted, free of charge, to any person obtaining a copy | |
* of this software and associated documentation files (the "Software"), to deal | |
* in the Software without restriction, including without limitation the rights | |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
* copies of the Software, and to permit persons to whom the Software is |
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.util.{Try, Success, Failure} | |
import scala.util.control.NonFatal | |
object Find { | |
def empty[A]: Find[A] = NotFound | |
def apply[A](value: => A): Find[A] = | |
try { | |
if (value == null) NotFound else Found(value) | |
} |
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
package actors | |
import akka.actor._ | |
import akka.pattern.ask | |
import scala.collection.immutable.Queue | |
import scala.concurrent.duration._ | |
import scala.util.{Success, Failure} | |
object WorkerPool { | |
val defaultTimeout = 30.seconds |
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.util.Random | |
trait Generator[A] extends Function0[A] { | |
val random = new Random | |
def apply: A | |
} | |
object Generator { |
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.reflect.ClassTag | |
import scala.util.{Either, Left, Right} | |
import spray.json._ | |
object JsonLens { | |
class Json(val value: Option[JsValue]) { | |
def /(name: String): Json = Json(value.flatMap(_.asJsObject.fields.get(name))) | |
def -(name: String): Json = Json(value.map(obj => JsObject(obj.asJsObject.fields - name))) | |
def apply(index: Int): Json = { |
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 Solution extends App { | |
def readLetters(width: Int, height: Int): Array[Array[String]] = { | |
val chars = for (i <- 0 until height) yield readLine.grouped(width).toArray | |
chars.toArray | |
} | |
def letterIndex(c: Char): Int = if (c < 'A' || c > 'Z') 26 else c - 'A' | |
val l = readInt |
NewerOlder