Skip to content

Instantly share code, notes, and snippets.

Avatar

matanster

  • Israel
View GitHub Profile
@matanster
matanster / util.py
Last active Sep 28, 2018
example of sampling from a distribution vector
View util.py
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]
View Edit Distance Correctness test
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
@matanster
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 (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 =>
@matanster
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 http://stackoverflow.com/questions/33291071/invoking-a-subprojects-main-with-a-custom-task
)
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
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.