Skip to content

Instantly share code, notes, and snippets.

@alainlompo
alainlompo / DeployToTomcat.bat
Last active June 29, 2017 08:53
Simple maven command to deploy an artifact to tomcat
mvn clean package tomcat7:redeploy -Dtomcat.url=http://your-url:portnumberhere/manager/text -Dtomcat.user=your-user -Dtomcat.password=your-password
@alainlompo
alainlompo / SafelyAvoidingNull.java
Created May 25, 2017 08:17
Safely avoiding null illustration
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
public class SafelyAvoidingNull {
public static void main(String[] args) {
List<String> strings = null;
int initialSize = Optional.ofNullable(strings).orElse(new ArrayList<String>()).size();
System.out.println(initialSize);
}
@alainlompo
alainlompo / Optionalizable.java
Created May 11, 2017 14:33
Showcasing how to build functional functions with the same level of fancyness as Java 8's core based on the Optional<T> class
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
public class Optionalizable {
public static Optional<Integer> getMaxLengthFrom(List<String> stringList) {
@alainlompo
alainlompo / SystematicToString.java
Created May 9, 2017 17:19
Building a toString() in a systematic way using org.apache.commons.lang.builder.ToStringBuilder
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
}
@alainlompo
alainlompo / list.installed.packages.r
Created May 8, 2017 19:44
List of R installed packages along with versions
installed.packages(lib.loc = NULL, priority = NULL,
+ noCache = FALSE, fields = NULL,
+ subarch = .Platform$r_arch)
@alainlompo
alainlompo / parallel-by-surefire-pom-extract.xml
Created May 4, 2017 18:42
surefire plugin for running tests in parallel (can be configured for per method or per class parallel run)
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7.1</version>
<configuration>
<parallel>classes</parallel>
<threadCount>5</threadCount>
</configuration>
@alainlompo
alainlompo / pom-for-powermock.xml
Created May 2, 2017 13:13
Usefull dependencies for Junit (4.11) PowerMock (1.6.6) and Mockito (1.10.19)
<!-- At this time junit 4.12 is available but there is a bug with it in regard to running Junit tests in Eclipse with the run contextual menu option -->
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.lompo.banking</groupId>
<artifactId>playground</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>playground</name>
<url>http://maven.apache.org</url>
@alainlompo
alainlompo / BasicMathsTest.java
Created May 2, 2017 13:05
Static method testing with PowerMock over Mockito (II)
package org.lompo.banking.utils.maths;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@alainlompo
alainlompo / BasicMaths.java
Created May 2, 2017 13:04
Static method testing with PowerMock over Mockito (I)
package org.lompo.banking.utils.maths;
public class BasicMaths {
private BasicMaths() {}
public static double PI_I() {
return 22.0/7.0;
}
public static double PI_II() {
@alainlompo
alainlompo / filterinigsamples.R
Created April 21, 2017 01:37
filtering with deployr samples
# applying the filterings on a data set called agadez
# filtering by the pm25tmean2 column and retaining the values that are greater and 30
moreThan30PM25 <- filter(agadez, pm25tmean2 > 30)
# get summary stats
summary(moreThan30PM25$pm25tmean2)
# Adding the temperature condition to the filter
moreThan30PM25And80DegF <- filter(agadez, pm25tmean2 > 30 & tmpd > 80)