Skip to content

Instantly share code, notes, and snippets.

View ochrons's full-sized avatar

Otto Chrons ochrons

View GitHub Profile
@ochrons
ochrons / gist:10681050
Last active March 26, 2018 15:21
Super thin Scala wrapper for common DataStax Cassandra Java driver functionality.
object CassandraWrapper {
import scala.language.implicitConversions
import scala.language.postfixOps
/**
* Converts a `ResultSetFuture` into a Scala `Future[ResultSet]`
* @param f ResultSetFuture to convert
* @return Converted Future
*/
implicit def resultSetFutureToScala(f: ResultSetFuture): Future[ResultSet] = {
val p = Promise[ResultSet]()
@ochrons
ochrons / browserChrome.txt
Created October 29, 2015 20:44
Scala/ScalaJS serialization lib performance comparison
1/18 : Encode single Seq[Int]
=============================
Library ops/s % size % size.gz %
BooPickle 146324 8.4% 2 100% 32 100%
Prickle 231064 13.2% 27 1350% 58 181%
uPickle 245188 14.1% 3 150% 35 109%
Circe 962996 55.2% 3 150% 35 109%
Pushka 1744486 100.0% 3 150% 35 109%
2/18 : Decode single Seq[Int]
class ZipModelR[M, S, SS](root: ModelR[M, M], get1: M => S, get2: M => SS)(implicit cts: ClassTag[S], ctss: ClassTag[SS]) extends ModelR[M, (S, SS)] {
private var zipped = Tuple2[S, SS](null.asInstanceOf[S], null.asInstanceOf[SS])
// ZipModel uses optimized `get` functions to compare if the contents of the tuple has changed or not
// Different comparison functions are used for boxed values and real references
private def getXX(compS: (S, S) => Boolean, compSS: (SS, SS) => Boolean)(model: M) = {
// check if inner references have changed
val v1 = get1(root.value)
val v2 = get2(root.value)
if (compS(zipped._1, v1) || compSS(zipped._2, v2)) {
@ochrons
ochrons / Osc.scala
Last active April 14, 2018 14:13 — forked from anonymous/SierpinskiTriangle.scala
ScalaFiddle gist
import math._
val (h, w) = (Page.canvas.height, Page.canvas.width)
var x = 0.0
// $FiddleStart
val graphs = Seq[(String, Double => Double)](
("red", sin),
("green", x => 2 - abs(x % 8 - 4)),
("blue", x => 3 * pow(sin(x / 12), 2) * sin(x))
)
// $FiddleEnd
@ochrons
ochrons / gitter.css
Created February 22, 2016 18:36
Custom CSS theme for Gitter
.room-list-item__unread-badge {
color: black;
}
pre code {
text-rendering: optimizeLegibility;
font-family: Hasklig, monospace;
}
import scala.tools.nsc.interactive, scala.tools.nsc.reporters._, scala.tools.nsc._
object Test {
def main(args: Array[String]): Unit = {
val reporter = new StoreReporter
val s = new Settings()
s.processArgumentString("-Ypresentation-any-thread")
val global = new interactive.Global(s, reporter)
import global._
val Cursor = ""//"_DUMMY_ "
@ochrons
ochrons / ScalaFiddle.scala
Last active April 25, 2016 20:41
Hilber curve demonstration in ScalaFiddle
// $FiddleDependency org.scala-js %%% scalajs-dom % 0.9.0
// $FiddleDependency com.lihaoyi %%% scalatags % 0.5.4
import scalatags.JsDom.all._
import org.scalajs.dom
import fiddle.Fiddle, Fiddle.println
import scalajs.js
object ScalaFiddle extends js.JSApp {
def main() = {
// $FiddleStart
import com.amazonaws.HttpMethod
import com.amazonaws.services.s3.AmazonS3Client
import com.amazonaws.services.s3.model._
...
val s3Client = new AmazonS3Client
private def getFlow(pathRaw: String, method: HttpMethod) = {
// clean the path
val path = pathRaw.dropWhile(_ == '/').trim
@ochrons
ochrons / WorkerMain.scala
Created May 25, 2016 19:59
Web Worker PoC in Scala.js
package poc
import org.scalajs.dom
import scala.scalajs.js
import scala.scalajs.js.annotation.JSExport
@js.native
object WorkerGlobal extends js.GlobalScope {
def addEventListener(`type`: String, f: js.Function): Unit = js.native
"Macau",
"Macedonia",
"Madagascar",
"Malawi",
"Malaysia",
"Maldives",
"Mali",
"Malta",
"Marshall Islands",
"Mauritania",