Skip to content

Instantly share code, notes, and snippets.

View markhibberd's full-sized avatar

markhibberd markhibberd

View GitHub Profile
@markhibberd
markhibberd / JavaDemo.java
Created June 19, 2011 11:56
Foil configuration demo
import io.mth.foil.j.*;
import javax.servlet.http.*;
import java.io.*;
public class JavaDemo {
private static final Foils f = new DefaultFoils();
private static final Configs c = new DefaultConfigs();
public static class DemoServlet extends HttpServlet {
protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException {
@markhibberd
markhibberd / usage
Created February 14, 2012 22:09
Never have I enjoyed crafting a usage message as much as this.
echo 'note:'
echo ' Examples assume use of a shell with "**" glob support. This means either zsh or'
echo ' bash 4.x with `shopt -s globstar` set. If you are an insolent mac user with a'
echo ' default bash 3.x, this tool strongly recommends you upgrade (although defenestration'
echo ' of said mac is also a valid option).'
echo
echo ' If you become desperate something like $(find src/test/js/atomic -name \*.js) could be'
echo ' used as a substitute.'
import Data.Text
import Control.Monad.Reader
data ZResult a =
ZVal a
| ZNotFound
| ZFail Text
| ZUnauth Text
newtype ZResultT m a = ZResultT {
import Data.Text
import Control.Monad.Reader
data ZResult a =
ZVal a
| ZNotFound
| ZFail Text
| ZUnauth Text
newtype ZResultT m a = ZResultT {
import Data.Monoid
import Control.Monad.State
import Control.Monad.Reader
data RequestHeaders =
RequestHeaders [(String, String)]
data ResponseHeaders =
ResponseHeaders [(String, String)]
@markhibberd
markhibberd / gist:4323270
Created December 17, 2012 23:04
Failing to publish against 2.10.0-RC5
[fire:argonaut] 2052$ ./sbt "+publish"
Detected sbt version 0.12.1
Using /home/mth/.sbt/0.12.1 as sbt dir, -sbt-dir to override.
[info] Loading project definition from /usr/home/mth/work/argonaut/project
[info] Set current project to argonaut (in build file:/usr/home/mth/work/argonaut/)
Setting version to 2.9.2
[info] Set current project to argonaut (in build file:/usr/home/mth/work/argonaut/)
[info] :: delivering :: io.argonaut#argonaut_2.9.2;6.0-SNAPSHOT :: 6.0-SNAPSHOT :: integration :: Tue Dec 18 08:53:07 EST 2012
[info] delivering ivy file to /usr/home/mth/work/argonaut/target/scala-2.9.2/ivy-6.0-SNAPSHOT.xml
[info] Wrote /usr/home/mth/work/argonaut/target/scala-2.9.2/argonaut_2.9.2-6.0-SNAPSHOT.pom
@markhibberd
markhibberd / gist:4349013
Created December 20, 2012 22:11
Implicit resolution failing on 2.10.0-RC5 with type alias.
Welcome to Scala version 2.10.0-RC5 (OpenJDK 64-Bit Server VM, Java 1.7.0_02).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import org.scalacheck._
import org.scalacheck._
scala> type ListString = List[String]
defined type alias ListString
val username: Option[String] \/ String = for {
parsed <- requestJson.parse.swapped(_.map(_.some)) // Parse the JSON.
jsonObject <- parsed.obj.toRight[Option[String]] // Get the JSON as a JsonObject instance.
userIDJson <- jsonObject("userid").toRight[Option[String]] // Get the "userid" field from the JsonObject.
userID <- userIDJson.string.toRight[Option[String]] // Get the value of the "userid" field.
user <- lookupUser(userID).toRight[Option[String]] // Get an instance of User for the user ID.
} yield user.username
object T {
implicit def XIntToInt(x: XInt): Int = x.n
// isomorphism to Int
case class XInt(n: Int)
case class Wibble[A](a: A) {
def wibble(implicit ev: A <:< Int) = a + 9
def map[B](f: A => B) =
case class Person(name: String, age: Int)
implicit val DecodePerson: DecodeJson[Person] = jdecode2L(Person(_: String, _: Int))("name", "age")
implicit val EncodePerson: EncodeJson[Person] = jencode2L((p: Person) => (p.name, p.age))("name", "age")
val decoded: Option[Person] = """{"name":"Fred","age":"40"}""".decodeOption[Person]
val encoded: Option[String] = decoded.map(_.jencode.nospaces)