Skip to content

Instantly share code, notes, and snippets.

@LenarBad
LenarBad / settings.xml
Last active April 16, 2019 14:57
Maven settings.xml for publishing open source projects
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>sonatype-nexus-snapshots</id>
<username>your-sonatype-username</username>
<password>your-sonatype-password</password>
</server>
@LenarBad
LenarBad / pom.xml
Created April 15, 2019 21:58
POM.XML for Open Source Maven project example
<?xml version="1.0" encoding="UTF-8"?>
<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>io.lenar</groupId>
<artifactId>app-props</artifactId>
<version>0.9.3-SNAPSHOT</version>
<packaging>jar</packaging>
<name>AppProps</name>
@LenarBad
LenarBad / JenkinsScheduleFormat
Created April 8, 2019 23:33
Jenkins schedule format
┌───────────── minute (0 - 59)
│ ┌───────────── hour (0 - 23)
│ │ ┌───────────── day of month (1 - 31)
│ │ │ ┌───────────── month (1 - 12)
│ │ │ │ ┌───────────── day of week (0 - 6) (Sunday to Saturday;
│ │ │ │ │ 7 is also Sunday on some systems)
│ │ │ │ │
│ │ │ │ │
* * * * * schedule command to execute
@LenarBad
LenarBad / queryToMap.java
Created April 8, 2019 21:43
Url query to parameter map
private Map<String, String> queryToMap(String query) throws UnsupportedEncodingException {
Map<String, String> parameters = new HashMap<>();
String[] queryArray = query.split("&");
for (String string : queryArray) {
int idx = string.indexOf("=");
parameters.put(decode(string.substring(0, idx), "UTF-8"), decode(string.substring(idx + 1), "UTF-8"));
}
return parameters;
}
@LenarBad
LenarBad / mapToQuery.java
Created April 8, 2019 21:39
Parameter map to url query
private String mapToQuery(Map<String, String> parameters) {
String query = "";
if (parameters != null && !parameters.isEmpty()){
query = "?" +
parameters.entrySet().stream()
.map(entry -> entry.getKey() + "=" + entry.getValue())
.collect(Collectors.joining("&"));
}
return query;
}
@LenarBad
LenarBad / RomanNumeral.java
Created March 8, 2019 03:49
Arabic to roman numerals
public class RomanNumeral {
private final HashMap<Integer, String> map = new HashMap<Integer, String>() {
{
put(1, "I");
put(5, "V");
put(10, "X");
put(50, "L");
put(100, "C");
put(500, "D");
put(1000, "M");
@LenarBad
LenarBad / PhoneLetters.java
Last active February 27, 2019 16:34
Interview Question. Generate and print all possible strings that could be created by a phone number, using the letters assigned on the phone Print all possibles strings that could be created by a phone number, using the letters assigned on the phone. Don’t have to store them, just print them
private Map<String, List<String>> static final digitToLetterMap = new HashMap() {{
map.put("0", Arrays.asList(" "));
map.put("1", Arrays.asList(""));
map.put("2", Arrays.asList("a", "b", "c"));
map.put("3", Arrays.asList("d", "e", "f"));
map.put("4", Arrays.asList("g", "h", "i"));
map.put("5", Arrays.asList("j", "k", "l"));
map.put("6", Arrays.asList("m", "m", "o"));
map.put("7", Arrays.asList("p", "q", "r", "s"));
map.put("8", Arrays.asList("t", "u", "v"));
@LenarBad
LenarBad / Spring Boot + TestNG test class TestNGTestsWithSpringBootIT.java
Last active December 15, 2018 02:05
Spring Boot and TestNG example - test class
package io.lenar.examples.spring.start;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.boot.test.context.SpringBootTest;
import org.testng.Assert;
import org.testng.annotations.Test;
@SpringBootTest(classes = TestNGWithSpringApplication.class)
public class TestNGTestsWithSpringBootIT extends AbstractTestNGSpringContextTests {
@LenarBad
LenarBad / isWiderPrimitive.java
Created July 24, 2018 17:43
Checks if object is auto-boxed primitive + String and Void
public boolean isWiderPrimitive(Object object) {
if (object == null) {
return false;
}
Class clazz = object.getClass();
if (clazz == Boolean.class || clazz == Character.class ||
clazz == Byte.class || clazz == Short.class ||
clazz == Integer.class || clazz == Long.class ||
clazz == Float.class || clazz == Double.class ||
clazz == String.class || clazz == Void.class) {
@LenarBad
LenarBad / SpringDataProviderRunner.java
Created June 14, 2018 19:09
JUnit data providers for Spring
import static java.lang.Character.toUpperCase;
import java.util.ArrayList;
import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.manipulation.Filter;
import org.junit.runner.manipulation.NoTestsRemainException;