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
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
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 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._ |
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
// Publish is performed on an existing post and if no post exists a new one will be created | |
case class Publish(postRef: PostRefs.ByPermalink, requesterRef: UserRef) extends | |
WriteAction[(PostRefs.ByPermalink, ModerationStatuses.ModerationStatus, PublicationStatuses.PublicationStatus)] { | |
// TODO: Test that this user has the permission to publish this draft | |
override def validate = requesterRef.validate ++ postRef.validate | |
def implementation = for { | |
isPublished <- PostActions.IsPublished(postRef).eval | |
p <- DraftStore.publish(postRef) |
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._ | |
import scala.collection.mutable.ArrayBuffer | |
import com.mongodb.casbah.Imports._ | |
import com.mongodb.casbah.WriteConcern | |
import akka.dispatch.Dispatchers |
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
>>> myList = [4, 3, 5, 9, 12] | |
>>> map(lambda x: x + 2, myList) | |
[6, 5, 7, 11, 14] |
OlderNewer