Skip to content

Instantly share code, notes, and snippets.

View andypetrella's full-sized avatar

Andy Petrella andypetrella

View GitHub Profile
@andypetrella
andypetrella / SparkAkka.scala
Last active December 20, 2015 22:39
Spark-bd blog entries
package spark
import spark.util.AkkaUtils
object SparkAkka {
private[this] lazy val config = be.bigdata.p2.conf.root.getConfig("deploy.akka")
lazy val name = config.getString("name")
lazy val host = config.getString("host")
lazy val port = config.getInt("port")
lazy val actorSystem = AkkaUtils.createActorSystem(name, host, port)._1
@andypetrella
andypetrella / conway.scala
Created August 7, 2013 06:10
Game of Life (Conway) in scala
object conway {
def neighbours(p:(Int, Int)) =
for {
dx <- List(-1, 0, 1)
dy <- if (dx == 0) List(-1, 1) else List(-1, 0, 1)
} yield (dx+p._1, dy+p._2)
def step(cells:List[(Int, Int)]) =
cells
@andypetrella
andypetrella / Co.scala
Last active December 19, 2015 17:59
Co-Contra variance in Scala
package cocontra
import model._
object Co extends App {
val kids = List(new Kid(9))
val humans:List[Human] = kids
println(humans)
@andypetrella
andypetrella / mat.scala
Last active December 17, 2015 22:49
Matrix Algebra and type level programming ~> compile time checks?
/*
First implementation of a Matrix String Interpolator.
This is a manipulable matrix strucutre
mat"""
| 1 | 2
| 3 |
"""
*/
object Mat {
@andypetrella
andypetrella / whishlist.txt
Last active December 15, 2015 09:19
My tech projects wish (I have time) list
* create a Neo4j Rest API on WebShell
* create a macro that will check cypher queries
* import TopoJSON in Neo4J, probably using org.neo4j.gis.spatial.pipes.GeoPipeFlow like org.neo4j.gis.spatial.pipes.processing.GeoJSON does
@andypetrella
andypetrella / crap.scala
Created March 6, 2013 08:37
Swithc to Play 2.1 in a quick and dirty fashion... at least for json
import play.api.libs.json._
//this is crap but ease a lot the switch to play 2.1
implicit def smashThat[A](js:JsResult[A]):A = js.recoverTotal { err => throw new RuntimeException(Json.stringify(JsError.toFlatJson(err))) }
val j = Json.obj("a"->1, "b"->2)
val m:Map[String, Int] = Json.fromJson[Map[String, Int]](j)
@andypetrella
andypetrella / test.scala
Created March 3, 2013 13:45
DuckTyping.scala
package test
object Template {
case object A {
def apply(i:Int) = "A " + i
}
case object B {
def apply() = "B"
@andypetrella
andypetrella / Covariant.scala
Created February 2, 2013 16:27
Co&ContraVariance in Scala (and not Java)
object Covariant extends App {
trait Vehicle {
def name:String
def velocity:Float
}
case class Car(name:String, velocity:Float) extends Vehicle
object VehiculeStats {
def meanVelocity(vs:List[Vehicle]):Float =
@andypetrella
andypetrella / main.scala
Last active December 11, 2015 23:39
Another try to define Model with Id, crud and so on. But using Type Classes rather than self type and recursive type definition
package tc
object Main extends App {
import tc.Action._
import tc.Generator._
import tc.User._
// a user
val user = User(None, "noootsab", true, 31)
println(s"User $user")
@andypetrella
andypetrella / sample-dsl.scala
Last active December 11, 2015 04:18
Un exemple de DSL très simple avec Scala
case class Banque(nom:String) {banque =>
def accepte(m:Montant) =
CompteBuilder(banque, m)
}
implicit def stringToBanque(s:String) = Banque(s)
implicit def intWithDevise(i:Int) = new {