Skip to content

Instantly share code, notes, and snippets.

View l-gu's full-sized avatar

Laurent GUERIN l-gu

View GitHub Profile
@l-gu
l-gu / CheatSheet.vm
Last active June 25, 2021 11:21
Velocity Language Cheat Sheet
## ----------------------------------------------------------------------
## Telosys Template : Velocity Cheat Sheet
## ----------------------------------------------------------------------
#*
Multi-lines comment
*#
#[[
Unparsed block (all this block will be rendered as is)
$undefined
#set($i = 50)
--- Getting an object value with a default value if not defined
#assertFalse($fn.isDefined("FOO2"), "F002 is not supposed to be defined!")
Getting "FOO2" : $fn.get("FOO2", "my default value")
--- Defining a variable if not already exists
Exemple 1 :
'NAMESPACE' has not been defined in the project variables
then it will be initialized with a default value
#set ( $NAMESPACE = $fn.get("NAMESPACE", "default-name" ) )
--- Playing with defined/undefined variables
#set ( $FOO1 = "FooValue1" )
'FOO1' variable has been set, value = "$FOO1"
#if ( $fn.isDefined("FOO1") ) ## Check by variable name (string, not object reference)
YES 'FOO1' is defined
#else
NO 'FOO1' is not defined
#end
@l-gu
l-gu / FooDateJsonMappingTest
Last active April 26, 2017 21:47
Java util.Date literal values
/*
* Created on 2017-04-26 ( Date ISO 2017-04-26 - Time 21:50:59 )
* Generated by Telosys ( http://www.telosys.org/ ) version 3.0.0
*/
package org.demo.persistence.impl.redis.commons.json;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.text.SimpleDateFormat;
@l-gu
l-gu / java.util.logging.Logger example
Created December 27, 2016 17:54
Logger example with java.util.logging.Logger
package org.demo.tmp;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.junit.Test;
public class LoggerTest {
@Test
@l-gu
l-gu / web-xml-jax-rs-jersey
Created July 2, 2015 13:18
web.xml for JAX-RS with Jersey
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="portail-jaxrs" version="2.5">
<display-name>portail-jaxrs</display-name>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
@l-gu
l-gu / pom-xml-jax-rs-jersey
Created July 2, 2015 13:15
pom.xml for jax-rs with jersey
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cours</groupId>
<artifactId>jax-rs</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
@l-gu
l-gu / gist:ed0c8726807e5e8dd83a
Created June 18, 2014 21:22
Database connection in a TelosysTools template
import java.io.File;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.net.URLClassLoader;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
@l-gu
l-gu / gist:9188049
Created February 24, 2014 13:05
Map entries
//--- For each entity
for ( Map.Entry<String, EntityInContext> entry : _entities.entrySet() )
{
//String name = entry.getKey() ;
EntityInContext entity = entry.getValue() ;
allEntities.add(entity);
}
@l-gu
l-gu / MapContent
Last active August 29, 2015 13:55
@SuppressWarnings("unchecked")
protected void logSessionContent(HttpSession session) {
Enumeration<String> enumNames = session.getAttributeNames();
List<String> names = Collections.list(enumNames);
logger.info("Session content (size = " + names.size() + ") : ");
for ( String name : names ) {
logger.info(" . '" + name + "' : " + session.getAttribute(name) );
}
}