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
@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) {
[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/
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 }
}
@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)
@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 / PrevaylerJr.scala
Created April 6, 2012 20:01
PrevaylerJr in Scala
import java.io._
class PrevaylerJr[T <: Serializable](initialState: T, pStorageFile: File) {
private val storageFile = new File(pStorageFile.getAbsolutePath + ".tmp")
private val system = {
val fileToRead = if (pStorageFile.exists) pStorageFile else storageFile
if (fileToRead.exists) {
val input = new ObjectInputStream(new FileInputStream(fileToRead))
@fwbrasil
fwbrasil / Nolan.scala
Created September 4, 2012 12:23
Nolan test...
package nolan
import net.fwbrasil.activate.ActivateContext
import net.fwbrasil.activate.migration.Migration
import net.fwbrasil.activate.storage.mongo.MongoStorage
object MongoContext extends ActivateContext {
def contextName = "mongoContext"
val storage = new MongoStorage {
override val authentication = Option(("activate_test", "activate_test"))
@fwbrasil
fwbrasil / gist:3783157
Created September 25, 2012 17:02
Subtrate rest
trait Person extends Entity {
var name: String
def nameAsUpperCase =
name.toUpperCase
}
object Person {
def personsWhereNameStartsWith(string: String) =
select[Person] where (_.name like string + "%")
}
class NaturalPerson(var name: String, var motherName: String) extends Person {
@fwbrasil
fwbrasil / ActivateGraph.scala
Created November 22, 2012 17:06
Activate graph database support spike
package com.example.foo
import activateExampleContext._
class Person(
var name: String)
extends Vertex
class Knows(
val from: Person,
package net.fwbrasil.sReflection
object CascadeImplicits {
implicit def toYourself[T](value: T): Yourself[T] = new Yourself(value)
implicit def toCascade[T](value: T): Cascade[T] = new Cascade(value)
class Yourself[T](value: T) {
def yourself = value
}