Skip to content

Instantly share code, notes, and snippets.

View fwbrasil's full-sized avatar

Flavio Brasil fwbrasil

  • Nubank
  • San Francisco Bay Area, California
View GitHub Profile
# Requirement: the project must be on Scala 2.12.3
# Step 1 - Add the scalafix sbt plugin
echo 'addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.5.0-M4")' >> projecs/plugins.sbt
# Step 2 (MANUAL) - Add the traneio Scala Future dependency to the sbt build
# resolvers += Resolver.sonatypeRepo("snapshots")
# libraryDependencies += "io.trane" % "future-scala" % "0.2.3-SNAPSHOT"
# Step 2 - Run the scalafix rewrite
package fix
import scalafix._
import scala.meta._
case class ReplaceSymbols(sctx: SemanticCtx) extends SemanticRewrite(sctx) {
def rewrite(ctx: RewriteCtx): Patch =
ctx.replaceSymbols(
"scala.concurrent.Await" -> "io.trane.future.scala.Await",
@fwbrasil
fwbrasil / gist:2db2b6ac2b86fe820442
Last active September 10, 2015 08:47
Monadic joins to SQL
t1.flatMap(a => t2.filter(b => b.s == a.s).map(b => b.s))
SELECT t2.s FROM t1, t2 WHERE t2.s = t1.s
t1.flatMap(a => t2.map(b => b.s).take(10))
SELECT x.s FROM t1, (SELECT * FROM t2 LIMIT 10) x
t1.flatMap(a => t2.filter(b => b.s == a.s).map(b => b.s).take(10))
@fwbrasil
fwbrasil / transcript
Last active August 29, 2015 14:16 — forked from paulp/transcript
scala> class Bippy(xs: List[Int]) extends improving.TypesafeProxy(xs) { def isEmpty = true }
defined class Bippy
scala> val bippy = new Bippy(1 to 10 toList)
bippy: Bippy = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
scala> bippy.slice(3, 7)
[proxy] $line4.$read.$iw.$iw.bippy.slice(3, 7)
res1: List[Int] = List(4, 5, 6, 7)
object Demo {
// A couple of type classes with type members ...
trait Foo[T] {
type A
}
object Foo {
implicit val fooIS = new Foo[Int] { type A = String }
}
[warn] The global sbt directory is now versioned and is located at /Users/flavio/.sbt/0.13.
[warn] You are seeing this warning because there is global configuration in /Users/flavio/.sbt but not in /Users/flavio/.sbt/0.13.
[warn] The global sbt directory may be changed via the sbt.global.base system property.
[info] Loading project definition from /Users/flavio/workspace/Activate_benchmark/project
[info] Set current project to Activate_benchmark (in build file:/Users/flavio/workspace/Activate_benchmark/)
> run
[info] Compiling 1 Scala source to /Users/flavio/workspace/Activate_benchmark/target/scala-2.11/classes...
[info] Running activate.ActivateBenchMark
09:27:43.191 [run-main-0] DEBUG org.reflections.Reflections - going to scan these urls:
file:/Users/flavio/workspace/Activate_benchmark/target/scala-2.11/classes/
@fwbrasil
fwbrasil / gist:9582504
Created March 16, 2014 12:29
TypeTag issue
import scala.reflect.runtime.universe._
object Main extends App {
trait SomeTrait
def doSomething[T: TypeTag] =
typeTag[T].tpe
val threads = List.fill(100) {
@fwbrasil
fwbrasil / FutureBridge.scala
Created January 14, 2014 13:11
Scala <=> Twitter Future Bridge
import scala.concurrent.ExecutionContext
import scala.concurrent.{ Future => ScalaFuture }
import scala.concurrent.{ Promise => ScalaPromise }
import scala.util.Failure
import scala.util.Success
import com.twitter.util.{ Future => TwitterFuture }
import com.twitter.util.{ Promise => TwitterPromise }
object FutureBridge {
@fwbrasil
fwbrasil / gist:7216591
Created October 29, 2013 15:16
mac console
localhost:FrameworkBenchmarks fwbrasil$ toolset/run-tests.py -u fwbrasil --test play-activate-mysql play-scala play-slick play-scala-mongodb -i /Users/fwbrasil/.ssh/id_rsa --max-threads 5 --max-concurrency 16 --duration 1
WARNING:root:results.json for test ec2 not found.
=====================================================
Preparing Server, Database, and Client ...
=====================================================
bash: line 0: cd: /sys/devices/system/cpu: No such file or directory
ls: cpu*: No such file or directory
net: class is not implemented
@fwbrasil
fwbrasil / gist:7135401
Created October 24, 2013 11:18
play-scala-mongodb error
=====================================================
Beginning play-scala-mongodb
-----------------------------------------------------
-----------------------------------------------------
Starting play-scala-mongodb
-----------------------------------------------------
sudo: no tty present and no askpass program specified