Skip to content

Instantly share code, notes, and snippets.

@ndmitchell
ndmitchell / GCHQ.hs
Created December 21, 2015 20:59
GCHQ 2015 Puzzle in Haskell
module Main(main) where
import Data.Maybe
import Data.List
-- Data table copied from https://matthewearl.github.io/2015/12/10/gchq-xmas-card/
width = 25
height = 25
rows = [
@paulp
paulp / braces.scala
Last active August 29, 2015 14:25
parens vs. braces
scala> case class Foo(x: Int = -12345)
defined class Foo
scala> def y = 5
y: Int
scala> val x = Foo(y)
x: Foo = Foo(5)
scala> val x = Foo{y}
@etorreborre
etorreborre / short_implicitly.scala
Created November 26, 2014 22:55
Short implicitly form
// for a given typeclass
trait CharIso[T] {
def toChar(t: T): Char
def fromChar(c: Char): T
}
// provide the following apply method
// so that you can write: CharIso[T].toChar(...) instead of implicitly[CharIso[T]].toChar(...)
object CharIso {
def apply[T : CharIso]: CharIso[T] = implicitly[CharIso[T]]

Hi, looking for scalac flags?

This gist has been upgraded to a blog post here.

@chilang
chilang / geohash.scala
Created December 27, 2011 15:46
geohash decoding
//http://en.wikipedia.org/wiki/Geohash
object geohash {
val LAT_RANGE = (-90.0, 90.0)
val LON_RANGE = (-180.0, 180.0)
private def mid(pair:(Double,Double)) = (pair._1+pair._2) / 2
private def decodePart(range:(Double,Double), bin:String) = bin.map(_.toInt - '0'.toInt).foldLeft(range)( (acc,bit) => if (bit == 0) (acc._1, mid(acc)) else (mid(acc), acc._2) )
import base32._
@JohnNilsson
JohnNilsson / gist:1227708
Created September 19, 2011 21:46
20 Intermediate Scala Exercises by Tony Morris
trait PartialType[T[_, _], A] {
type Apply[B] = T[A, B]
type Flip[B] = T[B, A]
}
trait Fluffy[F[_]] {
def furry[A, B](f: A => B, fa: F[A]): F[B]
}
object Fluffy {
@oxbowlakes
oxbowlakes / 3nightclubs.scala
Created May 13, 2011 15:14
A Tale of 3 Nightclubs
/**
* Part Zero : 10:15 Saturday Night
*
* (In which we will see how to let the type system help you handle failure)...
*
* First let's define a domain. (All the following requires scala 2.9.x and scalaz 6.0)
*/
import scalaz._
import Scalaz._