Skip to content

Instantly share code, notes, and snippets.

View nicmarti's full-sized avatar

Nicolas Martignole nicmarti

View GitHub Profile
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Association du Paris Java User Group.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
@nicmarti
nicmarti / FluentdLogbackAppenderBase.java
Last active December 22, 2015 18:18
Simple logback appender for Fluentd, ready to use with Play2 application
package org.zaptravel.logback.fluentd;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;
import ch.qos.logback.classic.spi.LoggingEvent;
import ch.qos.logback.core.UnsynchronizedAppenderBase;
import org.apache.commons.lang3.StringEscapeUtils;
@nicmarti
nicmarti / DaemonAppender.java
Last active December 22, 2015 17:49
FluentLogbackAppender Java, that is able to track the URI if you used MDC.put("URL","/page/toto") in your code. Used for zaptravel. I adapted one of the fluent logback appender.
package org.zaptravel.logback.fluentd;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import org.slf4j.Logger;
@nicmarti
nicmarti / tickets.json
Created March 21, 2013 16:52
JSON sample for tickets
{
"max": "10",
"eventId": 5,
"start": "0",
"tickets": [
{
"invoiceState": "PAID",
"modifiedTime": 1354710165000,
"tagId": "unassigned",
"optIn": false,
case class TicketRequest(max: String, eventId: Long, start: String, tickets: List[Ticket])
case class Ticket(modifiedOn: Date,
optIn:Boolean,
ticketId: Long,
email:String,
invoiceState:String,
ticketType: String,
modifiedTime: Long,
partnerCode: String,
@nicmarti
nicmarti / HaskellVSGroovy.groovy
Last active December 14, 2015 23:59 — forked from renatoathaydes/HaskellVSGroovy.groovy
Working on a very simple haskell vs groovy vs scala
// This is a comparison between Haskell and Groovy based on some simple problems found in the following
// Haskell Introduction:
// http://learnyouahaskell.com/starting-out#ready-set-go
// Ex 1. If we have two lists, [2,5,10] and [8,10,11] and we want to get the products of all the possible
// combinations between numbers in those lists, here's what we'd do.
/* HASKELL */
[ x*y | x <- [2,5,10], y <- [8,10,11]]
@nicmarti
nicmarti / Redis.scala
Created March 1, 2013 11:29
My simple Redis client wrapper that uses Play2 configuration
package library
import org.sedis.Pool
import redis.clients.jedis.{JedisPoolConfig, JedisPool}
import play.api.Play.current
import org.apache.commons.pool.impl.GenericObjectPool
/**
* Redis connection wrapper.
* You can configure the server details in the application.conf with:
@nicmarti
nicmarti / Origin.scala
Created March 1, 2013 11:27
Play2 and Redis simple demo - How to load an Origin from a Redis data store with a for-comprehension
def getOrigin(originId: Long): Option[Origin] = Redis.pool.withClient {
client =>
for(slug<-Option(client.hget("Url:From:Rev", originId.toString));
display<-Option(client.hget("Places:Place:"+originId, "display")
)) yield Origin(originId,display,slug)
}
}
@nicmarti
nicmarti / OriginSpecs.scala
Created March 1, 2013 11:25
Play2 and Spec simple test - Demo for Confoo
package models
import org.specs2.mutable._
import play.api.test._
import play.api.test.Helpers._
class OriginSpecs extends Specification {
"An Origin" should {
"returns the slug for a valid origin" in {
@nicmarti
nicmarti / play2_enumeratee_enumerator
Created August 5, 2012 14:02
Play2 stream with live scrapping
package models
import play.libs.WS
import play.api.libs.json.JsValue
import play.api.libs.json.Json._
import scala.Some
import play.api.libs.EventSource
import org.apache.commons.lang.StringUtils
// Define a generic event,