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 sample_from_distribution(distribution_vector): | |
''' samples from a provided distribution (e.g. for choosing an action from a VW returned distribution vector) ''' | |
probabilities = list(map(float, distribution_vector)) | |
actions = range(1,len(distribution_vector)+1) # VW actions are 1-indexed not zero indexed | |
assert(len(actions) == len(probabilities)) | |
s = choices(actions, probabilities) # https://docs.python.org/3/library/random.html#random.choices | |
action = s[0] |
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 WeightedWagnerFischerTest extends App { | |
/* currently tests for the default weights */ | |
val externalLibraryImpl = new info.debatty.java.stringsimilarity.Levenshtein | |
val random = new scala.util.Random(333) // pin down random seed | |
def randomString(length: Int) = random.alphanumeric.take(length).mkString | |
def randomPair(length: Int, maxTouches: Int): (String, String) = { | |
val string1 = randomString(length).toCharArray | |
var string2 = string1.clone |
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
/* | |
* parses the link header field (http://tools.ietf.org/html/rfc5988) returned by Github's api | |
* (c.f. https://developer.github.com/guides/traversing-with-pagination/) | |
*/ | |
trait GithubLinkHeader { | |
def parse(linkHeader: IndexedSeq[String]): Map[String, String] = { | |
assert(linkHeader.size == 1) | |
linkHeader.head.split(',').map { linkEntry => |
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 integrationTest = taskKey[Unit]("Executes integration tests.") | |
lazy val root = (project in file(".")).aggregate(simpleGraph, compilerPluginUnitTestLib, compilerPluginn, canveSbtPlugin, sbtPluginTestLib).enablePlugins(CrossPerProjectPlugin).settings( | |
scalaVersion := "2.11.7", | |
crossScalaVersions := Seq("2.10.4", "2.11.7"), | |
publishArtifact := false, // no artifact to publish for the virtual root project | |
integrationTest := (run in Compile in sbtPluginTestLib).value // not working: need to bounty http://stackoverflow.com/questions/33291071/invoking-a-subprojects-main-with-a-custom-task | |
) | |
lazy val simpleGraph = (project in file("simpleGraph")) |
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
libraryDependencies ++= Seq( | |
"com.typesafe.slick" %% "slick" % "3.0.0-RC2", | |
"com.zaxxer" % "HikariCP-java6" % "2.0.1", // HikariCP is the unofficial default connection pooling library for slick | |
"org.slf4j" % "slf4j-nop" % "1.6.4") | |
libraryDependencies += "mysql" % "mysql-connector-java" % "latest.release" |
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
// | |
// SBT task for slick code generation for a live database | |
// ====================================================== | |
// | |
// This sbt task will generate slick scala classes to match your (MySQL) database schema, | |
// which will allow you to use the database through slick, in your scala application. | |
// | |
// Usage: Review all ? symbols and comments below, to adapt to your system. Embed in build.sbt. | |
// Make sure the database is up. Run: sbt slickGenerate | |
// In your scala application, import the resulting scala file |