Skip to content

Instantly share code, notes, and snippets.

View noelwelsh's full-sized avatar
💭
Hacking on Doodle when I get time

Noel Welsh noelwelsh

💭
Hacking on Doodle when I get time
View GitHub Profile
import scalaz.{Functor, Monad}
import scalaz.std.option._
import scalaz.syntax.monad._
import scalaz.syntax.functor._
object SyntaxExamples {
// This works fine
Monad[Option].lift((x: Int) => x + 1)
// could not find implicit value for parameter F: scalaz.Functor[F]
// Type class
trait Burp[A] {
def burp(in: A): String
}
object Burp {
def apply[A](implicit burp: Burp[A]): Burp[A] = burp
}
case class Foo(name: String)
@noelwelsh
noelwelsh / Project.scala
Created March 2, 2011 14:48
Code to set the run.mode to production within WAR files.
val jettyWebPath = "src" / "main" / "webapp" / "WEB-INF" / "jetty-web.xml"
lazy val installProductionRunMode = task {
FileUtilities.copyFile("project" / "jetty-web.xml",
jettyWebPath,
log)
log.info("Copied jetty-web.xml into place")
None
} describedAs("Install a jetty-web.xml that sets the run mode to production")
@noelwelsh
noelwelsh / WellTyped.scala
Created November 7, 2015 21:02
WellTyped Programs Don't Go Wrong
sealed trait Observer[A] {
def observe(in :A): Unit =
this match {
case Map(f, o) =>
// This is completely unsound. b should be of type B, which we don't
// have available at this point. The compiler allows us to insert
// anything here, causing a runtime crash.
val b = ()
o.observe(b)
case Sink(f) =>
@noelwelsh
noelwelsh / Mixpanel.scala
Created January 22, 2013 20:38
Mixpanel API client for Play 2.0
package myna
package app
import bigtop.util.Uuid
import myna.model.external.User
import myna.util.Base64
import play.api.libs.ws._
import play.api.libs.json._
import play.api.libs.concurrent.Promise
import play.api.mvc.Request
@noelwelsh
noelwelsh / FreeInvariantMonoidal.scala
Last active January 12, 2016 17:04 — forked from Fristi/FreeInvariantMonoidal.scala
Free version of Invariant functor type class + Monoidal type class
package nl.mdj
import cats.arrow.NaturalTransformation
import cats.functor.Invariant
import cats._
import cats.syntax.all._
import scala.language.higherKinds
sealed abstract class FreeInvariant[F[_], A] extends Product with Serializable {
@noelwelsh
noelwelsh / Enum.scala
Created April 30, 2016 06:18
Attempt at extracting the names of types of the leaves of an algebraic data type
package underscoreio
package enum
import shapeless._
import shapeless.labelled._
import shapeless.syntax.singleton._
// The intention of this code is to extract the names of the types at the leaves of an algebraic data type.
// E.g. for Color at the bottom of this file,
//
@noelwelsh
noelwelsh / chatbot.scala
Last active July 28, 2016 16:02
Chat room and bots using Scalaz Stream
import scalaz.stream._
import scalaz.concurrent.Task
import scalaz.stream.async
object ChatBot {
val queue = async.boundedQueue[String](10)
val reader =
new Thread {
override def run(): Unit = {
@noelwelsh
noelwelsh / eventstream.scala
Created July 29, 2016 11:28
Pull-based event stream case study ala fs2
// Push vs pull evaluation
// Interpreters
// Reification
// Generalised algebraic data types
import java.util.concurrent.ArrayBlockingQueue
import scalaz.Applicative
import scalaz.syntax.applicative._ // for |@|
final case class Sink[A,B](source: EventStream[A], initialValue: B, f: (B, A) => B) {
def run: B = {
@noelwelsh
noelwelsh / Limerick.txt
Created December 30, 2015 22:25
Limericks for the digital age
Much software claims to scale horizontally
But don't take to these claims too wantonly
Too often things fail
To properly scale
And marketers talk irresponsibily