Skip to content

Instantly share code, notes, and snippets.

@umitanuki
umitanuki / Sca2Main.scala
Created April 27, 2011 18:21
Tentative JSON pretty printer in Scala
import scala.io._
import scala.util.parsing.json._
object Sca2Main {
def main(args: Array[String]){
val url = "http://search.twitter.com/search.json?q=umitanuki"
val parsed = JSON.parseRaw(Source.fromURL(url).getLines.mkString)
parsed match{
case Some(x:JSONObject) => println("object")
case Some(y:JSONArray) => println("array")
@NicolasT
NicolasT / functors.v
Created May 2, 2011 21:50
Coq definitions and proofs of several functors
Require Import Coq.Program.Basics.
Open Local Scope program_scope.
Definition id (A: Type) (e: A): A := e.
Module Type FUNCTOR.
Set Implicit Arguments.
Parameter F: forall (A: Type), Type.
Parameter fmap: forall (A B: Type), (A -> B) -> F A -> F B.
@oxbowlakes
oxbowlakes / 3nightclubs.scala
Created May 13, 2011 15:14
A Tale of 3 Nightclubs
/**
* Part Zero : 10:15 Saturday Night
*
* (In which we will see how to let the type system help you handle failure)...
*
* First let's define a domain. (All the following requires scala 2.9.x and scalaz 6.0)
*/
import scalaz._
import Scalaz._
@jonifreeman
jonifreeman / scalatoprolog.md
Created January 30, 2012 09:16
Scala type system -> Prolog
@drexin
drexin / Macros.scala
Last active October 27, 2016 09:41
macros to get current file and line, inspired by ruby's __FILE__ and __LINE__
import java.io.File
import language.experimental.macros
import scala.reflect.macros.Context
object Macros {
def LINE: Int = macro lineImpl
def lineImpl(c: Context): c.Expr[Int] = {
import c.universe._
@philnguyen
philnguyen / ValueEnum.scala
Last active November 8, 2015 01:45
Concise, type-safe and unboxed Enum by Scala macros
import scala.language.experimental.macros
import scala.reflect.macros.blackbox.Context
import scala.annotation.StaticAnnotation
import scala.annotation.compileTimeOnly
/**
This annotation turns a simple class declaration into a type-safe and unboxed Enum.
It does not attempt to be compatible with Java, because I have no respect for Java.
There is an example usage at the end of the file.
*/