Skip to content

Instantly share code, notes, and snippets.

View markhibberd's full-sized avatar

markhibberd markhibberd

View GitHub Profile
@tonymorris
tonymorris / gist:5367920
Created April 11, 2013 23:03
The z in scalaz
The z in scalaz means this: it was early 2008 and I was working for a Java consultancy and so of course, I used the most appropriate tool for the job: scala. But it had *terrible* libraries, so I offered to fix those while also meeting my other objectives. Turns out that the Scala guys were extremely hostile to even half-decent libraries (and still are to this day). I still struggle to wrap my head around this sometimes.
Anyway, so I thought, well fuck it, I will just keep them to myself for now. My (awesome) employer had already agreed that we'd probably open-source such a thing, but I was concerned most about my primary goal. So then it came time to "name" this library. I had named it "scalax" simply so that I did not have the inclination to think of a proper name. Then I found out that such a library was being developed and with my internal name! Whatever, I thought.
So I looked at this scalax library, hoping that I could just abandon my efforts and jump on board with everyone else -- they too had figure
@YoEight
YoEight / conversion.scala
Last active December 18, 2015 01:48
Scala-machines Machine to Play Enumerator
import com.clarifi.machines._
import play.api.libs.iteratee.{ Enumerator, Input, Iteratee }
import play.api.libs.concurrent.Execution.Implicits._
import scala.concurrent.Future
def simple[K, E](machine: Machine[K, E]): Enumerator[E] = new Enumerator[E] {
def apply[A](start: Iteratee[E, A]): Future[Iteratee[E, A]] =
val result = machine.foldLeft(Future.successful(start)) { (future, value) ⇒
object ArgonautPlay {
implicit val writeableJson: Writeable[Json] = {
// TODO this should explicitly be a UTF-8 encoder
val stringWriter = implicitly[Writeable[String]].transform
Writeable((a: Json) => stringWriter(a.spaces2), Some("application/json; charset=utf-8"))
}
}
@milessabin
milessabin / gist:6081113
Last active December 20, 2015 05:49
Slicing and dicing tuples in shapeless 2.0.0-SNAPSHOT.
Welcome to Scala version 2.10.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_21).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import shapeless._
import shapeless._
scala> import syntax.tuple._
import syntax.tuple._
@markhibberd
markhibberd / Setup.hs
Last active December 20, 2015 09:59
Generating runtime source at build step.
#!/usr/bin/env runhaskell
import Data.Time (formatTime, getCurrentTime)
import Data.List (intercalate)
import Distribution.PackageDescription
import Distribution.Verbosity
import Distribution.Simple
import Distribution.Simple.Setup (BuildFlags(..), fromFlag)
import Distribution.Simple.LocalBuildInfo
trait Functor {
type M <: { type T }
def fmap[A, B](fa: M { type T = A })(f: A => B): M { type T = B }
}
implicit class EitherRightFunctor extends Functor { self =>
type L
type M = Either { type A = self.L ; type T = B } //doesn't this specify a subtype of Either, rather than Either itself?
def fmap[A0, B0](fa: M { type A = self.L ; type B = A0 })(f: A0 => B0): Either { type A = self.L ; type B = B0 } =
@etorreborre
etorreborre / stackedAround.scala
Created October 23, 2013 04:08
Stack Around contexts
import org.specs2._
import matcher._
import execute._
import specification._
// the "larger" context must be mixed-in last
class MySpec extends mutable.Specification with Db with Web {
// prints
// on the web
// in the db
[info] benchmark us linear runtime
[info] example 47.3 =
[info] integers 89.2 ==
[info] jp10 180.6 ====
[info] jp100 1089.3 =========================
[info] jp50 585.0 =============
[info] numbers 363.8 ========
[info] twitter1 15.4 =
[info] twitter10 96.8 ==
[info] twitter100 936.2 =====================
#!/usr/bin/ruby
# Create display override file to force Mac OS X to use RGB mode for Display
# see http://embdev.net/topic/284710
require 'base64'
data=`ioreg -l -d0 -w 0 -r -c AppleDisplay`
edids=data.scan(/IODisplayEDID.*?<([a-z0-9]+)>/i).flatten
vendorids=data.scan(/DisplayVendorID.*?([0-9]+)/i).flatten
@tonymorris
tonymorris / scalaz.scala
Created January 5, 2014 01:16
Questions about \/ and Validation
// Questions about \/ and Validation
object scalaz {
/*
This explanation might help. This is a compilable source file with revisions
available at https://gist.github.com/tonymorris/8263051
Fact: All monads are applicative functors. As has been seen we can witness the
`Applicative` that arises from the `Monad` primitives. Let's illustrate this: