Skip to content

Instantly share code, notes, and snippets.

View filosganga's full-sized avatar

Filippo De Luca filosganga

View GitHub Profile
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@filosganga
filosganga / Contact.java
Last active December 9, 2016 17:30
GWT RPC Spring Scaffolding
package org.filippodeluca.gwt.examples.contacts;
import com.google.gwt.user.client.rpc.IsSerializable;
public class Contact implements IsSerializable {
private String name;
private String email;
public Contact(String name, String email) {
@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 / RoundRobinIterable.java
Last active May 13, 2023 07:50
It implements an Iterable that take elements from a list of Iterable in a round robin fashion. The test is most explicative than the description.
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterators.cycle;
import static java.util.Arrays.asList;
import java.util.Iterator;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
@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
}
@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+
@filosganga
filosganga / .gitignore
Last active August 29, 2015 14:27 — forked from mpilquist/.gitignore
Simulacrum Example
target
Verifying that +filosganga is my blockchain ID. https://onename.com/filosganga

Keybase proof

I hereby claim:

  • I am filosganga on github.
  • I am filippodeluca (https://keybase.io/filippodeluca) on keybase.
  • I have a public key ASC15nUa_a2CLHbteLCqNLcJOdILRNSHq5YRpdaV2xplzAo

To claim this, I am signing this object:

@filosganga
filosganga / ResourceMapStage.scala
Last active March 23, 2017 10:51
A map stage that control a resource lifecycle.
import akka.stream.ActorAttributes.SupervisionStrategy
import akka.stream._
import akka.stream.stage.{GraphStage, GraphStageLogic, InHandler, OutHandler}
import scala.util.control.NonFatal
class ResourceMapStage[In, Out, R](opener: () => R, closer: R => Unit, f: R => In ⇒ Out) extends GraphStage[FlowShape[In, Out]] {
val in = Inlet[In]("ResourceMap.in")
val out = Outlet[Out]("ResourceMap.out")