Skip to content

Instantly share code, notes, and snippets.

View markhibberd's full-sized avatar

markhibberd markhibberd

View GitHub Profile
@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._
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"))
}
}
@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) ⇒
@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

Installation

FreeBSD

portmaster irc/irssi
portmaster irc/irssi-xmpp

OS X

brew install irssi

@purefn
purefn / gist:5257660
Last active December 15, 2015 12:08
// This character generator is similar to the default one from ScalaCheck, but it filters out:
// 1. Unprintable control characters. These cause problems in Mongo queries, and should not able
// to get into our database since they will not be present in inputs parsed from HTTP text.
// 2. Characters that do not exist in the default platform encoding. We can exclude a big range
// of these right away (which ScalaCheck does) because they're in the range used for two-
// character UTF-16 sequences, but others are only detected by checking Character.isDefined(_).
// The symptom of using a bad character in a string is that when you encode it to UTF-8 and
// back again, you get a different string, so any of our web and database tests that check the
// input against the output may fail-- and you'll see a question mark somewhere in the data,
// since that's how bad characters are displayed.
case class Utf8String(value: String)
object Utf8String {
implicit val ArbitraryUtf8String: Arbitrary[Utf8String] =
Arbitrary(arbitrary[String] map (k =>
Utf8String(k filter (c => c < '\ud800' || c > '\udfff'))))
}
@vmarquez
vmarquez / BrokenFor.scala
Last active December 14, 2015 15:18
Broken Scala For Comprehension
package vsxmpp
import scalaz.EitherT
import scalaz._
import Scalaz._
case class ABC(s:String)
object ABC {
@cfreeman
cfreeman / gist:5105473
Last active January 16, 2016 07:41
Cheat sheet for getting started with chef.

Chef Cheat sheet

Configuring Chef

To install stuff needed to run chef in a solo mode (Small one or two server configuration):

gem install knife-solo

To setup chef after it has been installed:

@markhibberd
markhibberd / scala-2.10.0-match-on-nothing
Created February 4, 2013 09:51
Pattern matching on `Nothing`
Welcome to Scala version 2.10.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_37).
Type in expressions to have them evaluated.
Type :help for more information.
scala> val x: Option[Nothing] = None
x: Option[Nothing] = None
scala> x match {
| case Some(a) => a
| case None => None