This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Text | |
import Control.Monad.Reader | |
data ZResult a = | |
ZVal a | |
| ZNotFound | |
| ZFail Text | |
| ZUnauth Text | |
newtype ZResultT m a = ZResultT { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Text | |
import Control.Monad.Reader | |
data ZResult a = | |
ZVal a | |
| ZNotFound | |
| ZFail Text | |
| ZUnauth Text | |
newtype ZResultT m a = ZResultT { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Monoid | |
import Control.Monad.State | |
import Control.Monad.Reader | |
data RequestHeaders = | |
RequestHeaders [(String, String)] | |
data ResponseHeaders = | |
ResponseHeaders [(String, String)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |