This file contains 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 |
This file contains 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 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 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 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 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
(ns interceptors.success | |
(:require [re-frame.core :as rf] | |
[clojure.string :as string])) | |
(defn success-or-failure | |
"Tests whether an event keyword is a success or failure callback, | |
and returns one of :success, :failure, or nil." | |
[event] | |
(cond |
This file contains 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 element-with-id | |
"Return the element with the given ID." | |
[id] | |
(js/document.getElementById id)) | |
(defn resolve-element | |
"Given an ID or a CSS selector or an element, return the first matching document element." | |
[selector] | |
(cond |
This file contains 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 parse-string | |
"Parse a literal string, returning the [line col index] of the following character. | |
start-ix should point to the first character inside the literal string, not the opening quote." | |
[start-line start-col start-ix text] | |
(loop [line start-line | |
col start-col | |
ix start-ix] | |
(if (>= ix (.length text)) |
This file contains 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
final object Luhn { | |
/** An O(1) Map[Int, Int] of precomputed double values. */ | |
private[this] final val doubles = Array(0, 2, 4, 6, 8, 1, 3, 5, 7, 9) | |
/** | |
* Validate a card using the Luhn algorithm with a single pass through the string, | |
* no other validation needed prior. | |
* | |
* Pure speed here (only 1 function call to get the byte array). | |
*/ |
This file contains 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 sbt._ | |
object FixScalacOptionsInConsole extends AutoPlugin { | |
import Keys._ | |
override def requires = plugins.JvmPlugin | |
override def trigger = allRequirements | |
override lazy val projectSettings = Seq( | |
Compile / console / scalacOptions ~= filter, |
OlderNewer