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
class A | |
def my_class; self.class.name end | |
end | |
class B < A | |
end |
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
{ | |
"by_tank": { | |
"bison_i": [3, 5], | |
"t2_lt": [2, 4], | |
"m3_stuart_ll": [3, 4], | |
"bt-sv": [3, 4], | |
"pzii_j": [3, 4], | |
"t-127": [3, 4], | |
"t-50": [5, 9], | |
"vk1602": [5, 9], |
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 java.io.File | |
import scala.collection.JavaConversions._ | |
import org.jsoup.Jsoup | |
import org.jsoup.nodes.Element | |
object ParseVehicleData extends App { | |
val baseURL = "http://worldoftanks.com" | |
val categories = Map( | |
"Light Tanks" -> "lt", |
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
case class Parameters(userId: UserId, | |
device: Option[Device] = None, | |
additionalParameters: Map[String, Iterable[String]] = Map.empty) { | |
def getParameter[T](name: String, default: T)(implicit converter: (Iterable[String]) => Option[T]): T = { | |
additionalParameters.get(name).flatMap(converter).getOrElse(default) | |
} | |
} | |
object Parameters { | |
implicit val strings2Int = (values: Iterable[String]) => { |
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
val mimeTypeIsPdf = candidate.mimeType match { | |
case None => false | |
case Some(candidateMimeType) => candidateMimeType.equalsIgnoreCase(MimeTypes.PDF) | |
} | |
val urlHasPdfExtension = candidate.uri match { | |
case None => true | |
LowerCase().endsWith(FileExtensions.PDF) | |
} |
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 titleScore(titleWords: Array[String], sentence: Array[String]) = | |
sentence.count(w => !stopWords.contains(w) && titleWords.contains(w)) / titleWords.size.toDouble |
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 Primes extends App { | |
val primes: Stream[Int] = | |
2 #:: Stream.from(3, 2).filter(i => primes.takeWhile(p => p * p <= i).forall(p => i % p > 0)) | |
println(primes.take(10).toList) // List(2, 3, 5, 7, 11, 13, 17, 19, 23, 29) | |
} |
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
trait EntityBase { | |
def id: String | |
} | |
trait Repository { | |
type Entity <: EntityBase | |
def get(id: String): Option[Entity] | |
} |
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 Dijkstra { | |
case class Edge[T](node: T, cost: Double) | |
case class Path[T](nodes: List[T], cost: Double) | |
type Graph[T] = Map[T, List[Edge[T]]] | |
def dijkstra[T](graph: Graph[T], paths: List[Path[T]], dest: T, visited: Set[T]): Option[Path[T]] = { | |
def unvisitedPaths(node: T, path: Path[T]): List[Path[T]] = | |
graph(node).filterNot(edge => visited.contains(edge.node)) | |
.map(edge => Path(edge.node +: path.nodes, path.cost + edge.cost)) |
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 EveRouting extends App { | |
import EveMap.{SolarSystem, SolarSystemJump, loadSystems, loadJumps} | |
import scalax.collection.immutable.Graph | |
import scalax.collection.GraphPredef._, scalax.collection.GraphEdge._ | |
import scalax.collection.edge.Implicits._ | |
// Load the EVE map | |
val systems: List[SolarSystem] = loadSystems | |
val jumps: List[SolarSystemJump] = loadJumps |
OlderNewer