Skip to content

Instantly share code, notes, and snippets.

class Elipse(val width: Double, val height: Double)
// circle is a special case of elispse where width and height are the same
class Circle(r: Double) extends Elipse(r, r)
// typeclass to calculate the Area of a T
trait Area[-T] {
def area(t: T): Double
}
@stew
stew / Comp.scala
Last active August 29, 2015 14:27
this flatmap is probably not stacksafe
package cats
package effect
import java.util.concurrent.CountDownLatch
/**
* A computation of an A value
*/
sealed trait Comp[A] {
import Comp._
@stew
stew / gist:e979eaa13bca2d5e8d61
Created April 15, 2015 15:30
fix the zine for double sided printing
convert -quality 100 -density 300x300 strace-zine.pdf'[0,2,4,6]' 'strace-single%d.gif
convert -quality 100 -density 300x300 strace-zine.pdf'[1,3,5,7]' -rotate 180 'strace-single%d.gif'
convert strace-single<0-8>.gif strace-fixed.pdf #<0-8> is probably a zsh only thing, * would probably work ⏎
@stew
stew / either.py
Last active February 9, 2016 08:50
from abc import ABCMeta, abstractmethod
import sys
# lets get one thing straight right out of the box:
def fail(e):
import traceback
with open("/tmp/tb", "w") as f:
traceback.print_exc(e, f)
import scalaz._
import Maybe._
case class CofreeNEL[A](cf: Cofree[Maybe, A]) {
def +:(a: A): CofreeNEL[A] = CofreeNEL(Cofree(a, just(cf)))
def head: A = cf.head
def tail: Maybe[CofreeNEL[A]] = cf.tail.map(CofreeNEL.apply)
def map[B](f: A=>B): CofreeNEL[B] = CofreeNEL(cf map f)
def flatMap[B](f: A => CofreeNEL[B]): CofreeNEL[B] = CofreeNEL(Bind[({type l[A]=Cofree[Maybe, A]})#l].bind(cf)(f andThen (_.cf)))
import scalaz._
import Scalaz._
object IsItAProfunctor extends App {
case class Foo(f: Double)
val validateDouble: Double ⇒ Validation[String,Double] = {d ⇒
if(d < 0) "less than zero".fail
else d.success
trait MyOption[+A] {
// single abstract method
def cata[X](some: A => X, none: => X): X
def map[B](f: A => B): MyOption[B] = error("todo")
def flatMap[B](f: A => MyOption[B]): MyOption[B] = error("todo")
def getOrElse[AA >: A](e: => AA): AA = error("todo")
package maybe
sealed trait Maybe[A] {
def isEmpty: Boolean
}
case class Just[A](a: A) extends Maybe[A] {
override final def isEmpty = true
}
❯ date -d "9 fortnights ago"
Wed Apr 2 21:46:42 EDT 2014
❯ date -d "9.5 fortnights ago"
date: invalid date ‘9.5 fortnights ago’
Changes from HEAD to working tree
2 files changed, 19 insertions(+), 10 deletions(-)
core/src/main/scala/scalaz/IList.scala | 16 ++++++++++------
core/src/main/scala/scalaz/Maybe.scala | 13 +++++++++----
Modified core/src/main/scala/scalaz/IList.scala
diff --git a/core/src/main/scala/scalaz/IList.scala b/core/src/main/scala/scalaz/IList.scala
index 946ad98..7e383c7 100644
--- a/core/src/main/scala/scalaz/IList.scala
+++ b/core/src/main/scala/scalaz/IList.scala