Skip to content

Instantly share code, notes, and snippets.

@shajra
shajra / build.sbt
Created June 14, 2017 11:31 — forked from paulp/build.sbt
/** Your task is to reason your way to which compiler
* options which will be passed for each of
* 1) sbt root/compile
* 2) sbt p1/compile
*/
scalacOptions := Seq("-DSBT")
scalacOptions in ThisBuild += "-D0"
scalacOptions in Global += "-D1"
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
import Control.Monad.IO.Class
import Control.Monad.Trans.Class
import Prelude hiding (log)
--------------------------------------------------------------------------------
-- The API for cloud files.
class Monad m => MonadCloud m where
saveFile :: Path -> Bytes -> m ()
@shajra
shajra / twitter.scala
Created November 2, 2015 20:02 — forked from bryce-anderson/twitter.scala
slapped together bits of a basic http4s interface to the Twitter streaming API. OAuth not included.
// a simple process1 that splits the frames up based on a "\r\n" sequence of chars
val partitioner = {
import java.util.regex.Pattern
import scalaz.stream.process1
import scalaz.std.string._
val pattern = Pattern.compile("\r\n")
process1.repartition { s: String =>
pattern.split(s, -1)
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
import Control.Lens
import Data.Maybe
import Data.Monoid
data Constant a b =
Constant a
@shajra
shajra / gist:d383179fbf260b4e5978
Last active August 29, 2015 14:27 — forked from nkpart/gist:cc852b43d948a33a04c8
Using ghcid inside of emacs
Pieces you need:
* emacs
* ghcid
ghcid needs to know the height of the terminal, we'll set it explicitly
height = (window-height) - (scroll-margin) - 1
set this height as your term-buffer-maximum-size
@shajra
shajra / free1.scala
Last active August 29, 2015 14:03 — forked from danclien/step1.scala
// Implementing functor manually
import scalaz._, Scalaz._, Free.liftF
sealed trait TestF[+A]
case class Foo[A](o: A) extends TestF[A]
case class Bar[A](h: (Int => A)) extends TestF[A]
case class Baz[A](h: (Int => A)) extends TestF[A]
implicit def testFFunctor[B]: Functor[TestF] = new Functor[TestF] {
@shajra
shajra / objalg.scala
Last active August 29, 2015 14:03 — forked from jdanbrown/gist:4747205
#!/bin/bash
exec ~/src/scala/bin/scala -savecompiled "$0" "$@"
!#
// Example of object algebras, based on the scala example at http://ropas.snu.ac.kr/~bruno/oa/
// type Term = ∀A,O. O[A] -> A
trait Term[O[_]] {
def apply[A](o: O[A]): A
}
@shajra
shajra / alacarte.scala
Last active May 6, 2019 20:53 — forked from runarorama/gist:a8fab38e473fafa0921d
"datatypes a la carte" pattern in Scala
sealed trait Interact[A]
case class Ask(prompt: String)
extends Interact[String]
case class Tell(msg: String)
extends Interact[Unit]
trait Monad[M[_]] {
def pure[A](a: A): M[A]
@shajra
shajra / Setup.hs
Created June 30, 2014 23:06 — forked from hvr/Setup.hs
import Control.Exception
import Control.Monad
import Data.Maybe
import Data.Version
import Distribution.PackageDescription (PackageDescription(..), HookedBuildInfo, GenericPackageDescription(..))
import Distribution.Package (PackageIdentifier(..))
import Distribution.Simple (defaultMainWithHooks, simpleUserHooks, UserHooks(..))
import Distribution.Simple.LocalBuildInfo (LocalBuildInfo(..))
import Distribution.Simple.Setup (BuildFlags(..), ConfigFlags(..))
import Distribution.Simple.Utils (die)
import scalaz._
import Scalaz._
import Free._
/** "Pure" interactions with a console. */
sealed trait Console[+A]
case class GetLine[A](k: String => A) extends Console[A]
case class PutLine[A](s: String, a: A) extends Console[A]
object Console {