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
// Idiomatic solution using extrators | |
// Extractors allow us to bind parameters to an object and are usable in pattern matches to see if a pattern can apply to the params submitted. | |
// Note this is simialr to case classes, but works against an Object (which are like 'static' classes in Java). Also it incurs some performance penalties | |
// as opposed to using case classes | |
class BowlingForExtractors() { | |
def score(bowls:List[Int]) = scoreFrames(bowls).slice(0,10).sum // take the first 10 elements from the List and sum them..any additional elements are the result of additional strikes | |
def scoreFrames(bowls:List[Int]) : List[Int] = bowls match { | |
case Nil => List(0) |
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
/*! | |
* Small Walker - v0.1.1 - 5/5/2011 | |
* http://benalman.com/ | |
* | |
* Copyright (c) 2011 "Cowboy" Ben Alman | |
* Dual licensed under the MIT and GPL licenses. | |
* http://benalman.com/about/license/ | |
*/ | |
// Walk the DOM, depth-first (HTML order). Inside the callback, `this` is the |
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
// module dependencies | |
var http = require('http'), | |
url = require('url'); | |
/** | |
* UrlReq - Wraps the http.request function making it nice for unit testing APIs. | |
* | |
* @param {string} reqUrl The required url in any form | |
* @param {object} options An options object (this is optional) |
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
package akka.unfiltered | |
import akka.actor._ | |
import akka.dispatch.Future | |
import akka.pattern.ask | |
import akka.util.duration._ | |
import akka.util.Timeout | |
import unfiltered.Async | |
import unfiltered.request._ |
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
package auth | |
import unfiltered.Cycle | |
import unfiltered.request.{HttpRequest, BasicAuth, Path} | |
import unfiltered.response._ | |
import unfiltered.jetty.Http | |
import unfiltered.filter.Plan | |
object Req { | |
def apply[Req, Res](f:PartialFunction[HttpRequest[Req], HttpRequest[Req] => ResponseFunction[Res]]):Cycle.Intent[Req, Res] = { |
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
:paste | |
import scalaz._, Scalaz._, scalaz.Free.{Suspend, Return} | |
// Console grammar | |
sealed trait ConsoleF[+A] | |
object Console { | |
case class WriteLine[A](msg: String, o: A) extends ConsoleF[A] | |
case class ReadLine[A](o: String => A) extends ConsoleF[A] | |
} |
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
public class Switch { | |
private Engine engine; | |
private boolean on; | |
public Switch(Engine engine) { | |
this.engine = engine; | |
this.on = false; | |
} | |
public boolean switchOn() { |
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
var R = require('ramda'); | |
var Future = require('ramda-fantasy').Future; | |
//Wrap ajax in a future | |
//:: String -> Future String | |
var fetch = function(url) { | |
return new Future(function(rej, res){ | |
var oReq = new XMLHttpRequest(); | |
oReq.addEventListener("load", res, false); | |
oReq.addEventListener("error", rej, false); | |
oReq.addEventListener("abort", rej, false); |
OlderNewer