Skip to content

Instantly share code, notes, and snippets.

View danbills's full-sized avatar
🎩
-

Dan Billings danbills

🎩
-
  • Foundation Medicine
  • Marblehead, MA
View GitHub Profile
@danbills
danbills / protobuf code generator
Last active May 22, 2017 01:01
ammonite protobuf code generation example
//create run.sh w/ : cat - | amm -s compileprotobuffiledescriptor.sc
//protoc --plugin=protoc-gen-custom=run.sh --custom_out=out t.proto
import $ivy.`com.google.protobuf:protobuf-java:3.3.1`
import com.google.protobuf.compiler.PluginProtos.{CodeGeneratorRequest,CodeGeneratorResponse}
val fdp:CodeGeneratorRequest = CodeGeneratorRequest.parseFrom(System.in)
google/cloud/speech/v1/cloud_speech.proto: warning: Import google/protobuf/any.proto but not used.
google/cloud/speech/v1/cloud_speech.proto: warning: Import google/protobuf/duration.proto but not used.
fdp was Some(10)
fdp was Some(name: "google/api/http.proto"
package: "google.api"
message_type {
name: "Http"
field {
name: "rules"
number: 1
| \gTraversing Data Structures using TypeClasses
---
| \gRecap
--
Semigroup
A,A => A
associative combine function

Open the REPL and import some stuff:

Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_131).
Type in expressions for evaluation. Or try :help.

scala> import scala.concurrent._, duration._, ExecutionContext.Implicits.global
import scala.concurrent._
import duration._
import ExecutionContext.Implicits.global
@danbills
danbills / r.sc
Created June 20, 2017 01:19
Bug deriving Either decoder using generic.auto in Circe. (Run w/ Ammonite)
import $ivy.`io.circe::circe-core:0.6.1`
import $ivy.`io.circe::circe-generic:0.6.1`
import $ivy.`io.circe::circe-parser:0.6.1`
import io.circe._
import io.circe.syntax._
import io.circe.parser._
import io.circe.generic.auto._
@danbills
danbills / corenlp.sc
Created June 26, 2017 02:07
Ammonite script to run CoreNLP embedded
import $ivy.`edu.stanford.nlp:stanford-corenlp:3.8.0`
import edu.stanford.nlp.pipeline._
import edu.stanford.nlp.ling.CoreAnnotations._
import edu.stanford.nlp.trees.TreeCoreAnnotations._
import java.util._
import scala.collection.JavaConverters._
@danbills
danbills / enumeratum_circe.scala
Created July 7, 2017 14:30
enumeratum decoder
import enumeratum._
import io.circe.Printer
import io.circe.parser._
import io.circe.syntax._
import org.scalatest.prop.TableDrivenPropertyChecks
import org.scalatest.{EitherValues, FlatSpec, Matchers}
import scala.collection.immutable.IndexedSeq
object foo {
@danbills
danbills / salad.scala
Created August 14, 2017 11:51
using ammonite and cwltool to preprocess CWL
package wdl4s.cwl.other
import ammonite.ops._
import ammonite.ops.ImplicitWd._
import lenthall.validation.ErrorOr.ErrorOr
import wdl4s.cwl.{CwlCodecs, CwlFile}
object Salad extends App{
@danbills
danbills / swt.sc
Last active September 2, 2017 17:48
run SWT GUI based on current OS
//IMPORTANT
//to run on mac use JAVA_OPTS="-XstartOnFirstThread" amm -w swt.sc
interp.repositories() ++= Seq(coursier.maven.MavenRepository(
"http://maven-eclipse.github.io/maven/"))
import $ivy.`org.clapper::grizzled-scala:4.4.1`
import $ivy.`org.fusesource:sigar:1.6.4`
import grizzled.sys._
How many times have you used a JSON/ REST service? Did you enjoy it?
How many times have you written JSON decoders on top of an HTTP server?
Ever wish there was an API in your language of choice?
There happens to be a pretty nice solution to these issues.
With the gRPC/protocol buffers system by Google we specify rich types and a
service , then it generates a client and a skeleton server in over 10 languages.