Skip to content

Instantly share code, notes, and snippets.

@dokwork
dokwork / ScalaPbArbitrary.scala
Last active July 3, 2019 15:15
Derivation of the org.scalacheck.Arbitrary for case classes which was generated by the scalapb
// libraryDependencies += "com.github.alexarchambault" %% "scalacheck-shapeless_1.14" % "1.2.0"
// libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.14.0"
// libraryDependencies += "com.thesamet.scalapb" %% "scalapb-runtime" % "0.8.4"
import org.scalacheck.{ Arbitrary, Gen, ScalacheckShapeless }
import scalapb.{ GeneratedEnum, GeneratedEnumCompanion, TypeMapper }
/**
* Derives `or.scalacheck.Arbitrary` for generated by `scalapb` classes.
*
import java.util.concurrent.atomic.{ AtomicBoolean, AtomicReference }
import scala.concurrent.ExecutionContext
class Node[A](var a: A = null.asInstanceOf[A]) extends AtomicReference[Node[A]] {
def next: Node[A] = get()
def next_=(n: Node[A]): Unit = lazySet(n)
}
class MPSCQueue[A] {
@dokwork
dokwork / IDEA Code Style
Last active December 1, 2017 08:35
To import: File →Settings → Editor →Code Style → Scala →Scheme: Import Scheme
<code_scheme name="Dokwork Scala Style">
<option name="OTHER_INDENT_OPTIONS">
<value>
<option name="INDENT_SIZE" value="2" />
<option name="CONTINUATION_INDENT_SIZE" value="8" />
<option name="TAB_SIZE" value="2" />
<option name="USE_TAB_CHARACTER" value="false" />
<option name="SMART_TABS" value="false" />
<option name="LABEL_INDENT_SIZE" value="0" />
<option name="LABEL_INDENT_ABSOLUTE" value="false" />
@dokwork
dokwork / Json.scala
Last active June 30, 2017 12:50
Simple Json matcher for scalatest. Requared json4s.
import org.json4s.JsonAST.JObject
import org.json4s.native.JsonMethods._
import org.json4s.native.Serialization.write
import org.json4s.{ DefaultFormats, Diff, Formats, JValue }
import org.scalatest.matchers._
import org.scalatest.{ FreeSpec, Matchers }
object Json {
def apply(right: String)(implicit formats: Formats): BeMatcher[String] =
function encode64(data) {
r = "";
for (i=0; i<data.length; i+=3) {
if (i+2==data.length) {
r +=append3bytes(data.charCodeAt(i), data.charCodeAt(i+1), 0);
} else if (i+1==data.length) {
r += append3bytes(data.charCodeAt(i), 0, 0);
} else {
r += append3bytes(data.charCodeAt(i), data.charCodeAt(i+1), data.charCodeAt(i+2));
}