Skip to content

Instantly share code, notes, and snippets.

View timperrett's full-sized avatar
🚧

Timothy Perrett timperrett

🚧
View GitHub Profile
/**
* Problem 1 in scala
*/
(for(i <- 1 until 999) yield i).filter(n => (n % 3 == 0 || n % 5 == 0)).sum
/**
* Problem 2 in scala
*/
lazy val fib: Stream[Int] = Stream.cons(0, Stream.cons(1, fib.zip(fib.tail).map(p => p._1 + p._2)))
class A
class A2 extends A
class B
trait M[X]
//
// Upper Type Bound
//
def upperTypeBound[AA <: A](x: AA): A = x
import scalaz._
/**
* playing with some of the ideas from the Haskell fclabels library
* using the new Lens functionality in scalaz
*
* http://hackage.haskell.org/package/fclabels
*/
object LensTest {
@timperrett
timperrett / BindingTypeClasses.scala
Created April 8, 2011 23:14
Example of using Scala implicits to do CssSel type classes
package eu.getintheloop.snippet
// Author: Timothy Perrett
// Date: 11th April 2011
case class Product(name: String, price: Long)
import net.liftweb.util.CssSel
object Bindings {
// See http://lampsvn.epfl.ch/trac/scala/ticket/967.
//
// Gilles' fix causes the definition of Nat to be rejected with the error
// "Parameter type in structural refinement may not refer to a type member
// of that refinement". However we can work around the problem by
// quantifying out the problematic parameter type and reinstating it via
// a generalized type constraint.
type Num = {
type Rep
object Bindings {
class Bind[T](what: T){
def bind[DataBinding[T]] = implicitly(what)
}
type DataBinding[T] = T => CssSel
implicit def asCssSelector[T](in : T): Bind[T] = new Bind[T](in)
}
java.lang.AssertionError: assertion failed: adapt akka.dispatch.Future.apply$default$2():()Long to Long
at scala.tools.nsc.transform.Erasure$Eraser.adaptToType(Erasure.scala:533)
at scala.tools.nsc.transform.Erasure$Eraser.adapt(Erasure.scala:658)
at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:4208)
at scala.tools.nsc.typechecker.Typers$Typer.typedArg(Typers.scala:2202)
at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$typedArgs$3.apply(Typers.scala:2212)
at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$typedArgs$3.apply(Typers.scala:2211)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:206)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:206)
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:61)
case class XSetTrackingParameter(inTicketID: Option[String],
inParam: xmpiewsapi.XParameter)
case class XParameter(m_Name: Option[String],
m_Value: Option[String])
@timperrett
timperrett / GlassFish.scala
Created June 20, 2011 22:27 — forked from sdb/GlassFish.scala
create an SBT plug-in for running webapps in Glassfish
package sbt {
import org.glassfish.embeddable.{GlassFish, GlassFishRuntime, GlassFishProperties, Deployer}
trait GlassFishPlugin extends BasicWebScalaProject {
def glassFishPort = GlassFishRunner.DefaultPort
private lazy val glassFish = new GlassFishRunner(glassFishPort, temporaryWarPath)
lazy val glassfishRun = glassfishRunAction
@timperrett
timperrett / Aggregator.scala
Created September 4, 2011 15:54 — forked from remeniuk/Aggregator.scala
Scatter-Gather with Akka Dataflow
class Aggregator(recipients: Iterable[ActorRef]) extends Actor{
def receive = {
case msg @ Message(text) =>
println("Started processing message `%s`" format(text))
val result = Promise[String]()
val promises = List.fill(recipients.size)(Promise[String]())
recipients.zip(promises).map{case (recipient, promise) =>