Skip to content

Instantly share code, notes, and snippets.

View davegurnell's full-sized avatar
🐱

Dave Pereira-Gurnell davegurnell

🐱
View GitHub Profile
@davegurnell
davegurnell / ApplicationComponents.scala
Created January 27, 2017 10:15
Rough Play manual DI example. Note I haven't compiled this, so it's probably full of typos and broken imports.
package startup
import controllers._
import services._
import akka.actor.ActorSystem
import play.api.ApplicationLoader.Context
import play.api.libs.ws.ahc._
import play.api.routing.Router
import play.api._
import play.api.mvc.EssentialFilter
@davegurnell
davegurnell / shapeless-getters.scala
Created December 10, 2016 15:52
shapeless getters
import shapeless._
import shapeless.labelled._
final case class Employee(
name : String,
number : Int,
manager : Boolean
)
final case class IceCream(
import shapeless._
// Given this poly:
object myPoly extends Poly1 {
implicit val intCase: Case.Aux[Int, Double] =
at[Int](num => num / 2.0)
implicit val stringCase: Case.Aux[String, Int] =
at[String](str => str.length)
}
#!/usr/bin/env amm
load.ivy("org.typelevel" %% "cats" % "0.7.0")
@
import cats.{Id, ~>}
import cats.data.State
import cats.free._
import cats.free.Free._
@davegurnell
davegurnell / chainjsoncalls.scala
Created September 3, 2016 12:36
Snippet for a conversation in the Cats Gitter channel
import scala.annotation.tailrec
import scala.concurrent.{ ExecutionContext => EC, _ }
trait Json // whatever JSON type you're using
def getJson(url: String)(implicit ec: EC): Future[Json] =
??? // whatever implementation you currently have
def getNextUrlFromJson(json: Json): Option[String] =
??? // whatever implementation you currently have
sbt.version=0.13.13-M1
@davegurnell
davegurnell / CsvEncoder.scala
Created August 30, 2016 18:43
shapeless lazy example
import shapeless._
trait CsvEncoder[A] {
def encode(value: A): List[String]
}
object CsvEncoder {
def apply[A](implicit encoder: CsvEncoder[A]): CsvEncoder[A] =
encoder
@davegurnell
davegurnell / htgrep.sh
Last active May 24, 2016 10:26
Handy grep wrappers
#!/usr/bin/env bash
find . \( -name \*.jsx\? -or -name \*.coffee -or -name \*.css -or -name \*.less -or -name \*.shtml\? -or -name \*.html\? -or -name \*.php -or -name \*.asp \) -not -path \*.git\* -not -path \*.svn\* -not -path \*compiled\* -not -path \*target\* -exec egrep -H "$1" {} \;
@davegurnell
davegurnell / quickstart.sh
Last active May 13, 2016 10:18
Quick start shell script for SBT on OS X.
# Install SBT if you need to:
brew install sbt
# Make a directory for your project:
mkdir MYAPP
cd MYAPP
# Basic project directory structure:
mkdir -p project
mkdir -p src/main/scala
@davegurnell
davegurnell / json.scala
Created May 12, 2016 15:19
JsonWriter type class demo
// Scala script: run with "scala json.scala"
// JSON Library ---------------------------------
sealed trait JsValue {
def stringify: String = this match {
case JsNull => "null"
case JsString(value) => "\"" + value + "\""
case JsNumber(value) => value.toString
case JsBoolean(value) => value.toString