Skip to content

Instantly share code, notes, and snippets.

View ghusta's full-sized avatar

Guillaume Husta ghusta

  • Toulouse, France
  • 01:57 (UTC +02:00)
  • X @ghusta
View GitHub Profile
@ghusta
ghusta / JpaRepositoryItemReader.java
Created May 15, 2017 11:12
Spring Batch (ItemReader) + Spring Data JPA (JpaRepository) integration
import java.util.concurrent.CopyOnWriteArrayList;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.database.AbstractPagingItemReader;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
@ghusta
ghusta / MyRegexTest.java
Created October 5, 2022 21:31
Testing Java regex with SemVer example (named capturing group)
import org.junit.jupiter.api.Test;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static org.junit.jupiter.api.Assertions.fail;
class MyRegexTest {
@Test
@ghusta
ghusta / Dockerfile
Last active August 12, 2022 20:39
Tomcat 8 + Docker : add custom directory in classpath (Method #1 : modify conf/catalina.properties)
FROM tomcat:8.5-jre8
# $CATALINA_HOME is defined in tomcat image
ADD target/my-webapp*.war $CATALINA_HOME/webapps/my-webapp.war
# Application config
RUN mkdir $CATALINA_HOME/app_conf/
ADD src/main/config/test.properties $CATALINA_HOME/app_conf/
# Modify property 'shared.loader' in catalina.properties
@ghusta
ghusta / Vagrantfile
Last active April 20, 2021 16:28
Vagrant : Ubuntu 20.04 / Hyper-V
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
@ghusta
ghusta / create_machine_docker-dev.cmd
Created January 17, 2018 15:20
Create a Docker Machine with Windows, VirtualBox and Boot2Docker with a customized shared folder
rem set MACHINE_STORAGE_PATH=D:\Dev\Docker\.docker\machine
docker-machine version
docker-machine ls
echo creation VM VirtualBox : Docker Machine (Help : docker-machine create --help)
rem var env (ex : proxy) : --engine-env
set VM_NAME=docker-dev
mkdir d:\Dev\Docker\.docker\machine\SharedFolders\%VM_NAME%
docker-machine create -d "virtualbox" --virtualbox-cpu-count "2" --virtualbox-disk-size "50000" --virtualbox-memory "2048" --virtualbox-share-folder "\\?\d:\Dev\Docker\.docker\machine\SharedFolders\%VM_NAME%:host-shared" %VM_NAME%
@ghusta
ghusta / Assert-Comparables.md
Created October 8, 2015 10:07
Java Unit Tests : Assert on Comparables (BigDecimal)

This is UGLY : With JUnit 4

    BigDecimal actual = new BigDecimal("8.0");
    assertTrue(actual.compareTo(new BigDecimal("8.00")) == 0);
    assertEquals(0, actual.compareTo(new BigDecimal("8.00")));

That's too verbose...

This is BEAUTIFUL :

@ghusta
ghusta / Dockerfile
Last active February 6, 2019 18:19
Tomcat 8 + Docker : add custom directory in classpath (Method #2 : define CLASSPATH in bin/setenv.sh)
FROM tomcat:8.5-jre8
# $CATALINA_HOME is defined in tomcat image
ADD target/my-webapp*.war $CATALINA_HOME/webapps/my-webapp.war
# Application config
RUN mkdir $CATALINA_HOME/app_conf/
ADD src/main/config/test.properties $CATALINA_HOME/app_conf/
# Create "$CATALINA_HOME/bin/setenv.sh"
@ghusta
ghusta / test.jsp
Created January 2, 2019 11:08
Change the HTTP response status for a JSP
<%@ page language="java" contentType="text/html; UTF-8; charset=UTF-8" pageEncoding="UTF-8" trimDirectiveWhitespaces="true" %>
<%
response.setStatus(403);
%>
<!DOCTYPE html>
<html lang="en">
...
</html>
@ghusta
ghusta / LocalDateToDateConverter.java
Created June 10, 2016 11:42
Dozer Converter to convert org.joda.time.LocalDate to java.util.Date.
package ...util.dozer.converters.time;
import java.util.Date;
import org.dozer.DozerConverter;
import org.joda.time.LocalDate;
/**
* <b>Converter Dozer</b> : Convert a {@link LocalDate} to {@link Date}.
*/
@ghusta
ghusta / Dockerfile
Last active November 14, 2018 09:20
Docker image Postgres with vi(m)
FROM postgres:latest
RUN apt-get update && \
apt-get install -y vim