Skip to content

Instantly share code, notes, and snippets.

@LenarBad
LenarBad / BinaryTreePeers.java
Last active Aug 8, 2019
Binary Tree Peers. Everything is public for simplicity
View BinaryTreePeers.java
public class Node {
public int value;
public Node left;
public Node right;
public Node peer;
public Node(int value) {
this.value = value;
}
@LenarBad
LenarBad / Heroku - mLab MongoDB - Spring Boot - How to start example StatEntry.java
Last active Jun 5, 2019
Heroku - mLab MongoDB - Spring Boot - How to start example
View Heroku - mLab MongoDB - Spring Boot - How to start example StatEntry.java
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
@Document(collection = "stats")
public class StatEntry {
@Id
public String id;
@LenarBad
LenarBad / settings.xml
Last active Apr 16, 2019
Maven settings.xml for publishing open source projects
View settings.xml
<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 Apr 15, 2019
POM.XML for Open Source Maven project example
View pom.xml
<?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 Apr 8, 2019
Jenkins schedule format
View JenkinsScheduleFormat
┌───────────── 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 Apr 8, 2019
Url query to parameter map
View queryToMap.java
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 Apr 8, 2019
Parameter map to url query
View mapToQuery.java
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 Mar 8, 2019
Arabic to roman numerals
View RomanNumeral.java
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 Feb 27, 2019
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
View PhoneLetters.java
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 / isWiderPrimitive.java
Created Jul 24, 2018
Checks if object is auto-boxed primitive + String and Void
View isWiderPrimitive.java
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) {