Skip to content

Instantly share code, notes, and snippets.

View edufa's full-sized avatar

edufa edufa

  • Sesc/PR
  • Curitiba - PR - Brazil
View GitHub Profile
@perfectacle
perfectacle / java-10-install.config
Last active March 10, 2020 05:21
Installation of OpenJDK 10 in AWS Elastic Beanstalk with ebextensions
# make shell script
files:
"/opt/elasticbeanstalk/tasks/install-openjdk-10.sh" :
mode: "000755"
owner: root
group: root
content: |
if [[ $(javac -version) != *"javac 10"* ]]
then
# please check recently openjdk version.
Gist using Vraptor 4 and Thymeleaf, based on https://github.com/claudineij/vraptor-poc/tree/master/src/main/java/br/com/caelum/vraptor/poc/thymeleaf
<dependency>
<groupId>br.com.caelum</groupId>
<artifactId>vraptor</artifactId>
<version>4.2.0-RC3</version>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>3.0.2.RELEASE</version>
@lucascs
lucascs / Capitalize.java
Created April 30, 2015 01:50
Capitalize java 8
import java.util.Arrays;
public class Capitalize {
public static String capitalize (String x) {
return x.substring(0,1).toUpperCase() + x.substring(1).toLowerCase();
}
public static void main(String[] args) {
String text = "gabinete do deputado fulando de tal e de dona maria";

Session Management in an Autoscaling Environment

Problem Statement

User sessions in J2EE and LAMP stacks have traditionally been handled in memory by the application server handling the user request. Because of that, load balancers have been configured to use sticky sessions. By sticky sessions we mean that once the user has visited the site, they will be assigned an app server and will return to that server for subsequent requests. The load balancers typically handle that by referencing the users session cookie.

Elastic cloud environments differ from traditional server configurations in that they have a variable number of servers based on traffic loads whereas traditional configurations had a fixed number of servers. When traffic volumes decline it is necessary to vaporize servers. In doing so, we would lose user sessions (essentially forcing a logout) unless we come up with a new strategy for session management.

A new approach

After much research, it is clear that the best

@linyatis
linyatis / CORSController
Created November 6, 2014 00:44
VRaptor 4 CORS
@Controller
public class CORSController {
@Inject private Result result;
@Inject private Router router;
@Options("/*")
public void options(@Observes VRaptorRequestStarted requestInfo) {
Set<HttpMethod> allowed = router.allowedMethodsFor(requestInfo.getRequest().getRequestedUri());
String allowMethods = allowed.toString().replaceAll("\\[|\\]", "");
@garcia-jj
garcia-jj / AbstractRepositoryTest.java
Last active August 29, 2015 14:04
Testes unitários de repositórios
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.junit.AfterClass;
import org.junit.BeforeClass;
public abstract class AbstractRepositoryTest {
protected static EntityManagerFactory emFactory;
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>1.0.2.Final</version>
<configuration>
<hostname>${wildfly-hostname}</hostname>
<port>${wildfly-port}</port>
<username>${wildfly-username}</username>
<password>${wildfly-password}</password>
@garcia-jj
garcia-jj / PasswordBasedEncryption.java
Last active August 29, 2015 13:58
Strong encryption with PBE
package foo;
import static java.lang.System.arraycopy;
import static java.util.Arrays.copyOf;
import static java.util.Arrays.copyOfRange;
import static java.util.Arrays.fill;
import java.security.GeneralSecurityException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
/*
* Create an Amazon AWS Instance and Programmatically SSH into it
*/
/*
* Copyright 2010 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
package com.javaforu.rsync;
import com.javaforu.rsync.Sync.CharRingBuffer.Visitor;
import rollinghash.RabinKarpHash;
import java.util.*;
import java.util.zip.CRC32;
/**
* Author: Ashwin Jayaprakash / [email protected] / http://www.ashwinjayaprakash.com