Skip to content

Instantly share code, notes, and snippets.

View miere's full-sized avatar
😁
Distributing data among friends

Miere Teixeira miere

😁
Distributing data among friends
View GitHub Profile
@miere
miere / OfertaDeCompraResource.java
Created May 18, 2012 13:22
Exemplo de uso do Coffee Framework
package comprase.ofertaDeCompra;
import java.util.Date;
import java.util.List;
import javax.ejb.EJB;
import coffee.annotation.Action;
import coffee.annotation.Parameter;
import coffee.annotation.WebResource;
@miere
miere / CollectionDeserializer.java
Created July 29, 2012 23:05
Real Collection Deserializer to parse arrays with GSON
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
@miere
miere / JavaDateAPIBenchmark.java
Created October 17, 2012 14:36
Java Date API benchmark
import static com.unimondes.dsl.DateDsl.*;
import static com.unimondes.dsl.DateDsl.Months.*;
import static org.junit.Assert.assertEquals;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import org.joda.time.DateTime;
import org.junit.Test;
@miere
miere / Game.scala
Created March 28, 2013 20:35
A Small game used to illustrate basics of Scala Language.
package com.contaazul.api.pub.client
import scala.util.Random
class Character(
var name: String,
var lastName: String = "No Name") {
val location = new Location
var health = 100
}
@miere
miere / autotunnig.sh
Created May 8, 2013 19:58
Generate PostgreSQL optimized memory parameters
#!/bin/bash
#
# autotunning.sh
# Constants
TWO_GIGABYTES="2056772"
# Variables
# Utils
@miere
miere / domain-configure-slave.sh
Last active December 17, 2015 07:29
Resources to configure JBoss AS 7 cluster.
#!/bin/sh
# domain-configure-slave.sh
# Configure the host as slave for a specific master domain
# usage: domain-configure-slave.sh <myslavename> <masterip>
. `dirname $0`/domain-configure.sh
configure_domain(){
sed -i -e 's/remote host="[0-9\.]*" port/remote host="'$1'" port/' $HOST_XML
sed -i -e 's/<.*local\/.*>/<remote host="'$1'" port="9999" security-realm="ManagementRealm"\/>/' $HOST_XML
@miere
miere / BusinessRoutingLifeCycle.java
Created May 15, 2013 00:56
This class received a refactoring to make possible achieve asynchronous development soon. When methods are short/tiny they make the class execution imperative. Basically, its methods are now focuses on tiny jobs, and all blocking jobs can be now replaced with an asynchronous call.
package layr.routing.service;
import layr.engine.RequestContext;
import layr.routing.api.Configuration;
import layr.routing.api.Response;
import layr.routing.api.RouteMethod;
import layr.routing.exceptions.NotFoundException;
import layr.routing.exceptions.RoutingException;
import layr.routing.exceptions.UnhandledException;
@miere
miere / BusinessRoutingLifeCycleTest.java
Created May 15, 2013 02:34
Unit Test should be self explanatory, with shorter and imperative methods.
package layr.routing;
import static org.junit.Assert.assertEquals;
import java.util.HashSet;
import java.util.Set;
import layr.routing.exceptions.UnhandledException;
import layr.routing.service.BusinessRoutingLifeCycle;
import layr.routing.service.LifeCycle;
@miere
miere / HomeResource.scala
Last active December 17, 2015 12:19
Sample Routes using Layr to render home.xhtml as home resource page ( i.e. "http://example.com/" )
import layr.routing.api.ResponseBuilder._
import layr.routing.api._
@WebResource("home")
class HomeResource {
@GET
def renderHome():Response =
renderTemplate( "home.xhtml" )
.set("user", new User( true ))
@WebServlet(name="myServlet", urlPatterns={"/auctionservice"}, asyncSupported=true)
public class MyServlet extends HttpServlet {
// track bid prices
public void doGet(HttpServletRequest request, HttpServletResponse response) {
AsyncContext aCtx = request.startAsync(request, response);
// This could be a cluser-wide cache.
ServletContext appScope = request.getServletContext();
Map<String, List<AsyncContext>> aucWatchers = (Map<String, List<AsyncContext>>)appScope.getAttribute("aucWatchers");
List<AsyncContext> watchers = (List<AsyncContext>)aucWatchers.get(request.getParameter("auctionId"));