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
/* | |
* Copyright (c) 2010 Tobias Schneider | |
* This script is freely distributable under the terms of the MIT license. | |
*/ | |
(function(){ | |
var UPC_SET = { | |
"3211": '0', | |
"2221": '1', | |
"2122": '2', |
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 helper { | |
def printCaseClass(caseClass: AnyRef): Unit = { | |
def caseClassToMap(caseClass: AnyRef): Map[String, Any] = { | |
(Map.empty[String, Any] /: caseClass.getClass.getDeclaredFields) { | |
(a, f) => | |
f.setAccessible(true) | |
a + (f.getName -> f.get(caseClass)) | |
} |
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
trait Utility extends LazyLogging { | |
def log(future: Future[_])( | |
implicit executionContext: ExecutionContextExecutor): Unit = { | |
val start = System.currentTimeMillis() | |
future.onComplete { | |
case Success(res) => | |
logger.info( | |
s"Result in ${System.currentTimeMillis() - start} ms is $res") | |
case Failure(e) => |
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.annotation.tailrec | |
object sortings { | |
def insertionSort(ar: Array[Int]): Array[Int] = { | |
@tailrec | |
def loop(i: Int, key: Int): Int = | |
if (i < 0 || ar(i) < key) i + 1 | |
else { | |
ar(i + 1) = ar(i) | |
loop(i - 1, key) |
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.annotation.tailrec | |
object sortings { | |
//p <= q < r | |
def merge(ar: Array[Int], p: Int, q: Int, r: Int): Array[Int] = { | |
val x = q - p + 1 | |
val left = new Array[Int](x + 1) | |
Array.copy(ar, p, left, 0, x) | |
left(left.length - 1) = Int.MaxValue |
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 sortings { | |
def swap(ar: Array[Int], i: Int, j: Int): Array[Int] = { | |
val temp = ar(i) | |
ar(i) = ar(j) | |
ar(j) = temp | |
ar | |
} | |
def bubbleSort(ar: Array[Int]): Array[Int] = { |