Skip to content

Instantly share code, notes, and snippets.

View benkolera's full-sized avatar

Ben Kolera benkolera

  • biza.io
  • Brisbane, Australia
View GitHub Profile
@benkolera
benkolera / argonautSumTypes.scala
Last active December 29, 2015 23:29
This can't be the right way to go about this...
import scalaz._
import std.option._
import argonaut._,Argonaut._
object JsonDb {
sealed trait SumType
case class Option1( foo:String ) extends SumType
case class Option2( bar:Int ) extends SumType
@benkolera
benkolera / sumTypes.scala
Last active December 29, 2015 23:39
Ahh, so I was a noob after all.
import scalaz._
import argonaut._,Argonaut._
object JsonDb {
sealed trait SumType
case class Option1( foo:String ) extends SumType
case class Option2( bar:Int ) extends SumType
private implicit val option1Codec = casecodec1( Option1.apply , Option1.unapply _ )("foo")
import scalaz._
import argonaut._,Argonaut._
object JsonDb {
sealed trait SumType
case class Option1( foo:String ) extends SumType
case class Option2( bar:Int ) extends SumType
private implicit val option1Codec = casecodec1( Option1.apply , Option1.unapply _ )("foo")
@benkolera
benkolera / gist:7801552
Last active December 30, 2015 08:19
scalac is a sad panda... Getting a " no-symbol does not have an owner " error.
[info] Loading project definition from /home/vagrant/src/iseek/corp/iseek-salesfarce/project
[info] Set current project to salesfarce (in build file:/home/vagrant/src/iseek/corp/iseek-salesfarce/)
> clean
[success] Total time: 0 s, completed Dec 5, 2013 5:31:36 PM
> compile
[info] Updating {file:/home/vagrant/src/iseek/corp/iseek-salesfarce/}iseek-salesfarce...
[info] Resolving org.scala-lang#scala-library;2.10.3 ...
[info] Resolving au.com.iseek#logback_2.10;0.1.0 ...
[info] Resolving org.slf4j#slf4j-api;1.7.5 ...
[info] Resolving ch.qos.logback#logback-core;1.0.10 ...
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;CONNECT 4 - By Ben Kolera
;;
;;Last Revised, 6/7/05
;;N.B - "Best Moves" functionality still not implemented.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Interact with the game object, "g" defined in the last line of these defns.
;;You could create other games in the interactions window on the fly, or just
;;Alter the defintion of g to change players, board size and etc...
;;
import argonaut._, Argonaut._
case class Message ( id:String , event:String, data:Json )
object Message {
implicit val messageCodec = casecodec3( Message.apply , Message.unapply )( "id" , "event" , "data" )
//scala> """{"id":"foo","event":"bar","data":"string"}""".decodeOption[Message]
//res1: Option[Message] = Some(Message(foo,bar,"string"))
@benkolera
benkolera / gist:8512776
Last active January 3, 2016 20:09
Two questions about GHC warnings
-- 1) Is there way to get a warning if you aren't being explicit with your imports and exports?
-- OK:
module Foo (bar) where
import Foo (bar)
import qualified Foo as F
-- Warnings:
module Foo where
@benkolera
benkolera / gist:8515658
Created January 20, 2014 06:04
Does this exist in either the errors or either package?
recoverEitherT :: Monad m => (e -> EitherT e m a) -> EitherT e m a -> EitherT e m a
recoverEitherT lf et = EitherT $ runEitherT et >>= (runEitherT . either lf right)
scala> Json.obj( "foo" := Json.jString("bar") ).obj.map(_.toMap).map( m => Json.jObjectAssocList( m.toList ) )
res6: Option[argonaut.Json] = Some({"foo":"bar"})
def intent = {
case req @ GET(Path(Seg("admin" :: "accounts" :: rest ))) => req match {
case Session(session) if (session.get("username").nonEmpty) => Pass
case _ => req.respond(Unauthorized)
}
case req @ GET(Path(Seg("admin" :: "accounts" :: Nil))) =>
list(req)
case req @ GET(Path(Seg("admin" :: "accounts" :: "uncreated" :: Nil))) =>
uncreated(req)
case req @ GET(Path(Seg("admin" :: "accounts" :: id :: Nil))) =>