Skip to content

Instantly share code, notes, and snippets.

test("easy test") {
val urlCal = new URL("https://www.google.com/calendar/ical/u74t" +
"b1k9n53bnc5qsg3694p2l4%40group.calendar.google.com/private-4b" +
"4d566cd18fd63d76c6cc6ea84086cf/basic.ics")
val builder = new CalendarBuilder();
val cal = builder.build(urlCal.openStream());
val components: ComponentList = cal.getComponents(Component.VEVENT)
@ubourdon
ubourdon / gist:2702802
Created May 15, 2012 15:49
a real good pojo
public class SingleEvent {
private final Tupple<KeyType, String> basicatId;
private final Tupple<EventType, String> eventId;
private final String xmlData;
private final Boolean acquitted;
private SingleEvent( final Tupple<KeyType, String> basicatId, final Tupple<EventType, String> eventId, final String xmlData, final Boolean acquitted ) {
this.basicatId = basicatId;
this.eventId = eventId;
this.xmlData = xmlData;
@ubourdon
ubourdon / prez unfiltered PSUG
Created September 26, 2012 18:18
prez unfiltered PSUG
http://www.fotopedia.com
# MONGO
casbah official scala driver
dsl que requete sympa
mais pas sympa pour travailler sur les objets récupérés DBObject = Option[String] ou d'autres trucs
salat DRM document relationel model
map to immutable case class only
mapping - grating ?? grater[Picture].asObject(pictureCasbahObject)
@ubourdon
ubourdon / coursera week 1
Created October 5, 2012 09:24
[COURSERA-1][RECURSION] pascal triangle, count '(', count change money
/**
* Exercise 1
*/
def pascal(c: Int, r: Int): Int = {
if (c == 0 || c == r) 1 // si r == c alors la décomposition en dessous tombe forcement sur pascal(c>r) et c'est impossible
else pascal(c - 1, r - 1) + pascal(c, r - 1)
}
/**
* Exercise 2
object MyApp extends App {
case class Bag[+A](value: A) { // covariance
//override def toString = "toto"
//def copy
//equals
//hashcode
// + elem de Product
// functor dans la théorie des catégories
def map[B](f: A => B): Bag[B] = Bag(f(value))
@ubourdon
ubourdon / json.scala
Created April 4, 2013 14:57
Comment lire un array json hétérogène avec l'api json de Play! 2.1
implicit val venueReader: Reads[Venue] = (
(__ \ "address").readNullable[String] and
(__ \ "address_2").readNullable[String] and
(__ \ "city").readNullable[String] and
(__ \ "region").readNullable[String] and
(__ \ "country").readNullable[String] and
(__ \ "postal_code").readNullable[String]
)(Venue)
implicit val eventbriteEventReader: Reads[EventbriteEvent] =
package scalawebapp
import com.sun.net.httpserver.{HttpExchange, HttpHandler, HttpServer}
import java.net.InetSocketAddress
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
import scala.util.{Failure, Success}
class MyHttpServer(port: Int = 8080) {
@ubourdon
ubourdon / DurationTestTools.scala
Created November 18, 2013 22:07
DurationTestTools
import scala.concurrent.duration._
trait DurationTestTools {
implicit def duration2DurationCompare(duration: Duration): DurationCompare = DurationCompare(duration)
case class DurationCompare(duration: Duration) {
def shouldBeMinusThan(expectedDuration: Duration) { assert(duration.compare(expectedDuration) < 0, s"$duration was not minus than $expectedDuration") }
def shouldBeMinusOrEqualThan(expectedDuration: Duration) { assert(duration.compare(expectedDuration) <= 0, s"$duration was not minus or equal than $expectedDuration") }
def shouldBeGreaterThan(expectedDuration: Duration) { assert(duration.compare(expectedDuration) > 0, s"$duration was not greater than $expectedDuration") }
def shouldBeGreaterOrEqualThan(expectedDuration: Duration) { assert(duration.compare(expectedDuration) >= 0, s"$duration was not greater or equal than $expectedDuration") }
import concurrent.Await
import akka.pattern.gracefulStop
import akka.actor.ActorSystem
trait ActorTestingTools {
def closeDummyActors(actorsName: String*)(implicit system: ActorSystem) {
import scala.concurrent.duration._
actorsName.map( actorName => gracefulStop(system.actorFor(system / actorName), 1 seconds) )
.map( Await.result(_, 1 seconds) )
@ubourdon
ubourdon / AClassUsingActor.scala
Created January 10, 2014 02:04
Problem with Akka Actors that is when you use it, you must use ActorRef Scalatype. It means Akka Actors were not typed. We can "solve" this problem using simpla "companion class" api.
class AClassUsingActor(myClass: MyClass) {
def useActor = myClass.ref ! message
}
object CreateActorClass {
val system = ActorSystem("system")
val classUsingActor = new AClassUsingActor(new MyClass(system))
classUsingActor.useActor
}