Skip to content

Instantly share code, notes, and snippets.

View davegurnell's full-sized avatar
🐱

Dave Pereira-Gurnell davegurnell

🐱
View GitHub Profile
@davegurnell
davegurnell / noisyactors.scala
Created May 28, 2014 15:05
Sample code: dispatching jobs to actors and retrieving the results as futures
import akka.actor._
import akka.pattern.ask
import akka.routing._
import akka.util.Timeout
import scala.concurrent._
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
object Speaker {
case class EventuallySay(phrase: String)
@davegurnell
davegurnell / macro.scala
Last active August 29, 2015 14:02
Scala macro / for comprehension issue
import scala.language.experimental.macros
import scala.reflect.macros.blackbox.Context
object PrintForMacros {
def printFor[A](expr: A): A =
macro PrintForMacros.printForMacro[A]
}
class PrintForMacros(val c: Context) {
import c.universe._
@davegurnell
davegurnell / di.sjs
Last active August 29, 2015 14:03
sweet.js macro for inserting angular.js dependency injection annotations
macro di {
case {
_(function ($args (,) ...) {
$body...
})
} => {
letstx $names... = _.map(
#{ $args... },
function(ident) {
return makeValue(ident.token.value, ident);
@davegurnell
davegurnell / ConstructorBasedDependencyInjection.scala
Last active August 29, 2015 14:05
Simple dependency injection
trait DatabaseLayer {
def dependency: Int
}
trait ConcreteDatabaseLayer extends DatabaseLayer {
def dependency: Int = 100
}
trait DatabaseResource1 {
this: DatabaseLayer =>
@davegurnell
davegurnell / PhpValue.scala
Created October 3, 2014 11:56
Idea for modelling serialized PHP data in Scala
sealed trait PhpValue {
def \(field: PhpValue): Seq[PhpValue] = Seq.empty[PhpValue]
def \\(field: PhpValue): Seq[PhpValue] = Seq.empty[PhpValue]
}
sealed trait PhpArrayLike extends PhpValue {
def fields: Map[PhpValue, PhpValue]
override def \(field: PhpValue): Seq[PhpValue] =
fields.toSeq.collect {
@davegurnell
davegurnell / publish-github.sh
Created November 11, 2014 16:46
Shell script: publish examples and solutions to github without their histories
#!/usr/bin/env bash
git checkout master
git branch -D nohistory
for branch in `git branch | cut -c2-`
do
echo "========== $branch =========="
git checkout $branch
git branch -D nohistory
@davegurnell
davegurnell / build.sbt
Created November 12, 2014 16:29
Sample build.sbt to get Play to load different configs for test and dev
lazy val chat = project.in(file(".")).enablePlugins(PlayScala)
scalaVersion in chat := "2.11.4"
libraryDependencies in chat ++= Seq(
jdbc,
anorm,
"org.postgresql" % "postgresql" % "9.3-1101-jdbc4",
"org.webjars" % "bootstrap" % "3.0.2",
"org.scalatestplus" %% "play" % "1.2.0" % "test"
@davegurnell
davegurnell / scala-dojo.scala
Created February 19, 2015 20:00
Notes on error handling and monads from London Scala Dojo on 19th February 2015
def userId(username: String): Option[Int] =
Some(1)
def mostRecentOrderId(userId: Int): Option[Int] =
Some(2)
def orderCost(orderId: Int): Option[Int] =
Some(3)
def mostRecentOrderCost(username: String): Option[Int] =
@davegurnell
davegurnell / sparknotes.md
Created March 31, 2015 16:44
Anonymised notes from the session on Spark at Scale Summit.

Spark

Group leader:

  • Building Spark app.
  • Not in production.
  • Wants to know more about how people are building apps.
  • Currently runs jobs by hand using Spark EC2 scripts. What else is available?
@davegurnell
davegurnell / build.sbt
Last active August 29, 2015 14:18
Doodle as a dependency. Create the `build.sbt` file below and type `sbt console` to start doodling. See http://underscore.io/training/courses/creative-scala for inspiration!
scalaVersion := "2.11.2"
resolvers += "Underscore Training" at "https://dl.bintray.com/underscoreio/training"
libraryDependencies += "underscoreio" %% "doodle" % "0.1.0"
initialCommands in console := """
|import doodle.core._
|import doodle.syntax._
|import doodle.jvm._