Skip to content

Instantly share code, notes, and snippets.

View filosganga's full-sized avatar

Filippo De Luca filosganga

View GitHub Profile
@filosganga
filosganga / CycleIterator.scala
Created October 27, 2013 20:40
An Iterator that cycles trough the given elements
class CycleIterator[B <: A, +A](elements: Iterable[B]) extends Iterator[A] {
var iterator: Iterator[B] = Iterator.empty
def hasNext: Boolean = {
if (!iterator.hasNext) {
iterator = elements.iterator
}
iterator.hasNext
}
Verifying that +filosganga is my blockchain ID. https://onename.com/filosganga
@filosganga
filosganga / FizzBuzz.scala
Created November 7, 2012 12:59
FizzBuzz implementation
class FizzBuzz(divisors = Map(3->"Fizz", 5->"Buzz")) {
def fizzBuzz(n: Int): String = {
divisors.foldLeft(""){(res, d)=>
n % d._1 match {
case 0 => res + d._2
case _ => res
}
} match {
case "" => n.toString
@filosganga
filosganga / .gitignore
Last active August 29, 2015 14:27 — forked from mpilquist/.gitignore
Simulacrum Example
target
@filosganga
filosganga / CssParser.scala
Created February 17, 2015 23:15
CSS Parser
import util.parsing.combinator.JavaTokenParsers
case class Rule(val selectors : List[String], val properties : List[Property])
case class Property(name: String, value: String)
object CssParser extends JavaTokenParsers {
def rules = rule+