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 ground | |
// Show that println and Unit are not the same. | |
// Why pure IO? | |
// Trampoline | |
// IO values and interpreters | |
object UnitIsNotUnit { | |
// Side effects are extremely hard to reason about. |
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 ground | |
// Why pure IO? | |
// Trampoline | |
// IO values and interpreters | |
object UnitIsNotUnit { | |
// Side effects are extremely hard to reason about. | |
// The only way you can tell when they are executed is by following imperative code |
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 ground | |
// Why pure IO? | |
// Trampoline | |
// IO values and interpreters | |
object UnitIsNotUnit { | |
// Side effects are extremely hard to reason about. | |
// The only way you can tell when they are executed is by following imperative code |
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
case class NGramGroup(name: String, NGrams: Seq[NGram]) {} | |
case class Experience(name: String, NGramGroups: Seq[NGramGroup]) {} | |
case class NGram(name: String, weight: Double) | |
object Parser { | |
def parseLine(line: String) = { | |
val spl = line.split(" ") | |
val (expName, emo) = (spl(0), spl(1)) | |
val ng = NGram(spl(2), spl(3).toDouble) |
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 Labels { | |
val FIRST_PUBLISHED = "first published by" | |
val CURRENT_PUBLISHER = "current publisher" | |
val coverOrder = List("BB", "BA", "BC", "DG", "29").reverse | |
val formRankMap = Map(coverOrder.zipWithIndex:_*) | |
val PB = "PB" | |
val WORLD = "WORLD" | |
val US = "US" | |
val SR3 = "03" | |
val SR1 = "01" |
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 mkDisplayImage(cIsbn13: String, refs: Seq[ProductRefView]): Option[String] = { | |
val l = coverOrder | |
val (_, isbn13) = refs.foldLeft(0, None: Option[String])((acum, r: ProductRefView) => { | |
val (p, tIsbn13) = acum | |
if (r.hasImage || checkRights(r)) { | |
if (r.isbn13 == cIsbn13) | |
((l.size + 1), Some(r.isbn13)) | |
else if (tIsbn13.isEmpty) | |
(l.indexOf(r.form), Some(r.isbn13)) | |
else if (l.indexOf(r.form) > p) |
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 mkDisplayImage(cIsbn13: String, refs: Seq[ProductRefView]): Option[String] = { | |
val l = coverOrder | |
val (_, isbn13) = refs.foldLeft(0, None: Option[String])((acum, r: ProductRefView) => { | |
val (p, tIsbn13) = acum | |
if (r.hasImage || checkRights(r)) { | |
if (r.isbn13 == cIsbn13) | |
((l.size + 1), Some(r.isbn13)) | |
else if (tIsbn13.isEmpty) | |
(l.indexOf(r.form), Some(r.isbn13)) | |
else if (l.indexOf(r.form) > p) |
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 pascal(numRows: Int) = { | |
type Coord = (Int, Int) | |
def find(where: Coord, memo: Map[Coord, Int): (Int, Map[Coord, Int]) = memo.get(where) match { | |
case Some(v) => v | |
case None => { | |
val prev = find((where._1 - 1, where._2 - 1), memo) | |
val new = // do your calculation | |
memo.updated(where, new) | |
} | |
} |
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 Permissions { | |
import scalaz.syntax.pointed._ | |
trait PermissionRequired[I, T] { self => | |
type Myself = this.type | |
def action: I => Reader[T] | |
def apply(check: PermissionCheck[I, Myself]): Reader[T] = { | |
val checkAction: Reader[I] = check() |
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 com.knollop.migrate | |
import java.sql.{DriverManager, Driver} | |
import org.bson.types.ObjectId | |
import com.mongodb.casbah.Imports._ | |
import com.novus.salat._ | |
import com.novus.salat.global._ | |
import com.knollop.store._ |