Skip to content

Instantly share code, notes, and snippets.



  • Israel
View GitHub Profile
matanster /
Last active Sep 28, 2018
example of sampling from a distribution vector
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) #
action = s[0]
View Edit Distance Correctness test
object WeightedWagnerFischerTest extends App {
/* currently tests for the default weights */
val externalLibraryImpl = new
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
matanster / GithubHelper.scala
Last active Dec 29, 2015 — forked from guizmaii/GithubHelper.scala
Helper object parsing the "Link" header of the Github API v3, in Scala
View GithubHelper.scala
* parses the link header field ( returned by Github's api
* (c.f.
trait GithubLinkHeader {
def parse(linkHeader: IndexedSeq[String]): Map[String, String] = {
assert(linkHeader.size == 1)
linkHeader.head.split(',').map { linkEntry =>
matanster / build.sbt
Created Oct 23, 2015
multi-project sbt build definition, involving dependent compiler and sbt plugins
View build.sbt
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
lazy val simpleGraph = (project in file("simpleGraph"))
View Sample SBT configuration for Slick 3.0.0 and MySQL
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"
matanster / Slick 3.0.0 code generation
Last active Apr 13, 2018
SBT task for slick code generation from a live database
View Slick 3.0.0 code generation
// 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
You can’t perform that action at this time.