This file contains 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
Block[{}, | |
BusData[bus_] := | |
"results" /. First[Import[StringJoin["http://apis.is/bus/realtime?busses=", bus], "JSON"]]; | |
AllBusData := "results" /. First[Import["http://apis.is/bus/realtime?busses=", "JSON"]]; | |
Dist[{x_ -> y_, a_ -> b_}] := (Flatten[{#1, a -> b}] & ) /@ y; | |
CommaSep[xs_] := StringTemplate["<*Row[`1`,\",\"]*>"][xs]; |
This file contains 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
Dynamic[With[{img = CurrentImage[]}, Block[{}, | |
faces = FindFaces[img]; | |
If[Length[faces] > 0, ( | |
mask = | |
Graphics[Disk[Mean[##], First@Differences[##]/2] & /@ faces, | |
PlotRange -> Transpose[{{0, 0}, ImageDimensions[img]}], | |
ImageSize -> 1 -> 1]; | |
blur = Max[Abs[#2 - #1] & @@@ faces]/5; | |
ImageCompose[img, | |
SetAlphaChannel[ColorNegate[img], |
This file contains 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
Block[{}, | |
Query := | |
Import["http://webservices.nextbus.com/service/publicXMLFeed?a=mbta&command=vehicleLocations", "XML"]; | |
UpdatePositions := | |
busPositions = Cases[Query, | |
XMLElement["vehicle", | |
{__, | |
"routeTag" -> rt_, |
This file contains 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
package scalaz | |
import Deque._ | |
/** | |
* A purely functional binary catenable deque. | |
* Based on "Notes on Catenable Deques in Pure LISP" by Mihaesau and Tarjan. | |
*/ | |
sealed trait Deque[A] { |
This file contains 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
sealed trait WriterBox { | |
type T | |
def value: T | |
def evidence: Writer[T] | |
} | |
object WriterBox { | |
def apply[B](b:B)(implicit W: Writer[B]): WriterBox = | |
new WriterBox { | |
type T = B |
This file contains 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 scala.language.experimental.macros | |
import scala.reflect.macros.whitebox.Context | |
class Foo { | |
override def toString: String = macro Foo.toStringImpl | |
} | |
object Foo { | |
def toStringImpl(c: Context): c.Expr[String] = { | |
import c.universe._ |
This file contains 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
// Finally tagless lambda calculus | |
object Final { | |
def varZ[A,B](env1: A, env2: B): A = env1 | |
def varS[A,B,T](vp: B => T)(env1: A, env2: B): T = vp(env2) | |
def b[E](bv: Boolean)(env: E): Boolean = bv | |
def lam[A,E,T](e: (A, E) => T)(env: E): A => T = x => e(x, env) | |
def app[A,E,T](e1: E => A => T, e2: E => A)(env: E): T = e1(env)(e2(env)) | |
def testf1[E,A](env: E): Boolean = | |
app(lam[Boolean,E,Boolean](varZ) _, b(true))(env) |
This file contains 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
def fix[H,DA:c.WeakTypeTag,DB:c.WeakTypeTag]( | |
f: (c.Expr[DA => DB], H) => c.Expr[DA => DB]): H => c.Expr[DA => DB] = | |
h => c.Expr[DA => DB]( | |
q"{ def self(n: ${c.weakTypeOf[DA]}): ${c.weakTypeOf[DB]} = ${f((c.Expr(q"self"), h))}(n); self _}") |
This file contains 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 scala.language.experimental.macros | |
import scala.reflect.macros.whitebox.Context | |
sealed trait Trampoline[A] { | |
def flatMap[B](f: A => Trampoline[B]): Trampoline[B] = macro Trampoline.flatMapImpl[A,B] | |
} | |
case class Return[A](a: A) extends Trampoline[A] | |
case class Suspend[A](k: () => Trampoline[A]) extends Trampoline[A] |
This file contains 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 scala.reflect.macros.whitebox.Context | |
import scala.language.experimental.macros | |
sealed trait Trampoline[A] { | |
def flatMap[B](f: A => Trampoline[B]): Trampoline[B] = macro Trampoline.flatMapImpl[A,B] | |
} | |
case class Return[A](a: A) extends Trampoline[A] | |
case class Suspend[A](k: () => Trampoline[A]) extends Trampoline[A] |